Skip to content

Commit 3e500c5

Browse files
committed
rename Runner to Commander, Describer to Descriptor, Parent to Subcommander
1 parent b4358ea commit 3e500c5

31 files changed

Lines changed: 375 additions & 375 deletions

args.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
// ScanArgs inspects a command's struct tags and returns positional arg definitions.
1111
// This is exported so custom [HelpRenderer] implementations can inspect a command's args.
12-
func ScanArgs(cmd Runner) []ArgDef {
12+
func ScanArgs(cmd Commander) []ArgDef {
1313
v := reflect.ValueOf(cmd)
1414
if v.Kind() == reflect.Ptr {
1515
v = v.Elem()
@@ -63,7 +63,7 @@ func scanArgsRecurse(t reflect.Type, defs *[]ArgDef) {
6363

6464
// populateArgs sets struct fields tagged with `arg` from positional arguments,
6565
// environment variables, and defaults. Returns unconsumed positional arguments.
66-
func populateArgs(cmd Runner, args []string, envPrefix string) ([]string, error) {
66+
func populateArgs(cmd Commander, args []string, envPrefix string) ([]string, error) {
6767
v := reflect.ValueOf(cmd)
6868
if v.Kind() == reflect.Ptr {
6969
v = v.Elem()

bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func BindSingleton[T any](fn func() (T, error)) Option {
130130

131131
// injectBindings populates injectable fields on all commands in the chain.
132132
// A field is injectable if it has no flag:, arg:, or env: tag.
133-
func injectBindings(chain []Runner, bindings []binding) error {
133+
func injectBindings(chain []Commander, bindings []binding) error {
134134
if len(bindings) == 0 {
135135
return nil
136136
}

bind_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ type bindParentCmd struct {
142142
DB *mockDB
143143
}
144144

145-
func (c *bindParentCmd) Subcommands() []cli.Runner {
146-
return []cli.Runner{&bindChildCmd{}}
145+
func (c *bindParentCmd) Subcommands() []cli.Commander {
146+
return []cli.Commander{&bindChildCmd{}}
147147
}
148148

149149
func (c *bindParentCmd) Run(ctx context.Context) error {
@@ -293,7 +293,7 @@ type singletonParentCmd struct {
293293
}
294294

295295
func (c *singletonParentCmd) Run(_ context.Context) error { return nil }
296-
func (c *singletonParentCmd) Subcommands() []cli.Runner { return []cli.Runner{&singletonChildCmd{}} }
296+
func (c *singletonParentCmd) Subcommands() []cli.Commander { return []cli.Commander{&singletonChildCmd{}} }
297297

298298
type singletonChildCmd struct {
299299
DB *mockDB

cli.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
"syscall"
1010
)
1111

12-
// Runner is the core interface every command must implement.
13-
type Runner interface {
12+
// Commander is the core interface every command must implement.
13+
type Commander interface {
1414
Run(ctx context.Context) error
1515
}
1616

17-
// RunFunc adapts a plain function into a [Runner].
17+
// RunFunc adapts a plain function into a [Commander].
1818
type RunFunc func(ctx context.Context) error
1919

20-
// Run implements [Runner].
20+
// Run implements [Commander].
2121
func (f RunFunc) Run(ctx context.Context) error {
2222
return f(ctx)
2323
}
@@ -158,7 +158,7 @@ func WithStdin(r io.Reader) Option {
158158
// Execute runs the command tree rooted at root with the given args and options.
159159
// It resolves subcommands, parses flags, runs lifecycle hooks, and executes
160160
// the target command.
161-
func Execute(ctx context.Context, root Runner, args []string, opts ...Option) error {
161+
func Execute(ctx context.Context, root Commander, args []string, opts ...Option) error {
162162
o := defaults()
163163
for _, opt := range opts {
164164
opt(o)
@@ -177,7 +177,7 @@ func Execute(ctx context.Context, root Runner, args []string, opts ...Option) er
177177
// errors (unknown flag, missing required flag, etc.) a usage hint is appended.
178178
// If the error implements [ExitCoder], its exit code is used; non-nil errors
179179
// default to exit code 1.
180-
func ExecuteAndExit(ctx context.Context, root Runner, args []string, opts ...Option) {
180+
func ExecuteAndExit(ctx context.Context, root Commander, args []string, opts ...Option) {
181181
o := defaults()
182182
for _, opt := range opts {
183183
opt(o)
@@ -205,7 +205,7 @@ func ExecuteAndExit(ctx context.Context, root Runner, args []string, opts ...Opt
205205
}
206206

207207
// formatError writes the error message and optional usage hint to w.
208-
func formatError(w io.Writer, root Runner, err error) {
208+
func formatError(w io.Writer, root Commander, err error) {
209209
fmt.Fprintf(w, "Error: %s\n", err) //nolint:errcheck
210210

211211
if _, isExit := err.(ExitCoder); !isExit && isFlagOrCommandError(err) {

command.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ type commandInfo struct {
1414
examples []Example
1515
}
1616

17-
func resolveInfo(cmd Runner) commandInfo {
17+
func resolveInfo(cmd Commander) commandInfo {
1818
info := commandInfo{
1919
name: defaultName(cmd),
2020
}
2121
if n, ok := cmd.(Namer); ok {
2222
info.name = n.Name()
2323
}
24-
if d, ok := cmd.(Describer); ok {
24+
if d, ok := cmd.(Descriptor); ok {
2525
info.description = d.Description()
2626
}
27-
if ld, ok := cmd.(LongDescriber); ok {
27+
if ld, ok := cmd.(LongDescriptor); ok {
2828
info.longDescription = ld.LongDescription()
2929
}
3030
if a, ok := cmd.(Aliaser); ok {
@@ -39,7 +39,7 @@ func resolveInfo(cmd Runner) commandInfo {
3939
return info
4040
}
4141

42-
func defaultName(cmd Runner) string {
42+
func defaultName(cmd Commander) string {
4343
t := reflect.TypeOf(cmd)
4444
if t.Kind() == reflect.Ptr {
4545
t = t.Elem()

complete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
// RuntimeComplete generates completion candidates for the given args and writes
3232
// them to w. Each candidate is one line, optionally followed by a tab and
3333
// description. The last line is a directive in the format ":<int>".
34-
func RuntimeComplete(ctx context.Context, root Runner, args []string, w io.Writer) {
34+
func RuntimeComplete(ctx context.Context, root Commander, args []string, w io.Writer) {
3535
completions, directive := computeCompletions(ctx, root, args)
3636
for _, c := range completions {
3737
fmt.Fprintln(w, c) //nolint:errcheck // best-effort completion output
@@ -41,7 +41,7 @@ func RuntimeComplete(ctx context.Context, root Runner, args []string, w io.Write
4141

4242
// computeCompletions resolves the command chain and returns completion
4343
// candidates with a directive.
44-
func computeCompletions(ctx context.Context, root Runner, args []string) ([]string, ShellCompDirective) {
44+
func computeCompletions(ctx context.Context, root Commander, args []string) ([]string, ShellCompDirective) {
4545
// Split args: everything except last is context, last is the prefix to complete.
4646
var contextArgs []string
4747
var toComplete string
@@ -170,7 +170,7 @@ func computeCompletions(ctx context.Context, root Runner, args []string) ([]stri
170170
}
171171

172172
// completeCommandFlags returns flag completions matching prefix.
173-
func completeCommandFlags(cmd Runner, prefix string) []string {
173+
func completeCommandFlags(cmd Commander, prefix string) []string {
174174
flags := ScanFlags(cmd)
175175
var candidates []string
176176
for i := range flags {
@@ -222,7 +222,7 @@ func completeCommandFlags(cmd Runner, prefix string) []string {
222222

223223
// lookupValueFlagName returns the flag name (without dashes) if arg matches
224224
// a non-bool, non-counter flag on cmd, or empty string if not found.
225-
func lookupValueFlagName(cmd Runner, arg string) string {
225+
func lookupValueFlagName(cmd Commander, arg string) string {
226226
if !strings.HasPrefix(arg, "-") {
227227
return ""
228228
}
@@ -245,7 +245,7 @@ func lookupValueFlagName(cmd Runner, arg string) string {
245245

246246
// lookupFlagEnum returns the Enum string for a flag matching the given arg
247247
// (e.g. "--format"), or empty if no match or no enum.
248-
func lookupFlagEnum(cmd Runner, arg string) string {
248+
func lookupFlagEnum(cmd Commander, arg string) string {
249249
if !strings.HasPrefix(arg, "-") {
250250
return ""
251251
}

complete_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type compRootCmd struct{}
1717

1818
func (c *compRootCmd) Run(_ context.Context) error { return nil }
1919
func (c *compRootCmd) Name() string { return "myapp" }
20-
func (c *compRootCmd) Subcommands() []cli.Runner {
21-
return []cli.Runner{&compServeCmd{}, &compDeployCmd{}, &compHiddenCmd{}}
20+
func (c *compRootCmd) Subcommands() []cli.Commander {
21+
return []cli.Commander{&compServeCmd{}, &compDeployCmd{}, &compHiddenCmd{}}
2222
}
2323

2424
type compServeCmd struct {
@@ -59,17 +59,17 @@ type compNestedRoot struct{}
5959

6060
func (c *compNestedRoot) Run(_ context.Context) error { return nil }
6161
func (c *compNestedRoot) Name() string { return "myapp" }
62-
func (c *compNestedRoot) Subcommands() []cli.Runner {
63-
return []cli.Runner{&compClusterCmd{}}
62+
func (c *compNestedRoot) Subcommands() []cli.Commander {
63+
return []cli.Commander{&compClusterCmd{}}
6464
}
6565

6666
type compClusterCmd struct{}
6767

6868
func (c *compClusterCmd) Run(_ context.Context) error { return nil }
6969
func (c *compClusterCmd) Name() string { return "cluster" }
7070
func (c *compClusterCmd) Description() string { return "Manage clusters" }
71-
func (c *compClusterCmd) Subcommands() []cli.Runner {
72-
return []cli.Runner{&compClusterListCmd{}}
71+
func (c *compClusterCmd) Subcommands() []cli.Commander {
72+
return []cli.Commander{&compClusterListCmd{}}
7373
}
7474

7575
type compClusterListCmd struct {
@@ -97,8 +97,8 @@ func (c *compCompleterNilCmd) Complete(_ context.Context, _ []string) ([]string,
9797
return nil, cli.ShellCompDirectiveDefault
9898
}
9999

100-
func (c *compCompleterNilCmd) Subcommands() []cli.Runner {
101-
return []cli.Runner{&compServeCmd{}}
100+
func (c *compCompleterNilCmd) Subcommands() []cli.Commander {
101+
return []cli.Commander{&compServeCmd{}}
102102
}
103103

104104
// completionNames extracts flag/command names from completion candidates.

completion/command.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import (
88
"github.com/bjaus/cli"
99
)
1010

11-
// Command returns a [cli.Runner] that prints shell completion scripts. It has
11+
// Command returns a [cli.Commander] that prints shell completion scripts. It has
1212
// bash, zsh, fish, and powershell subcommands. Output is written to w.
1313
// Typically added as a hidden "completion" subcommand:
1414
//
15-
// func (a *App) Subcommands() []cli.Runner {
16-
// return []cli.Runner{
15+
// func (a *App) Subcommands() []cli.Commander {
16+
// return []cli.Commander{
1717
// &serveCmd{},
1818
// completion.Command(a, "myapp", os.Stdout),
1919
// }
2020
// }
21-
func Command(root cli.Runner, appName string, w io.Writer) cli.Runner {
21+
func Command(root cli.Commander, appName string, w io.Writer) cli.Commander {
2222
return &completionCmd{root: root, appName: appName, out: w}
2323
}
2424

2525
type completionCmd struct {
26-
root cli.Runner
26+
root cli.Commander
2727
appName string
2828
out io.Writer
2929
}
@@ -36,8 +36,8 @@ func (c *completionCmd) Name() string { return "completion" }
3636
func (c *completionCmd) Description() string { return "Generate shell completion scripts" }
3737
func (c *completionCmd) Hidden() bool { return true }
3838

39-
func (c *completionCmd) Subcommands() []cli.Runner {
40-
return []cli.Runner{
39+
func (c *completionCmd) Subcommands() []cli.Commander {
40+
return []cli.Commander{
4141
&shellCmd{root: c.root, appName: c.appName, shell: "bash", out: c.out},
4242
&shellCmd{root: c.root, appName: c.appName, shell: "zsh", out: c.out},
4343
&shellCmd{root: c.root, appName: c.appName, shell: "fish", out: c.out},
@@ -46,7 +46,7 @@ func (c *completionCmd) Subcommands() []cli.Runner {
4646
}
4747

4848
type shellCmd struct {
49-
root cli.Runner
49+
root cli.Commander
5050
appName string
5151
shell string
5252
out io.Writer

completion/command_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func TestCommand_Structure(t *testing.T) {
2222
require.True(t, ok)
2323
assert.Equal(t, "completion", n.Name())
2424

25-
d, ok := cmd.(cli.Describer)
25+
d, ok := cmd.(cli.Descriptor)
2626
require.True(t, ok)
2727
assert.NotEmpty(t, d.Description())
2828

29-
p, ok := cmd.(cli.Parent)
29+
p, ok := cmd.(cli.Subcommander)
3030
require.True(t, ok)
3131

3232
subs := p.Subcommands()
@@ -38,7 +38,7 @@ func TestCommand_Structure(t *testing.T) {
3838
require.True(t, ok)
3939
assert.Equal(t, wantShells[i], n.Name())
4040

41-
d, ok := sub.(cli.Describer)
41+
d, ok := sub.(cli.Descriptor)
4242
require.True(t, ok)
4343
assert.NotEmpty(t, d.Description())
4444
}
@@ -74,7 +74,7 @@ func TestCommand_UsesWriter(t *testing.T) {
7474
var buf bytes.Buffer
7575
cmd := completion.Command(root, "myapp", &buf)
7676

77-
p, ok := cmd.(cli.Parent)
77+
p, ok := cmd.(cli.Subcommander)
7878
require.True(t, ok)
7979

8080
subs := p.Subcommands()
@@ -100,11 +100,11 @@ func TestCommand_ShellOutput(t *testing.T) {
100100

101101
var buf bytes.Buffer
102102
cmd := completion.Command(root, "myapp", &buf)
103-
p, ok := cmd.(cli.Parent)
103+
p, ok := cmd.(cli.Subcommander)
104104
require.True(t, ok)
105105

106106
// Find the matching shell subcommand.
107-
var target cli.Runner
107+
var target cli.Commander
108108
for _, sub := range p.Subcommands() {
109109
n, ok := sub.(cli.Namer)
110110
if ok && n.Name() == shell {

completion/completion.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package completion generates shell completion scripts from a [cli.Runner]
1+
// Package completion generates shell completion scripts from a [cli.Commander]
22
// command tree.
33
//
44
// Supported shells: bash, zsh, fish, and PowerShell. Each generator produces
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
// Bash generates a bash completion script that calls the binary at runtime.
28-
func Bash(_ cli.Runner, appName string) string {
28+
func Bash(_ cli.Commander, appName string) string {
2929
var b strings.Builder
3030
safe := bashSafe(appName)
3131

@@ -87,7 +87,7 @@ func Bash(_ cli.Runner, appName string) string {
8787
}
8888

8989
// Zsh generates a zsh completion script that calls the binary at runtime.
90-
func Zsh(_ cli.Runner, appName string) string {
90+
func Zsh(_ cli.Commander, appName string) string {
9191
var b strings.Builder
9292
safe := bashSafe(appName)
9393

@@ -147,7 +147,7 @@ func Zsh(_ cli.Runner, appName string) string {
147147
}
148148

149149
// Fish generates a fish completion script that calls the binary at runtime.
150-
func Fish(_ cli.Runner, appName string) string {
150+
func Fish(_ cli.Commander, appName string) string {
151151
var b strings.Builder
152152
safe := bashSafe(appName)
153153

@@ -183,7 +183,7 @@ func Fish(_ cli.Runner, appName string) string {
183183
}
184184

185185
// PowerShell generates a PowerShell completion script that calls the binary at runtime.
186-
func PowerShell(_ cli.Runner, appName string) string {
186+
func PowerShell(_ cli.Commander, appName string) string {
187187
var b strings.Builder
188188

189189
fmt.Fprintf(&b, "# PowerShell completion for %s\n\n", appName)

0 commit comments

Comments
 (0)