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

Abierto
#117 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
57/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
cli

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Go
Estrellas
70
Forks
17
Merge medio
21 h 36 min
PR fusionados (30 d)
19

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de agent-substrate/env

Todos los issues de agent-substrate/env

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.