Hide hidden sub-commands.

This commit is contained in:
Alec Thomas
2019-03-29 11:08:28 +11:00
parent 42ea64b1b4
commit 4e9878074f
5 changed files with 24 additions and 11 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
command: |
go get -v github.com/jstemmer/go-junit-report
go get -v -t -d ./...
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s v1.10.2
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s v1.15.0
mkdir ~/report
when: always
- run:
+1
View File
@@ -9,6 +9,7 @@ linters:
disable:
- maligned
- lll
- gochecknoglobals
linters-settings:
govet:
+20 -9
View File
@@ -142,6 +142,9 @@ func printNodeDetail(w *helpWriter, node *Node, hide bool) {
func writeCommandList(cmds []*Node, iw *helpWriter) {
for i, cmd := range cmds {
if cmd.Hidden {
continue
}
printCommandSummary(iw, cmd)
if i != len(cmds)-1 {
iw.Print("")
@@ -152,29 +155,37 @@ func writeCommandList(cmds []*Node, iw *helpWriter) {
func writeCompactCommandList(cmds []*Node, iw *helpWriter) {
rows := [][2]string{}
for _, cmd := range cmds {
if cmd.Hidden {
continue
}
rows = append(rows, [2]string{cmd.Path(), cmd.Help})
}
writeTwoColumns(iw, defaultColumnPadding, rows)
writeTwoColumns(iw, rows)
}
func writeCommandTree(w *helpWriter, node *Node) {
iw := w.Indent()
rows := make([][2]string, 0, len(node.Children)*2)
for i, cmd := range node.Children {
if cmd.Hidden {
continue
}
rows = append(rows, w.commandTree(cmd, "")...)
if i != len(node.Children)-1 {
rows = append(rows, [2]string{"", ""})
}
}
writeTwoColumns(iw, defaultColumnPadding, rows)
writeTwoColumns(iw, rows)
}
// nolint: unused
type helpCommandGroup struct {
Name string
Commands []*Node
}
func collectCommandGroups(nodes []*Node) []helpCommandGroup { // nolint: deadcode
// nolint: unused, deadcode
func collectCommandGroups(nodes []*Node) []helpCommandGroup {
groups := map[string][]*Node{}
for _, node := range nodes {
groups[node.Group] = append(groups[node.Group], node)
@@ -253,7 +264,7 @@ func writePositionals(w *helpWriter, args []*Positional) {
for _, arg := range args {
rows = append(rows, [2]string{arg.Summary(), arg.Help})
}
writeTwoColumns(w, defaultColumnPadding, rows)
writeTwoColumns(w, rows)
}
func writeFlags(w *helpWriter, groups [][]*Flag) {
@@ -277,10 +288,10 @@ func writeFlags(w *helpWriter, groups [][]*Flag) {
}
}
}
writeTwoColumns(w, defaultColumnPadding, rows)
writeTwoColumns(w, rows)
}
func writeTwoColumns(w *helpWriter, padding int, rows [][2]string) {
func writeTwoColumns(w *helpWriter, rows [][2]string) {
maxLeft := 375 * w.width / 1000
if maxLeft < 30 {
maxLeft = 30
@@ -293,16 +304,16 @@ func writeTwoColumns(w *helpWriter, padding int, rows [][2]string) {
}
}
offsetStr := strings.Repeat(" ", leftSize+padding)
offsetStr := strings.Repeat(" ", leftSize+defaultColumnPadding)
for _, row := range rows {
buf := bytes.NewBuffer(nil)
doc.ToText(buf, row[1], "", strings.Repeat(" ", defaultIndent), w.width-leftSize-padding)
doc.ToText(buf, row[1], "", strings.Repeat(" ", defaultIndent), w.width-leftSize-defaultColumnPadding)
lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
line := fmt.Sprintf("%-*s", leftSize, row[0])
if len(row[0]) < maxLeft {
line += fmt.Sprintf("%*s%s", padding, "", lines[0])
line += fmt.Sprintf("%*s%s", defaultColumnPadding, "", lines[0])
lines = lines[1:]
}
w.Print(line)
+1
View File
@@ -409,6 +409,7 @@ func TestHooks(t *testing.T) {
for _, test := range tests {
*ctx = hookContext{}
cli.One = hookCmd{}
// nolint: scopelint
t.Run(test.name, func(t *testing.T) {
_, err := p.Parse(strings.Split(test.input, " "))
require.NoError(t, err)
+1 -1
View File
@@ -13,7 +13,7 @@ type ConfigFlag string
// BeforeResolve adds a resolver.
func (c ConfigFlag) BeforeResolve(kong *Kong, ctx *Context, trace *Path) error {
if kong.loader == nil {
return fmt.Errorf("Kong must be configured with kong.Configuration(...)")
return fmt.Errorf("kong must be configured with kong.Configuration(...)")
}
path := string(ctx.FlagValue(trace.Flag).(ConfigFlag))
resolver, err := kong.LoadConfig(path)