fix(cli): rely on framework doctor alias

This commit is contained in:
thibaud-lclr 2026-04-15 09:57:43 +02:00
parent 46c94a1a12
commit 7315f2658c
2 changed files with 6 additions and 39 deletions

View file

@ -115,7 +115,10 @@ func NewAppWithDependencies(
}
func (a *App) Run(args []string) error {
return a.runBootstrap(context.Background(), normalizeArgs(args))
if args == nil {
args = []string{}
}
return a.runBootstrap(context.Background(), args)
}
func (a *App) runBootstrap(ctx context.Context, args []string) error {
@ -125,6 +128,7 @@ func (a *App) runBootstrap(ctx context.Context, args []string) error {
BinaryName: metadata.BinaryName,
Description: metadata.Description,
Version: a.version,
EnableDoctorAlias: true,
Args: args,
Stdin: a.stdin,
Stdout: a.stdout,
@ -778,40 +782,3 @@ func newUserFacingError(message string, err error) error {
err: err,
}
}
func normalizeArgs(args []string) []string {
if len(args) == 0 {
return []string{}
}
normalized := append([]string(nil), args...)
for i, arg := range normalized {
normalized[i] = strings.TrimSpace(arg)
}
switch normalized[0] {
case "doctor":
if len(normalized) == 1 {
return []string{frameworkbootstrap.CommandConfig, frameworkbootstrap.ConfigSubcommandTest}
}
lastArg := normalized[len(normalized)-1]
if lastArg == "-h" || lastArg == "--help" {
return []string{"help", frameworkbootstrap.CommandConfig, frameworkbootstrap.ConfigSubcommandTest}
}
return append(
[]string{frameworkbootstrap.CommandConfig, frameworkbootstrap.ConfigSubcommandTest},
normalized[1:]...,
)
case "help":
if len(normalized) > 1 && normalized[1] == "doctor" {
return append(
[]string{"help", frameworkbootstrap.CommandConfig, frameworkbootstrap.ConfigSubcommandTest},
normalized[2:]...,
)
}
}
return normalized
}

View file

@ -158,7 +158,7 @@ func TestAppRunShowsUsageWhenNoArgsProvided(t *testing.T) {
}
text := output.String()
for _, snippet := range []string{"Usage:", "config", "version"} {
for _, snippet := range []string{"Usage:", "config", "version", `doctor Diagnostiquer la configuration locale. (alias de "config test").`} {
if !strings.Contains(text, snippet) {
t.Fatalf("help output missing %q: %q", snippet, text)
}