Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store): add depth family (#250) #251

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/assistant/i18n/messages-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
103 changes: 63 additions & 40 deletions src/store/families_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
// --folders-gb(Z)
// --folders-rx(y)

type fileFamilyTE struct {
type familyTE struct {
familyType string
persistent bool
commandLine []string
Expand Down Expand Up @@ -82,7 +82,7 @@ var _ = Describe("Families", Ordered, func() {
})

DescribeTable("filter family",
func(entry *fileFamilyTE) {
func(entry *familyTE) {
switch entry.familyType {
case "poly":
{
Expand Down Expand Up @@ -116,35 +116,35 @@ 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"},
},
),
Entry(
nil,
&fileFamilyTE{
&familyTE{
familyType: "files",
commandLine: []string{"-X", "^foo"},
},
),
//
Entry(
nil,
&fileFamilyTE{
&familyTE{
familyType: "folders",
commandLine: []string{"--folders-gb", "bar*"},
},
),
Entry(
nil,
&fileFamilyTE{
&familyTE{
familyType: "folders",
persistent: true,
commandLine: []string{"-Z", "bar*"},
Expand All @@ -153,29 +153,29 @@ 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"},
},
),
Entry(
nil,
&fileFamilyTE{
&familyTE{
familyType: "poly",
persistent: true,
commandLine: []string{"-G", "foo*", "-Y", "^bar"},
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -238,39 +226,39 @@ 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,
},
),
)

DescribeTable("preview family",
func(entry *fileFamilyTE) {
func(entry *familyTE) {
ps := assistant.NewParamSet[store.PreviewParameterSet](rootCommand)
if entry.persistent {
ps.Native.BindAll(ps, rootCommand.PersistentFlags())
Expand All @@ -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())
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
},
),
)
})
50 changes: 50 additions & 0 deletions src/store/family-depth.go
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 7 additions & 2 deletions src/store/family.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type FlagDefinitions map[LongFlagName]ShortFlagName
var ShortFlags = FlagDefinitions{
// worker pool family
//
"cpu": "C",
"now": "N",
"cpu": "",
"now": "",

// preview family
//
Expand All @@ -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 {
Expand Down