Add Code Generation Support for Alternative Sources - #19
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Yargs resolution currently breaks defaults, required flags, enum compilation, and source precedence, while Go YAML numeric coercion is incomplete.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds generated CLI support for environment- and config-file-backed flag values across Cobra, urfave/cli, and Yargs.
Changes:
- Generates alternative-source resolvers and config loaders.
- Adds global-flag propagation and generator coverage.
- Updates examples, documentation, generated fixtures, and web navigation.
File summaries
| File | Description |
|---|---|
gen/cli.go |
Validates unsupported group arguments/flags. |
gen/cli_cobra.go |
Generates Cobra source resolution. |
gen/cli_urfave_cli.go |
Generates urfave source resolution. |
gen/cli_yargs.go |
Generates Yargs source resolution. |
gen/templates/code/cobra/gencli/config.tmpl |
Adds Cobra config resolvers. |
gen/templates/code/cobra/gencli/run.tmpl |
Loads config and binds globals. |
gen/templates/code/cobra/gencli/params.tmpl |
Adds global-flag context helpers. |
gen/templates/code/cobra/gencli/command.tmpl |
Resolves flags and injects globals. |
gen/templates/code/cobra/gencli/actions.tmpl |
Corrects parameter generation. |
gen/templates/code/urfavecli/gencli/config.tmpl |
Adds urfave config resolvers. |
gen/templates/code/urfavecli/gencli/run.tmpl |
Loads config and registers globals. |
gen/templates/code/urfavecli/gencli/params.tmpl |
Adds global-flag context helpers. |
gen/templates/code/urfavecli/gencli/command.tmpl |
Resolves flags and injects globals. |
gen/templates/code/urfavecli/gencli/actions.tmpl |
Corrects parameter generation. |
gen/templates/code/yargs/gencli/config.tmpl |
Adds TypeScript config resolvers. |
gen/templates/code/yargs/gencli/run.tmpl |
Accepts argv and loads config. |
gen/templates/code/yargs/gencli/params.tmpl |
Adds global-flag accessors. |
gen/templates/code/yargs/gencli/help.tmpl |
Corrects argument help rendering. |
gen/templates/code/yargs/gencli/command.tmpl |
Resolves flags and sets globals. |
gen/cli_group_test.go |
Tests group validation. |
gen/cli_globalflags_test.go |
Tests global-flag generation. |
gen/cli_yargs_variadic_test.go |
Tests typed variadic flags. |
gen/testdata/globalflags-cli.ocs.yaml |
Defines global-flag fixture. |
gen/testdata/cobra/globalflags/gencli/run.gen.go |
Cobra global-flag golden. |
gen/testdata/cobra/globalflags/gencli/params.gen.go |
Cobra global parameter golden. |
gen/testdata/cobra/globalflags/gencli/iostreams.gen.go |
Cobra I/O golden. |
gen/testdata/cobra/globalflags/gencli/help.gen.go |
Cobra help golden. |
gen/testdata/cobra/globalflags/gencli/errors.gen.go |
Cobra error golden. |
gen/testdata/cobra/globalflags/gencli/cmd_gflag.gen.go |
Cobra root-command golden. |
gen/testdata/cobra/globalflags/gencli/cmd_gflag_send.gen.go |
Cobra send-command golden. |
gen/testdata/cobra/globalflags/gencli/cmd_gflag_ping.gen.go |
Cobra ping-command golden. |
gen/testdata/cobra/globalflags/gencli/cmd_gflag_greet.gen.go |
Cobra greet-command golden. |
gen/testdata/cobra/globalflags/gencli/cmd_gflag_echo.gen.go |
Cobra echo-command golden. |
gen/testdata/cobra/globalflags/gencli/actions.gen.go |
Cobra actions golden. |
gen/testdata/cobra/gencli/run.gen.go |
Loads generated Cobra config. |
gen/testdata/cobra/gencli/cmd_petstore_user_login.gen.go |
Resolves Cobra login sources. |
gen/testdata/urfavecli/globalflags/gencli/run.gen.go |
urfave global-flag golden. |
gen/testdata/urfavecli/globalflags/gencli/params.gen.go |
urfave global parameter golden. |
gen/testdata/urfavecli/globalflags/gencli/iostreams.gen.go |
urfave I/O golden. |
gen/testdata/urfavecli/globalflags/gencli/errors.gen.go |
urfave error golden. |
gen/testdata/urfavecli/globalflags/gencli/cmd_gflag.gen.go |
urfave root-command golden. |
gen/testdata/urfavecli/globalflags/gencli/cmd_gflag_send.gen.go |
urfave send-command golden. |
gen/testdata/urfavecli/globalflags/gencli/cmd_gflag_ping.gen.go |
urfave ping-command golden. |
gen/testdata/urfavecli/globalflags/gencli/cmd_gflag_greet.gen.go |
urfave greet-command golden. |
gen/testdata/urfavecli/globalflags/gencli/cmd_gflag_echo.gen.go |
urfave echo-command golden. |
gen/testdata/urfavecli/globalflags/gencli/actions.gen.go |
urfave actions golden. |
gen/testdata/urfavecli/gencli/run.gen.go |
Loads generated urfave config. |
gen/testdata/urfavecli/gencli/config.gen.go |
Generated urfave source resolvers. |
gen/testdata/urfavecli/gencli/cmd_petstore_user_login.gen.go |
Resolves urfave login sources. |
gen/testdata/yargs/globalflags/gencli/types.ts |
Yargs metadata golden. |
gen/testdata/yargs/globalflags/gencli/run.ts |
Yargs global option golden. |
gen/testdata/yargs/globalflags/gencli/params.ts |
Yargs global accessor golden. |
gen/testdata/yargs/globalflags/gencli/help.ts |
Yargs help golden. |
gen/testdata/yargs/globalflags/gencli/errors.ts |
Yargs error golden. |
gen/testdata/yargs/globalflags/gencli/cmd-gflag.ts |
Yargs root-command golden. |
gen/testdata/yargs/globalflags/gencli/cmd-gflag-send.ts |
Yargs send-command golden. |
gen/testdata/yargs/globalflags/gencli/cmd-gflag-ping.ts |
Yargs ping-command golden. |
gen/testdata/yargs/globalflags/gencli/cmd-gflag-greet.ts |
Yargs greet-command golden. |
gen/testdata/yargs/globalflags/gencli/cmd-gflag-echo.ts |
Yargs echo-command golden. |
gen/testdata/yargs/globalflags/gencli/actions.ts |
Yargs actions golden. |
gen/testdata/yargs/gencli/run.ts |
Loads generated Yargs config. |
gen/testdata/yargs/gencli/help.ts |
Corrects generated argument help. |
gen/testdata/yargs/gencli/cmd-petstore-user-login.ts |
Resolves Yargs login sources. |
internal/cli/gencli/run.gen.go |
Loads OpenCLI configuration. |
internal/cli/gencli/cmd_ocli_gen_docs.gen.go |
Resolves docs format sources. |
internal/cli/gencli/cmd_ocli_gen_cli.gen.go |
Resolves framework sources. |
ocli.ocs.yaml |
Adds canonical self-documenting spec. |
docs/ocli.ocs.md |
Regenerates CLI documentation. |
docs/actions-implementation.md |
Documents action data access. |
README.md |
Updates canonical spec link. |
CONTRIBUTING.md |
Updates repository layout reference. |
.github/copilot-instructions.md |
Updates repository guidance. |
Makefile |
Updates generation targets and examples. |
go.mod |
Adds config-resolution dependencies. |
go.sum |
Records dependency checksums. |
examples/code/README.md |
Documents all generated examples. |
examples/code/yargs/pleasantries/src/index.ts |
Uses the new Yargs run API. |
examples/code/yargs/pleasantries/src/gencli/run.ts |
Generates the new run API. |
examples/code/yargs/pleasantries/src/gencli/help.ts |
Corrects argument help output. |
examples/code/urfavecli/pleasantries/main.go |
Adds urfave example entry point. |
examples/code/urfavecli/pleasantries/go.mod |
Defines urfave example module. |
examples/code/urfavecli/pleasantries/internal/cli/actions.go |
Implements example actions. |
examples/code/urfavecli/pleasantries/internal/gencli/run.gen.go |
Adds urfave runtime. |
examples/code/urfavecli/pleasantries/internal/gencli/params.gen.go |
Adds generated parameters. |
examples/code/urfavecli/pleasantries/internal/gencli/iostreams.gen.go |
Adds generated I/O support. |
examples/code/urfavecli/pleasantries/internal/gencli/errors.gen.go |
Adds generated errors. |
examples/code/urfavecli/pleasantries/internal/gencli/cmd_pleasantries.gen.go |
Adds generated root command. |
examples/code/urfavecli/pleasantries/internal/gencli/cmd_pleasantries_greet.gen.go |
Adds generated greet command. |
examples/code/urfavecli/pleasantries/internal/gencli/cmd_pleasantries_farewell.gen.go |
Adds generated farewell command. |
examples/code/urfavecli/pleasantries/internal/gencli/actions.gen.go |
Adds generated action interface. |
examples/code/cobra/pleasantries/internal/gencli/run.gen.go |
Adds generated Cobra runtime. |
examples/code/gencli/params.gen.go |
Removes misplaced generated fixture. |
examples/code/gencli/cmd_petstore.gen.go |
Removes misplaced root command. |
examples/code/gencli/cmd_petstore_user.gen.go |
Removes misplaced user group. |
examples/code/gencli/cmd_petstore_user_update.gen.go |
Removes misplaced update command. |
examples/code/gencli/cmd_petstore_user_logout.gen.go |
Removes misplaced logout command. |
examples/code/gencli/cmd_petstore_user_login.gen.go |
Removes misplaced login command. |
examples/code/gencli/cmd_petstore_user_get.gen.go |
Removes misplaced get command. |
examples/code/gencli/cmd_petstore_user_delete.gen.go |
Removes misplaced delete command. |
examples/code/gencli/cmd_petstore_user_createwithlist.gen.go |
Removes misplaced list-create command. |
examples/code/gencli/cmd_petstore_user_create.gen.go |
Removes misplaced create command. |
examples/code/gencli/cmd_petstore_store.gen.go |
Removes misplaced store group. |
examples/code/gencli/cmd_petstore_store_order.gen.go |
Removes misplaced order group. |
examples/code/gencli/cmd_petstore_store_order_place.gen.go |
Removes misplaced place command. |
examples/code/gencli/cmd_petstore_store_order_get.gen.go |
Removes misplaced order-get command. |
examples/code/gencli/cmd_petstore_store_order_delete.gen.go |
Removes misplaced order-delete command. |
examples/code/gencli/cmd_petstore_store_inventory.gen.go |
Removes misplaced inventory command. |
examples/code/gencli/cmd_petstore_pet.gen.go |
Removes misplaced pet group. |
examples/code/gencli/cmd_petstore_pet_uploadimage.gen.go |
Removes misplaced upload command. |
examples/code/gencli/cmd_petstore_pet_updateform.gen.go |
Removes misplaced form-update command. |
examples/code/gencli/cmd_petstore_pet_update.gen.go |
Removes misplaced pet-update command. |
examples/code/gencli/cmd_petstore_pet_get.gen.go |
Removes misplaced pet-get command. |
examples/code/gencli/cmd_petstore_pet_findbytags.gen.go |
Removes misplaced tag-search command. |
examples/code/gencli/cmd_petstore_pet_findbystatus.gen.go |
Removes misplaced status-search command. |
examples/code/gencli/cmd_petstore_pet_delete.gen.go |
Removes misplaced pet-delete command. |
examples/code/gencli/cmd_petstore_pet_add.gen.go |
Removes misplaced pet-add command. |
examples/code/gencli/cmd_petstore_list.gen.go |
Removes misplaced list command. |
examples/code/gencli/actions.gen.go |
Removes misplaced action interface. |
web/tsconfig.json |
Excludes public assets from TypeScript. |
web/src/views/GettingStarted.tsx |
Links TypeScript generation docs. |
web/src/views/GenMarkdownDocs.tsx |
Links TypeScript generation docs. |
web/src/views/GenManDocs.tsx |
Links TypeScript generation docs. |
web/src/views/GenHtmlDocs.tsx |
Links TypeScript generation docs. |
web/src/views/GeneratingGoCode.tsx |
Documents global flags and updates links. |
web/src/app/docs/code-generation-yargs/page.tsx |
Adds the Yargs documentation route. |
web/public/assets/code/actions.txt |
Adds downloadable TypeScript example. |
Review details
- Files reviewed: 129/136 changed files
- Comments generated: 11
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Yargs precedence and typing edge cases, missing generated dependencies, and unvalidated global choices can produce incorrect or non-building generated CLIs.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Files not reviewed (1)
- web/package-lock.json: Generated file
Suppressed comments (2)
gen/templates/code/yargs/gencli/config.tmpl:226
- This scan continues past the
--end-of-options marker. For a passthrough invocation such ascmd -- --name, it incorrectly treats--nameas an explicit option and suppresses the declared environment/config fallback, even though Yargs treats it as positional data. Stop scanning at--.
gen/templates/code/yargs/gencli/config.tmpl:232 - Yargs accepts grouped short options, but this exact-name comparison sees
-vxonly asvx, not aliasesvandx. An explicit grouped shorthand for an alternative-sourced flag can therefore be overwritten by environment/config data. Parse single-dash option groups consistently with Yargs while preserving support for declared multi-character aliases.
- Files reviewed: 153/162 changed files
- Comments generated: 9
- Review effort level: Balanced
| import toml from "@iarna/toml"; | ||
| {{- end}} | ||
| {{- if .HasFileAltSource}} | ||
| import { JSONPath } from "jsonpath-plus"; |
| export async function run( | ||
| yargsInstance: yargs.Argv<{}>, | ||
| argv: string[], | ||
| actions: ActionsInterface, |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Alternative Sources
Although the OpenCLI Specification supported the concept of alternative sources (i.e. passing flag values from config files and environment variables) there was no support in the code generation within
ocli. This branch adds that missing support. Now CLIs generated for Cobra, urfave/cli V3 and Yargs can all pull values from the specified config files/environment variables.Global Flags
This branch also addresses a major bug where global flags were dropped during code generation for some frameworks.