ate-env CLI root command dispatch treats unknown subcommands as <id> (exiting 0), rejects global flags before <id>, and allows creating reserved subcommand names

Open
#117 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
cli

Research direction

Start with cmd/ate-env/main.go, especially newRootCommand and newGuestCommand, then inspect the built-in command definitions and the matching code in internal/apiservice/server.go. Reproduce the listed command cases and check how Cobra handles flags, unknown commands, and reserved names. Done means unknown commands fail non-zero, global flags work in the shown positions, and environment creation rejects reserved command names and invalid IDs.

Written by the indexing model from the issue text.

Description

Summary & Root Cause

The CLI decides how to parse the command line from os.Args[1] alone:

  • Unknown word (list, status, get): becomes a guest command. Without a subcommand, Cobra prints Manage environment list help and returns success.
  • Flag first (--api ...): root.Find succeeds on the root itself, so no guest command is registered. alice is then an unknown command at root. --api is not a root flag anyway.
  • Reserved name (delete): matches the built-in, so an environment named delete cannot be addressed as ate-env delete shell .... CreateEnvironment does not reject reserved names.
Affected Code Locations

All env citations are at 40a6c63. cmd/ate-env/main.go and internal/apiservice/server.go are identical at de462e98.

  • cmd/ate-env/main.go:234-262: newRootCommand
  • cmd/ate-env/main.go:254-259: inspects only args[0] and, if root.Find fails, registers newGuestCommand(args[0])
  • cmd/ate-env/main.go:43-67: newGuestCommand has no RunE and no Args, so ate-env <word> prints its help and exits 0. --api and --atespace are defined only as this command's persistent flags (:66-67), not on root
  • cmd/ate-env/main.go:249-252: built-ins manifest, create, suspend, delete
  • cmd/ate-env/main.go:208-232: delete <id> takes cobra.ExactArgs(1)
  • internal/apiservice/server.go:116-119: CreateEnvironment only checks that id is non-empty
	if len(args) > 0 {
		cmdName := args[0]
		if _, _, err := root.Find([]string{cmdName}); err != nil {
			root.AddCommand(newGuestCommand(cmdName))
		}
	}
Detailed Reproduction Guide
export SUBSTRATE_ENV_API=127.0.0.1:17790   # port-forward to svc/ate-env-api
ate-env list; echo "exit: $?"
ate-env status; echo "exit: $?"
ate-env get alice; echo "exit: $?"
ate-env --api 127.0.0.1:17790 alice shell 'echo hi'; echo "exit: $?"
ate-env --atespace ate-env alice read /etc/hostname; echo "exit: $?"
ate-env create delete; echo "exit: $?"
ate-env delete shell 'echo hi'; echo "exit: $?"
Expected vs. Actual Behavior
  • Expected: Unknown commands fail on stderr with a non-zero exit code. Global flags work in any position. create rejects IDs that collide with CLI subcommands (and validates the ID format).
  • Actual: list, status and get alice print environment help and exit 0. Flags before <id> fail with unknown command "alice" for "ate-env". create delete succeeds, and ate-env delete shell 'echo hi' fails with accepts 1 arg(s), received 2.
Observed Output & Logs
$ kubectl set image deploy/ate-env-api -n ate-env ate-env-api=<de462e98 api image>   # rollout_rc=0, pod 1/1 Running
$ ate-env(de462e98) create compat1                      # EXIT: 0
$ ate-env(de462e98) compat1 shell 'echo hi-from-de462e98'   # hi-from-de462e98 / EXIT: 0
$ ate-env(de462e98) delete compat1                      # EXIT: 0
$ kubectl rollout undo deploy/ate-env-api -n ate-env    # back to 40a6c63 image
Dominant language
Go
Stars
70
Forks
17
Avg merge
21h 36m
Merged PRs (30d)
19

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from agent-substrate/env

All issues in agent-substrate/env

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.