fix(cli): rely on framework doctor alias
This commit is contained in:
parent
46c94a1a12
commit
7315f2658c
2 changed files with 6 additions and 39 deletions
|
|
@ -115,7 +115,10 @@ func NewAppWithDependencies(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Run(args []string) error {
|
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 {
|
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,
|
BinaryName: metadata.BinaryName,
|
||||||
Description: metadata.Description,
|
Description: metadata.Description,
|
||||||
Version: a.version,
|
Version: a.version,
|
||||||
|
EnableDoctorAlias: true,
|
||||||
Args: args,
|
Args: args,
|
||||||
Stdin: a.stdin,
|
Stdin: a.stdin,
|
||||||
Stdout: a.stdout,
|
Stdout: a.stdout,
|
||||||
|
|
@ -778,40 +782,3 @@ func newUserFacingError(message string, err error) error {
|
||||||
err: err,
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ func TestAppRunShowsUsageWhenNoArgsProvided(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
text := output.String()
|
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) {
|
if !strings.Contains(text, snippet) {
|
||||||
t.Fatalf("help output missing %q: %q", snippet, text)
|
t.Fatalf("help output missing %q: %q", snippet, text)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue