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

Aperta
#117 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Go
Stelle
70
Fork
17
Merge medio
21h 36m
PR unite (30g)
19

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di agent-substrate/env

Tutte le issue di agent-substrate/env

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.