Skip to content

Commit 4164c33

Browse files
committed
feat: impl New which will use the module name for the root command name
1 parent c3a1a35 commit 4164c33

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

builder.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"runtime/debug"
45
"slices"
56
"strings"
67
)
@@ -19,6 +20,17 @@ var (
1920
errReqArgAfterOptional = "required positional arguments cannot come after optional ones"
2021
)
2122

23+
func New() CommandInfo {
24+
info, ok := debug.ReadBuildInfo()
25+
if !ok {
26+
panic("failed to read build info")
27+
}
28+
lastSlash := strings.LastIndexByte(info.Path, '/')
29+
modName := info.Path[lastSlash+1:]
30+
31+
return NewCmd(modName)
32+
}
33+
2234
func (c *CommandInfo) prepareAndValidate() {
2335
// Add the default help option here as long as this
2436
// command doesn't already have a help option.

0 commit comments

Comments
 (0)