Summary
The azd extension framework registers -o/--output as a single SDK-owned persistent flag on the root command (via azdext.NewExtensionRootCommand). This avoids flag collisions with azd's reserved global flags, but leaves a gap: extensions have no way to customize the supported values, default value, or help text of --output on a per-subcommand basis.
Gap
Different subcommands within the same extension typically support different output formats. For example, in azure.ai.agents:
agent files list and sessions list support json and table (default json)
agent version only emits json
- Most other commands don't produce structured output at all and just inherit the SDK default
default
Because the persistent --output flag is shared across the entire command tree, all subcommands render the same generic help text:
-o, --output string The output format (default "default")
…regardless of what the subcommand actually accepts, which is misleading to users running <cmd> --help and to consumers of the extension metadata JSON used for IntelliSense. There is also no SDK-side validation, completion, or per-command default for the flag.
Workarounds (redeclaring a local --output flag on each subcommand) collide with the inherited persistent flag and break once azd enforces its reserved-flag set.
Proposed approach
Add a new SDK helper that lets a subcommand declare its allowed values and default for any inherited persistent flag in one place:
azdext.RegisterFlagOptions(listCmd, "output", []string{"json", "table"}, "json")
A single declaration drives:
- Help text rendered for that subcommand
- Extension metadata (
Flag.ValidValues, Flag.Default)
- Parse-time validation (rejects unsupported values before
RunE runs)
- Shell completion for the flag on that subcommand
- Default substitution into the bound
ExtensionContext field
Generalizes to any inherited persistent flag via the flag-name argument; not hardcoded to --output.
Related
Summary
The azd extension framework registers
-o/--outputas a single SDK-owned persistent flag on the root command (viaazdext.NewExtensionRootCommand). This avoids flag collisions with azd's reserved global flags, but leaves a gap: extensions have no way to customize the supported values, default value, or help text of--outputon a per-subcommand basis.Gap
Different subcommands within the same extension typically support different output formats. For example, in
azure.ai.agents:agent files listandsessions listsupportjsonandtable(defaultjson)agent versiononly emitsjsondefaultBecause the persistent
--outputflag is shared across the entire command tree, all subcommands render the same generic help text:…regardless of what the subcommand actually accepts, which is misleading to users running
<cmd> --helpand to consumers of the extension metadata JSON used for IntelliSense. There is also no SDK-side validation, completion, or per-command default for the flag.Workarounds (redeclaring a local
--outputflag on each subcommand) collide with the inherited persistent flag and break once azd enforces its reserved-flag set.Proposed approach
Add a new SDK helper that lets a subcommand declare its allowed values and default for any inherited persistent flag in one place:
A single declaration drives:
Flag.ValidValues,Flag.Default)RunEruns)ExtensionContextfieldGeneralizes to any inherited persistent flag via the flag-name argument; not hardcoded to
--output.Related
NewExtensionRootCommand)