Add generated help and version commands

This commit is contained in:
2026-10-07 13:37:57 +00:00
parent c3448a2ebe
commit ecd2b19783
13 changed files with 736 additions and 27 deletions

View File

@@ -6,6 +6,8 @@ import (
"reflect"
"strings"
"testing"
spfcobra "github.com/spf13/cobra"
)
func TestParseRoutesBeforeOptionsAndKeepsFlagsLocal(t *testing.T) {
@@ -29,6 +31,18 @@ func TestParseRoutesBeforeOptionsAndKeepsFlagsLocal(t *testing.T) {
}
}
func TestParseRequiresExactCommandPathWhenPrefixMatchingIsEnabled(t *testing.T) {
previous := spfcobra.EnablePrefixMatching
spfcobra.EnablePrefixMatching = true
t.Cleanup(func() { spfcobra.EnablePrefixMatching = previous })
tree := &Command{Name: "app", Children: []*Command{{Name: "config", Runnable: true}}}
result := Parse(tree, []string{"con"}, ParseOptions{})
if result.Failure == nil {
t.Fatal("accepted a prefixed command path")
}
}
func TestParseInterspersedOperandsBooleanFlagsAndTerminator(t *testing.T) {
tree := &Command{Name: "app", Children: []*Command{
{Name: "restore", Runnable: true, Flags: []Flag{