From 5e452452392419de3a74615a4f9f8c2424615040 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 28 Dec 2023 14:43:38 +0000 Subject: [PATCH] feat(store): add depth family (#250) --- src/assistant/i18n/messages-command.go | 28 +++++++ src/store/families_test.go | 103 +++++++++++++++---------- src/store/family-depth.go | 50 ++++++++++++ src/store/family.go | 9 ++- 4 files changed, 148 insertions(+), 42 deletions(-) create mode 100644 src/store/family-depth.go diff --git a/src/assistant/i18n/messages-command.go b/src/assistant/i18n/messages-command.go index 69dadab..47b02ec 100644 --- a/src/assistant/i18n/messages-command.go +++ b/src/assistant/i18n/messages-command.go @@ -139,3 +139,31 @@ func (td LanguageParamUsageTemplData) Message() *Message { Other: "language allows the user to override the language the app runs in", } } + +// DepthDepthParamUsageTemplData +// 🧊 +type DepthDepthParamUsageTemplData struct { + CobrassTemplData +} + +func (td DepthDepthParamUsageTemplData) Message() *Message { + return &Message{ + ID: "depth-depth.param-usage", + Description: "limits the number of sub directories navigated", + Other: "depth denotes the number of sub directories to navigate", + } +} + +// DepthSkimParamUsageTemplData +// 🧊 +type DepthSkimParamUsageTemplData struct { + CobrassTemplData +} + +func (td DepthSkimParamUsageTemplData) Message() *Message { + return &Message{ + ID: "depth-skim.param-usage", + Description: "sets the navigator to not descend into sub directories", + Other: "skim sets the navigator to not descend into sub directories", + } +} diff --git a/src/store/families_test.go b/src/store/families_test.go index d48aa1d..b3abc6d 100644 --- a/src/store/families_test.go +++ b/src/store/families_test.go @@ -29,7 +29,7 @@ const ( // --folders-gb(Z) // --folders-rx(y) -type fileFamilyTE struct { +type familyTE struct { familyType string persistent bool commandLine []string @@ -82,7 +82,7 @@ var _ = Describe("Families", Ordered, func() { }) DescribeTable("filter family", - func(entry *fileFamilyTE) { + func(entry *familyTE) { switch entry.familyType { case "poly": { @@ -116,12 +116,12 @@ var _ = Describe("Families", Ordered, func() { execute(entry.commandLine) }, - func(entry *fileFamilyTE) string { + func(entry *familyTE) string { return shouldMessage }, Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "files", persistent: true, commandLine: []string{"--files-rx", "^foo"}, @@ -129,7 +129,7 @@ var _ = Describe("Families", Ordered, func() { ), Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "files", commandLine: []string{"-X", "^foo"}, }, @@ -137,14 +137,14 @@ var _ = Describe("Families", Ordered, func() { // Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "folders", commandLine: []string{"--folders-gb", "bar*"}, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "folders", persistent: true, commandLine: []string{"-Z", "bar*"}, @@ -153,21 +153,21 @@ var _ = Describe("Families", Ordered, func() { // Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "poly", commandLine: []string{"--files-rx", "^foo", "--folders-gb", "bar*"}, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "poly", commandLine: []string{"-X", "^foo", "-Z", "bar*"}, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "poly", persistent: true, commandLine: []string{"--files-gb", "foo*", "--folders-rx", "^bar"}, @@ -175,7 +175,7 @@ var _ = Describe("Families", Ordered, func() { ), Entry( nil, - &fileFamilyTE{ + &familyTE{ familyType: "poly", persistent: true, commandLine: []string{"-G", "foo*", "-Y", "^bar"}, @@ -186,7 +186,7 @@ var _ = Describe("Families", Ordered, func() { ) DescribeTable("worker pool family", - func(entry *fileFamilyTE) { + func(entry *familyTE) { ps := assistant.NewParamSet[store.WorkerPoolParameterSet](rootCommand) if entry.persistent { ps.Native.BindAll(ps, rootCommand.PersistentFlags()) @@ -196,39 +196,27 @@ var _ = Describe("Families", Ordered, func() { execute(entry.commandLine) }, - func(entry *fileFamilyTE) string { + func(entry *familyTE) string { return shouldMessage }, Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--cpu"}, persistent: true, }, ), Entry( nil, - &fileFamilyTE{ - commandLine: []string{"-C"}, - }, - ), - Entry( - nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--now", "4"}, persistent: true, }, ), - Entry( - nil, - &fileFamilyTE{ - commandLine: []string{"-N", "4"}, - }, - ), ) DescribeTable("profile family", - func(entry *fileFamilyTE) { + func(entry *familyTE) { ps := assistant.NewParamSet[store.ProfileParameterSet](rootCommand) if entry.persistent { ps.Native.BindAll(ps, rootCommand.PersistentFlags()) @@ -238,31 +226,31 @@ var _ = Describe("Families", Ordered, func() { execute(entry.commandLine) }, - func(entry *fileFamilyTE) string { + func(entry *familyTE) string { return shouldMessage }, Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--profile", "foo"}, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"-P", "foo"}, persistent: true, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--scheme", "foo"}, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"-S", "foo"}, persistent: true, }, @@ -270,7 +258,7 @@ var _ = Describe("Families", Ordered, func() { ) DescribeTable("preview family", - func(entry *fileFamilyTE) { + func(entry *familyTE) { ps := assistant.NewParamSet[store.PreviewParameterSet](rootCommand) if entry.persistent { ps.Native.BindAll(ps, rootCommand.PersistentFlags()) @@ -280,26 +268,26 @@ var _ = Describe("Families", Ordered, func() { execute(entry.commandLine) }, - func(entry *fileFamilyTE) string { + func(entry *familyTE) string { return shouldMessage }, Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--dry-run"}, persistent: true, }, ), Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"-D"}, }, ), ) DescribeTable("i18n family", - func(entry *fileFamilyTE) { + func(entry *familyTE) { ps := assistant.NewParamSet[store.I18nParameterSet](rootCommand) if entry.persistent { ps.Native.BindAll(ps, rootCommand.PersistentFlags()) @@ -309,12 +297,12 @@ var _ = Describe("Families", Ordered, func() { execute(entry.commandLine) }, - func(entry *fileFamilyTE) string { + func(entry *familyTE) string { return shouldMessage }, Entry( nil, - &fileFamilyTE{ + &familyTE{ commandLine: []string{"--language", "en-GB"}, persistent: true, }, @@ -342,4 +330,39 @@ var _ = Describe("Families", Ordered, func() { Expect(err).Error().To(BeNil(), reason("BindAll", err)) }) }) + + DescribeTable("depth family", + func(entry *familyTE) { + ps := assistant.NewParamSet[store.DepthParameterSet](rootCommand) + if entry.persistent { + ps.Native.BindAll(ps, rootCommand.PersistentFlags()) + } else { + ps.Native.BindAll(ps) + } + + execute(entry.commandLine) + }, + func(entry *familyTE) string { + return shouldMessage + }, + Entry( + nil, + &familyTE{ + commandLine: []string{"--depth", "3"}, + }, + ), + Entry( + nil, + &familyTE{ + commandLine: []string{"--skim"}, + }, + ), + Entry( + nil, + &familyTE{ + commandLine: []string{"-K"}, + persistent: true, + }, + ), + ) }) diff --git a/src/store/family-depth.go b/src/store/family-depth.go new file mode 100644 index 0000000..b295232 --- /dev/null +++ b/src/store/family-depth.go @@ -0,0 +1,50 @@ +package store + +import ( + "github.com/snivilised/cobrass/src/assistant" + "github.com/snivilised/cobrass/src/assistant/i18n" + xi18n "github.com/snivilised/extendio/i18n" + "github.com/spf13/pflag" +) + +type DepthParameterSet struct { + Depth uint + Skim bool +} + +func (f *DepthParameterSet) BindAll( + parent *assistant.ParamSet[DepthParameterSet], + flagSet ...*pflag.FlagSet, +) { + // --depth + // + const ( + defaultDepth = uint(0) + ) + + parent.BindUint( + resolveNewFlagInfo( + xi18n.Text(i18n.DepthDepthParamUsageTemplData{}), + defaultDepth, + flagSet..., + ), + &parent.Native.Depth, + ) + + // --skim(K) + // + const ( + defaultSkim = false + ) + + parent.BindBool( + resolveNewFlagInfo( + xi18n.Text(i18n.DepthSkimParamUsageTemplData{}), + defaultSkim, + flagSet..., + ), + &parent.Native.Skim, + ) + + parent.Command.MarkFlagsMutuallyExclusive("depth", "skim") +} diff --git a/src/store/family.go b/src/store/family.go index af58be3..a399fbd 100644 --- a/src/store/family.go +++ b/src/store/family.go @@ -16,8 +16,8 @@ type FlagDefinitions map[LongFlagName]ShortFlagName var ShortFlags = FlagDefinitions{ // worker pool family // - "cpu": "C", - "now": "N", + "cpu": "", + "now": "", // preview family // @@ -38,6 +38,11 @@ var ShortFlags = FlagDefinitions{ // i18n family (niche option, so let's define without a short code) // "language": "", + + // depth family + // + "depth": "", + "skim": "K", } func newFlagInfo[T any](usage string, defaultValue T) *assistant.FlagInfo {