Compare commits
No commits in common. "main" and "v0.2.4" have entirely different histories.
16
command.go
16
command.go
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
type Command struct {
|
||||
Name string
|
||||
version string
|
||||
ShortDescription string
|
||||
LongDescription string
|
||||
Aliases []string
|
||||
|
@ -21,8 +20,8 @@ type Command struct {
|
|||
isRoot bool
|
||||
}
|
||||
|
||||
func NewRoot(name string, version string, options ...Option) *Command {
|
||||
cmd := &Command{Name: name, version: version, isRoot: true}
|
||||
func NewRoot(name string, options ...Option) *Command {
|
||||
cmd := &Command{Name: name, isRoot: true}
|
||||
cmd.ApplyOptions(options...)
|
||||
return cmd
|
||||
}
|
||||
|
@ -92,12 +91,6 @@ func (c *Command) Execute(args []string) {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
versionOpt, ok := opt.Globals().GetBool("version")
|
||||
if ok && versionOpt.Value() {
|
||||
c.ShowVersion()
|
||||
return
|
||||
}
|
||||
|
||||
helpOpt, ok := opt.Globals().GetBool("help")
|
||||
if ok && helpOpt.Value() {
|
||||
c.ShowHelp()
|
||||
|
@ -111,8 +104,3 @@ func (c *Command) Execute(args []string) {
|
|||
|
||||
c.ShowHelp()
|
||||
}
|
||||
|
||||
func (c *Command) ShowVersion() {
|
||||
rootName := c.Root().Name
|
||||
fmt.Printf("%s %s\n", rootName, c.version)
|
||||
}
|
||||
|
|
5
help.go
5
help.go
|
@ -2,7 +2,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go.fifitido.net/cmd/opt"
|
||||
)
|
||||
|
@ -44,10 +43,8 @@ func (c *Command) ShowHelp() {
|
|||
fmt.Println("Available subcommands:")
|
||||
}
|
||||
|
||||
paddedWidth := c.Subcommands.MaxWidth()
|
||||
for _, s := range c.Subcommands {
|
||||
spaceSize := 2 + paddedWidth - len(s.Name)
|
||||
fmt.Println(" " + s.Name + strings.Repeat(" ", spaceSize) + s.ShortDescription)
|
||||
fmt.Println(" " + s.Name + " " + s.ShortDescription)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue