Skip to content

Commit

Permalink
Add RunAsSubcommand to keep API unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Oct 11, 2022
1 parent 4a109bc commit 00afca4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@ func newContextFromStringSlice(ss []string) *Context {
return &Context{flagSet: set}
}

/*
func TestHideHelpCommand_RunAsSubcommand(t *testing.T) {
app := &App{
HideHelpCommand: true,
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 00afca4

Please sign in to comment.