Add RunAsSubcommand to keep API unchanged

This commit is contained in:
Naveen Gogineni 2022-10-11 16:35:54 -04:00
parent 4a109bc0ce
commit 00afca42c8
2 changed files with 6 additions and 2 deletions

6
app.go
View File

@ -305,6 +305,12 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
return a.rootCommand.Run(cCtx, arguments...)
}
// This is a stub function to keep public API unchanged from old code
// No one should really use this. Always use a.Run to execute app
func (a *App) RunAsSubcommand(ctx *Context) (err error) {
return a.RunContext(ctx.Context, ctx.Args().Slice())
}
func (a *App) suggestFlagFromError(err error, command string) (string, error) {
flag, parseErr := flagFromError(err)
if parseErr != nil {

View File

@ -1050,7 +1050,6 @@ func newContextFromStringSlice(ss []string) *Context {
return &Context{flagSet: set}
}
/*
func TestHideHelpCommand_RunAsSubcommand(t *testing.T) {
app := &App{
HideHelpCommand: true,
@ -1097,7 +1096,6 @@ func TestHideHelpCommand_RunAsSubcommand_False(t *testing.T) {
t.Errorf("Run returned unexpected error: %v", err)
}
}
*/
func TestHideHelpCommand_WithSubcommands(t *testing.T) {
app := &App{