diff --git a/example/cmd/action_test.go b/example/cmd/action_test.go index a390ee22..1668399b 100644 --- a/example/cmd/action_test.go +++ b/example/cmd/action_test.go @@ -20,31 +20,146 @@ func TestAction(t *testing.T) { s.Reply("git", "remote").With("origin\nfork") - s.Run("action", "--callback", "").Expect(carapace.ActionMessage("values flag is not set").NoSpace().Usage("ActionCallback()")) - s.Run("action", "--values", "first", "--callback", "").Expect(carapace.ActionMessage("values flag is set to: 'first'").NoSpace().Usage("ActionCallback()")) - s.Run("action", "--directories", "").Expect(carapace.ActionValues("dirA/", "dirB/").Tag("directories").StyleF(style.ForPath).NoSpace('/').Usage("ActionDirectories()")) - s.Run("action", "--directories", "dirB/").Expect(carapace.ActionValues("dirC/").Prefix("dirB/").Tag("directories").StyleF(style.ForPath).NoSpace('/').Usage("ActionDirectories()")) - s.Run("action", "--exec-command", "").Expect(carapace.ActionValues("origin", "fork").Usage("ActionExecCommand()")) - s.Run("action", "--files", "").Expect(carapace.ActionValues("dirA/", "dirB/", "file5.go").Tag("files").StyleF(style.ForPath).NoSpace('/').Usage("ActionFiles()")) - s.Run("action", "--files-filtered", "").Expect(carapace.ActionValues("dirA/", "dirB/").Tag("files").StyleF(style.ForPath).NoSpace('/').Usage("ActionFiles(\".md\", \"go.mod\", \"go.sum\")")) - s.Run("action", "--files-filtered", "dirB/").Expect(carapace.ActionValues("dirC/", "file4.md").Tag("files").Prefix("dirB/").StyleF(style.ForPath).NoSpace('/').Usage("ActionFiles(\".md\", \"go.mod\", \"go.sum\")")) - s.Run("action", "--import", "").Expect(carapace.ActionValues("first", "second", "third").Usage("ActionImport()")) - s.Run("action", "--import", "s").Expect(carapace.ActionValues("second").Usage("ActionImport()")) - s.Run("action", "--message", "").Expect(carapace.ActionMessage("example message").NoSpace().Usage("ActionMessage()")) - s.Run("action", "--message-multiple", "t").Expect(carapace.Batch(carapace.ActionMessage("first message"), carapace.ActionMessage("second message"), carapace.ActionMessage("third message"), carapace.ActionValues("one", "two", "three")).ToA().NoSpace().Usage("ActionMessage()")) - s.Run("action", "--multiparts", "").Expect(carapace.ActionValues("userA", "userB").Suffix(":").NoSpace(':').Usage("ActionMultiParts()")) - s.Run("action", "--multiparts", "userA:").Expect(carapace.ActionValues("groupA", "groupB").Prefix("userA:").NoSpace(':').Usage("ActionMultiParts()")) - s.Run("action", "--multiparts-nested", "").Expect(carapace.ActionValues("DIRECTORY", "FILE", "VALUE").Suffix("=").NoSpace(',', '=').Usage("ActionMultiParts(...ActionMultiParts...)")) - s.Run("action", "--multiparts-nested", "VALUE=").Expect(carapace.ActionValues("one", "two", "three").Prefix("VALUE=").NoSpace().Usage("ActionMultiParts(...ActionMultiParts...)")) - s.Run("action", "--multiparts-nested", "VALUE=two,").Expect(carapace.ActionValues("DIRECTORY", "FILE").Prefix("VALUE=two,").Suffix("=").NoSpace(',', '=').Usage("ActionMultiParts(...ActionMultiParts...)")) - s.Run("action", "--multiparts-nested", "VALUE=two,DIRECTORY=").Expect(carapace.ActionValues("dirA/", "dirB/").Tag("directories").StyleF(style.ForPath).Prefix("VALUE=two,DIRECTORY=").NoSpace().Usage("ActionMultiParts(...ActionMultiParts...)")) - s.Run("action", "--styled-values", "s").Expect(carapace.ActionStyledValues("second", style.Blue).Usage("ActionStyledValues()")) - s.Run("action", "--styled-values-described", "t").Expect(carapace.ActionStyledValuesDescribed("third", "description of third", style.Of("#112233", style.Italic), "thirdalias", "description of third", style.BgBrightMagenta).Usage("ActionStyledValuesDescribed()")) - s.Run("action", "--values", "sec").Expect(carapace.ActionValues("second").Usage("ActionValues()")) - s.Run("action", "--values-described", "third").Expect(carapace.ActionValuesDescribed("third", "description of third").Usage("ActionValuesDescribed()")) - s.Run("action", "pos").Expect(carapace.ActionValues("positional1", "positional1 with space").Usage("action [pos1] [pos2] [--] [dashAny]...")) - s.Run("action", "p1", "positional2 ").Expect(carapace.ActionValues("positional2 with space").Usage("action [pos1] [pos2] [--] [dashAny]...")) - - s.Run("action", "--unknown", "").Expect(carapace.ActionMessage("unknown flag: --unknown")) + s.Run("action", "--callback", ""). + Expect(carapace.ActionMessage("values flag is not set"). + NoSpace(). + Usage("ActionCallback()")) + + s.Run("action", "--values", "first", "--callback", ""). + Expect(carapace.ActionMessage("values flag is set to: 'first'"). + NoSpace(). + Usage("ActionCallback()")) + + s.Run("action", "--directories", ""). + Expect(carapace.ActionValues("dirA/", "dirB/"). + Tag("directories"). + StyleF(style.ForPath). + NoSpace('/'). + Usage("ActionDirectories()")) + + s.Run("action", "--directories", "dirB/"). + Expect(carapace.ActionValues("dirC/"). + Prefix("dirB/"). + Tag("directories"). + StyleF(style.ForPath). + NoSpace('/'). + Usage("ActionDirectories()")) + + s.Run("action", "--exec-command", ""). + Expect(carapace.ActionValues("origin", "fork"). + Usage("ActionExecCommand()")) + + s.Run("action", "--files", ""). + Expect(carapace.ActionValues("dirA/", "dirB/", "file5.go"). + Tag("files"). + StyleF(style.ForPath). + NoSpace('/'). + Usage("ActionFiles()")) + + s.Run("action", "--files-filtered", ""). + Expect(carapace.ActionValues("dirA/", "dirB/"). + Tag("files"). + StyleF(style.ForPath). + NoSpace('/'). + Usage("ActionFiles(\".md\", \"go.mod\", \"go.sum\")")) + + s.Run("action", "--files-filtered", "dirB/"). + Expect(carapace.ActionValues("dirC/", "file4.md"). + Tag("files"). + Prefix("dirB/"). + StyleF(style.ForPath). + NoSpace('/'). + Usage("ActionFiles(\".md\", \"go.mod\", \"go.sum\")")) + + s.Run("action", "--import", ""). + Expect(carapace.ActionValues("first", "second", "third"). + Usage("ActionImport()")) + + s.Run("action", "--import", "s"). + Expect(carapace.ActionValues("second"). + Usage("ActionImport()")) + + s.Run("action", "--message", ""). + Expect(carapace.ActionMessage("example message"). + NoSpace(). + Usage("ActionMessage()")) + + s.Run("action", "--message-multiple", "t"). + Expect(carapace.Batch( + carapace.ActionMessage("first message"), + carapace.ActionMessage("second message"), + carapace.ActionMessage("third message"), + carapace.ActionValues("one", "two", "three")). + ToA(). + NoSpace(). + Usage("ActionMessage()")) + + s.Run("action", "--multiparts", ""). + Expect(carapace.ActionValues("userA", "userB"). + Suffix(":"). + NoSpace(':'). + Usage("ActionMultiParts()")) + + s.Run("action", "--multiparts", "userA:"). + Expect(carapace.ActionValues("groupA", "groupB"). + Prefix("userA:"). + NoSpace(':'). + Usage("ActionMultiParts()")) + + s.Run("action", "--multiparts-nested", ""). + Expect(carapace.ActionValues("DIRECTORY", "FILE", "VALUE"). + Suffix("="). + NoSpace(',', '='). + Usage("ActionMultiParts(...ActionMultiParts...)")) + + s.Run("action", "--multiparts-nested", "VALUE="). + Expect(carapace.ActionValues("one", "two", "three"). + Prefix("VALUE="). + NoSpace(). + Usage("ActionMultiParts(...ActionMultiParts...)")) + + s.Run("action", "--multiparts-nested", "VALUE=two,"). + Expect(carapace.ActionValues("DIRECTORY", "FILE"). + Prefix("VALUE=two,"). + Suffix("="). + NoSpace(',', '='). + Usage("ActionMultiParts(...ActionMultiParts...)")) + + s.Run("action", "--multiparts-nested", "VALUE=two,DIRECTORY="). + Expect(carapace.ActionValues("dirA/", "dirB/"). + Tag("directories"). + StyleF(style.ForPath). + Prefix("VALUE=two,DIRECTORY="). + NoSpace(). + Usage("ActionMultiParts(...ActionMultiParts...)")) + + s.Run("action", "--styled-values", "s"). + Expect(carapace.ActionStyledValues("second", style.Blue). + Usage("ActionStyledValues()")) + + s.Run("action", "--styled-values-described", "t"). + Expect(carapace.ActionStyledValuesDescribed( + "third", "description of third", style.Of("#112233", style.Italic), + "thirdalias", "description of third", style.BgBrightMagenta). + Usage("ActionStyledValuesDescribed()")) + + s.Run("action", "--values", "sec"). + Expect(carapace.ActionValues("second"). + Usage("ActionValues()")) + + s.Run("action", "--values-described", "third"). + Expect(carapace.ActionValuesDescribed("third", "description of third"). + Usage("ActionValuesDescribed()")) + + s.Run("action", "pos"). + Expect(carapace.ActionValues("positional1", "positional1 with space"). + Usage("action [pos1] [pos2] [--] [dashAny]...")) + + s.Run("action", "p1", "positional2 "). + Expect(carapace.ActionValues("positional2 with space"). + Usage("action [pos1] [pos2] [--] [dashAny]...")) + + s.Run("action", "--unknown", ""). + Expect(carapace.ActionMessage("unknown flag: --unknown")) }) } diff --git a/example/cmd/multiparts_test.go b/example/cmd/multiparts_test.go index cef4b534..20b59200 100644 --- a/example/cmd/multiparts_test.go +++ b/example/cmd/multiparts_test.go @@ -17,15 +17,63 @@ func TestMultiparts(t *testing.T) { "dirB/file4.md", "", "file5.go", "", ) - s.Run("multiparts", "").Expect(carapace.ActionValues("DIRECTORY", "FILE", "VALUE").Suffix("=").NoSpace(',', '=')) - s.Run("multiparts", "D").Expect(carapace.ActionValues("DIRECTORY").Suffix("=").NoSpace(',', '=')) - s.Run("multiparts", "DIRECTORY").Expect(carapace.ActionValues("DIRECTORY").Suffix("=").NoSpace(',', '=')) - s.Run("multiparts", "DIRECTORY=").Expect(carapace.ActionValues("dirA/", "dirB/").Tag("directories").StyleF(style.ForPath).Prefix("DIRECTORY=").NoSpace(',', '/', '=')) - s.Run("multiparts", "VALUE=").Expect(carapace.ActionValues("one", "two", "three").Prefix("VALUE=").NoSpace(',', '=')) - s.Run("multiparts", "VALUE=o").Expect(carapace.ActionValues("one").Prefix("VALUE=").NoSpace(',', '=')) - s.Run("multiparts", "VALUE=one,").Expect(carapace.ActionValues("DIRECTORY", "FILE").Prefix("VALUE=one,").Suffix("=").NoSpace(',', '=')) - s.Run("multiparts", "VALUE=one,F").Expect(carapace.ActionValues("FILE").Prefix("VALUE=one,").Suffix("=").NoSpace(',', '=')) - s.Run("multiparts", "VALUE=one,FILE=").Expect(carapace.ActionValues("dirA/", "dirB/", "file5.go").Tag("files").StyleF(style.ForPath).Prefix("VALUE=one,FILE=").NoSpace(',', '/', '=')) - s.Run("multiparts", "VALUE=one,FILE=dirB/").Expect(carapace.ActionValues("dirC/", "file4.md").Tag("files").Prefix("dirB/").StyleF(style.ForPath).Prefix("VALUE=one,FILE=").NoSpace(',', '/', '=')) + s.Run("multiparts", ""). + Expect(carapace.ActionValues("DIRECTORY", "FILE", "VALUE"). + Suffix("="). + NoSpace(',', '=')) + + s.Run("multiparts", "D"). + Expect(carapace.ActionValues("DIRECTORY"). + Suffix("="). + NoSpace(',', '=')) + + s.Run("multiparts", "DIRECTORY"). + Expect(carapace.ActionValues("DIRECTORY"). + Suffix("="). + NoSpace(',', '=')) + + s.Run("multiparts", "DIRECTORY="). + Expect(carapace.ActionValues("dirA/", "dirB/"). + Tag("directories"). + StyleF(style.ForPath). + Prefix("DIRECTORY="). + NoSpace(',', '/', '=')) + + s.Run("multiparts", "VALUE="). + Expect(carapace.ActionValues("one", "two", "three"). + Prefix("VALUE="). + NoSpace(',', '=')) + + s.Run("multiparts", "VALUE=o"). + Expect(carapace.ActionValues("one"). + Prefix("VALUE="). + NoSpace(',', '=')) + + s.Run("multiparts", "VALUE=one,"). + Expect(carapace.ActionValues("DIRECTORY", "FILE"). + Prefix("VALUE=one,"). + Suffix("="). + NoSpace(',', '=')) + + s.Run("multiparts", "VALUE=one,F"). + Expect(carapace.ActionValues("FILE"). + Prefix("VALUE=one,"). + Suffix("="). + NoSpace(',', '=')) + + s.Run("multiparts", "VALUE=one,FILE="). + Expect(carapace.ActionValues("dirA/", "dirB/", "file5.go"). + Tag("files"). + StyleF(style.ForPath). + Prefix("VALUE=one,FILE="). + NoSpace(',', '/', '=')) + + s.Run("multiparts", "VALUE=one,FILE=dirB/"). + Expect(carapace.ActionValues("dirC/", "file4.md"). + Tag("files"). + Prefix("dirB/"). + StyleF(style.ForPath). + Prefix("VALUE=one,FILE="). + NoSpace(',', '/', '=')) }) } diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go index 79719a38..7d0d2cc7 100644 --- a/example/cmd/root_test.go +++ b/example/cmd/root_test.go @@ -58,64 +58,73 @@ func TestZsh(t *testing.T) { func TestRoot(t *testing.T) { sandbox.Run(t, "github.com/rsteube/carapace/example")(func(s *sandbox.Sandbox) { - s.Run("").Expect(carapace.Batch( - carapace.ActionValuesDescribed( - "action", "action example", - "alias", "action example", - "flag", "flag example", - ).Style(style.Blue).Tag("main commands"), - carapace.ActionValuesDescribed( - "modifier", "modifier example", - ).Style(style.Yellow).Tag("modifier commands"), - carapace.ActionValuesDescribed( - "injection", "just trying to break things", - ).Style(style.Magenta).Tag("test commands"), - carapace.ActionValuesDescribed( - "completion", "Generate the autocompletion script for the specified shell", - "help", "Help about any command", - "multiparts", "multiparts example", - "special", "", - ).Tag("other commands"), - ).ToA()) - - s.Run("a").Expect(carapace.ActionStyledValuesDescribed( - "action", "action example", style.Blue, - "alias", "action example", style.Blue, - ).Tag("main commands")) - - s.Run("action").Expect(carapace.ActionStyledValuesDescribed( - "action", "action example", style.Blue, - ).Tag("main commands")) - - s.Run("-").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - "-a", "multiflag", - "--persistentFlag", "Help message for persistentFlag", - "-p", "Help message for persistentFlag", - "--toggle", "Help message for toggle", - "-t", "Help message for toggle", - ).Tag("flags")) - - s.Run("--").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - "--persistentFlag", "Help message for persistentFlag", - "--toggle", "Help message for toggle", - ).Tag("flags")) - - s.Run("--a").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - ).Tag("flags")) - - s.Run("--array").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - ).Tag("flags")) - - s.Run("--array", "", "--a").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - ).Tag("flags")) - - s.Run("-a", "", "--a").Expect(carapace.ActionValuesDescribed( - "--array", "multiflag", - ).Tag("flags")) + s.Run(""). + Expect(carapace.Batch( + carapace.ActionValuesDescribed( + "action", "action example", + "alias", "action example", + "flag", "flag example", + ).Style(style.Blue).Tag("main commands"), + carapace.ActionValuesDescribed( + "modifier", "modifier example", + ).Style(style.Yellow).Tag("modifier commands"), + carapace.ActionValuesDescribed( + "injection", "just trying to break things", + ).Style(style.Magenta).Tag("test commands"), + carapace.ActionValuesDescribed( + "completion", "Generate the autocompletion script for the specified shell", + "help", "Help about any command", + "multiparts", "multiparts example", + "special", "", + ).Tag("other commands"), + ).ToA()) + + s.Run("a"). + Expect(carapace.ActionStyledValuesDescribed( + "action", "action example", style.Blue, + "alias", "action example", style.Blue, + ).Tag("main commands")) + + s.Run("action"). + Expect(carapace.ActionStyledValuesDescribed( + "action", "action example", style.Blue, + ).Tag("main commands")) + + s.Run("-"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + "-a", "multiflag", + "--persistentFlag", "Help message for persistentFlag", + "-p", "Help message for persistentFlag", + "--toggle", "Help message for toggle", + "-t", "Help message for toggle", + ).Tag("flags")) + + s.Run("--"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + "--persistentFlag", "Help message for persistentFlag", + "--toggle", "Help message for toggle", + ).Tag("flags")) + + s.Run("--a"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + ).Tag("flags")) + + s.Run("--array"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + ).Tag("flags")) + + s.Run("--array", "", "--a"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + ).Tag("flags")) + + s.Run("-a", "", "--a"). + Expect(carapace.ActionValuesDescribed( + "--array", "multiflag", + ).Tag("flags")) }) }