Skip to content

Migrate CLI argument parsing to betteropts - #86

Open
jakub-bochenski wants to merge 1 commit into
VirtusLab:masterfrom
jakub-bochenski:betteropts-cli-migration
Open

Migrate CLI argument parsing to betteropts#86
jakub-bochenski wants to merge 1 commit into
VirtusLab:masterfrom
jakub-bochenski:betteropts-cli-migration

Conversation

@jakub-bochenski

Copy link
Copy Markdown
Contributor

Adapts the bin/sandcat dispatcher (module/command listing, --__complete, --completion), adds betteropts as a submodule, and converts every libexec command to declare its flags/options/arguments through it instead of hand-rolled while/case loops. Bumps the minimum Bash version to 4.2 since betteropts requires associative arrays and declare -g.

Behavioral notes:

  • init's --agent/--ide/--secret-provider (and its --sp alias) validate via betteropts' own type=choice/choices=, since each is a single value from a small fixed (or, for --agent, dynamically fetched) set - a genuine fit. --stacks/--features stay on custom validation since they're comma- separated multi-value fields, not a single choice; cache/rm and init/devcontainer have no choice-shaped validation to convert either.
  • init's --stacks/--secret-provider(/--sp)/--features need to distinguish "explicitly passed empty" from "omitted" (to skip interactive prompts), which betteropts doesn't expose directly; a small presence-scan over the raw args recovers it alongside the normal betteropts value parsing. The same reasoning shows up in test/init/init.bats: betteropts schema state is process-global, so tests that call init twice route both calls through run (which forks a subshell) to keep the first call's schema from leaking into the second.

Adapts the bin/sandcat dispatcher (module/command listing, --__complete,
--completion) from the android-deps-build-config tab-completion template,
adds betteropts as a submodule, and converts every libexec command to
declare its flags/options/arguments through it instead of hand-rolled
while/case loops. Bumps the minimum Bash version to 4.2 since betteropts
requires associative arrays and declare -g.

Behavioral notes:
- init's --agent/--ide/--secret-provider (and its --sp alias) validate via
  betteropts' own type=choice/choices=, since each is a single value from a
  small fixed (or, for --agent, dynamically fetched) set - a genuine fit.
  --stacks/--features stay on custom validation since they're comma-
  separated multi-value fields, not a single choice; cache/rm and
  init/devcontainer have no choice-shaped validation to convert either.
- init's --stacks/--secret-provider(/--sp)/--features need to distinguish
  "explicitly passed empty" from "omitted" (to skip interactive prompts),
  which betteropts doesn't expose directly; a small presence-scan over the
  raw args recovers it alongside the normal betteropts value parsing. The
  same reasoning shows up in test/init/init.bats: betteropts schema state
  is process-global, so tests that call `init` twice route both calls
  through `run` (which forks a subshell) to keep the first call's schema
  from leaking into the second.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@adamw

adamw commented Aug 4, 2026

Copy link
Copy Markdown
Member

Thanks - though I'll hold off with merging this since it requires a bash update on mac, which would increase the barrier of entry for some users. But if people have other opinion, let me know :)

@jakub-bochenski

Copy link
Copy Markdown
Contributor Author

FWIW the shell installer (#80) already has to handle jq, so if it's handling one dependency IMO adding another one is not such a big jump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants