-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store): add parameter families (#208)
feat(store): add parameter families (#208) feat(store): add worker pool family (#208) feat(store): add profile family (#208) feat(store): add preview family (#208) feat(store): add family usage test (#208)
- Loading branch information
1 parent
7e96fe5
commit c02c728
Showing
13 changed files
with
545 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
"magick", | ||
"memfs", | ||
"nakedret", | ||
"nicksnyder", | ||
"nolint", | ||
"nolintlint", | ||
"paramset", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package i18n | ||
|
||
// FilesGlobParamUsageTemplData | ||
// 🧊 | ||
type FilesGlobParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td FilesGlobParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "files-glob-filter.param-usage", | ||
Description: "files glob filter (negate-able with leading !)", | ||
Other: "files-gb files glob filter (negate-able with leading !)", | ||
} | ||
} | ||
|
||
// FilesRegExParamUsageTemplData | ||
// 🧊 | ||
type FilesRegExParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td FilesRegExParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "files-regex-filter.param-usage", | ||
Description: "files regex filter (negate-able with leading !)", | ||
Other: "files-rx folder regular expression filter (negate-able with leading !)", | ||
} | ||
} | ||
|
||
// FolderGlobParamUsageTemplData | ||
// 🧊 | ||
type FolderGlobParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td FolderGlobParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "folders-glob-filter.param-usage", | ||
Description: "folders glob (negate-able with leading !)", | ||
Other: "folders-gb folder glob filter (negate-able with leading !)", | ||
} | ||
} | ||
|
||
// FolderRexExParamUsageTemplData | ||
// 🧊 | ||
type FolderRexExParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td FolderRexExParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "folders-regex-filter.param-usage", | ||
Description: "folders regex filter (negate-able with leading !)", | ||
Other: "folders-rx folder regular expression filter (negate-able with leading !)", | ||
} | ||
} | ||
|
||
// WorkerPoolCPUParamUsageTemplData | ||
// 🧊 | ||
type WorkerPoolCPUParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td WorkerPoolCPUParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "worker-pool-cpu.param-usage", | ||
Description: "run with the number of workers in pool set to number of CPUs available", | ||
Other: "cpu denotes parallel execution with all available processors", | ||
} | ||
} | ||
|
||
// WorkerPoolCPUParamUsageTemplData | ||
// 🧊 | ||
type WorkerPoolNoWParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td WorkerPoolNoWParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "worker-pool-cpu.param-usage", | ||
Description: "run with the number of workers in pool set to this number", | ||
Other: "now denotes parallel execution with this number of workers in pool", | ||
} | ||
} | ||
|
||
// WorkerPoolCPUParamUsageTemplData | ||
// 🧊 | ||
type ProfileParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td ProfileParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "profile.param-usage", | ||
Description: "pre-defined flag/option list in config file", | ||
Other: "profile specifies which set of flags/options to load from config", | ||
} | ||
} | ||
|
||
// WorkerPoolCPUParamUsageTemplData | ||
// 🧊 | ||
type DryRunParamUsageTemplData struct { | ||
CobrassTemplData | ||
} | ||
|
||
func (td DryRunParamUsageTemplData) Message() *Message { | ||
return &Message{ | ||
ID: "dry-run.param-usage", | ||
Description: "allows the user to preview the effects of a command without running it", | ||
Other: "dry-run allows the user to see the effects of a command without running it", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package i18n | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func LeadsWith(name, text string) string { | ||
if strings.HasPrefix(text, name) { | ||
return text | ||
} | ||
|
||
return name + " " + text | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package store_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/snivilised/cobrass/src/assistant" | ||
"github.com/snivilised/cobrass/src/assistant/i18n" | ||
"github.com/snivilised/cobrass/src/internal/helpers" | ||
"github.com/snivilised/cobrass/src/store" | ||
xi18n "github.com/snivilised/extendio/i18n" | ||
) | ||
|
||
func reason(binder string, err error) string { | ||
return fmt.Sprintf("🔥 expected '%v' error to be nil, but was '%v'\n", | ||
binder, err, | ||
) | ||
} | ||
|
||
const ( | ||
shouldMessage = "🧪 should: bind all parameters without error" | ||
) | ||
|
||
var _ = Describe("Families", Ordered, func() { | ||
var ( | ||
repo string | ||
l10nPath string | ||
|
||
from xi18n.LoadFrom | ||
rootCommand *cobra.Command | ||
execute func(args []string) | ||
) | ||
|
||
BeforeAll(func() { | ||
repo = helpers.Repo("../..") | ||
l10nPath = helpers.Path(repo, "Test/data/l10n") | ||
|
||
from = xi18n.LoadFrom{ | ||
Path: l10nPath, | ||
Sources: xi18n.TranslationFiles{ | ||
i18n.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, | ||
}, | ||
} | ||
|
||
if err := xi18n.Use(func(o *xi18n.UseOptions) { | ||
o.From = from | ||
}); err != nil { | ||
Fail(err.Error()) | ||
} | ||
|
||
execute = func(args []string) { | ||
_, err := helpers.ExecuteCommand( | ||
rootCommand, args..., | ||
) | ||
Expect(err).Error().To(BeNil(), reason("BindAll", err)) | ||
} | ||
}) | ||
|
||
BeforeEach(func() { | ||
rootCommand = &cobra.Command{ | ||
Use: "scorch", | ||
Short: "scotch", | ||
Long: "scorch is a fake test command which contains filtering capabilities", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
}) | ||
|
||
DescribeTable("filter family", | ||
func(commandLine []string) { | ||
ps := assistant.NewParamSet[store.FilterParameterSet](rootCommand) | ||
ps.Native.BindAll(ps) | ||
|
||
execute(commandLine) | ||
}, | ||
func(args []string) string { | ||
return shouldMessage | ||
}, | ||
Entry( | ||
nil, []string{"--files-rx", "^foo", "--folders-gb", "bar*"}, | ||
), | ||
Entry( | ||
nil, []string{"-X", "^foo", "-z", "bar*"}, | ||
), | ||
Entry( | ||
nil, []string{"--files-gb", "foo*", "--folders-rx", "^bar"}, | ||
), | ||
Entry( | ||
nil, []string{"-G", "foo*", "-y", "^bar"}, | ||
), | ||
) | ||
|
||
DescribeTable("worker pool family", | ||
func(commandLine []string) { | ||
ps := assistant.NewParamSet[store.WorkerPoolParameterSet](rootCommand) | ||
ps.Native.BindAll(ps) | ||
|
||
execute(commandLine) | ||
}, | ||
func(args []string) string { | ||
return shouldMessage | ||
}, | ||
Entry( | ||
nil, []string{"--cpu"}, | ||
), | ||
Entry( | ||
nil, []string{"-C"}, | ||
), | ||
Entry( | ||
nil, []string{"--now", "4"}, | ||
), | ||
Entry( | ||
nil, []string{"-N", "4"}, | ||
), | ||
) | ||
|
||
DescribeTable("profile family", | ||
func(commandLine []string) { | ||
ps := assistant.NewParamSet[store.ProfileParameterSet](rootCommand) | ||
ps.Native.BindAll(ps) | ||
|
||
execute(commandLine) | ||
}, | ||
func(args []string) string { | ||
return shouldMessage | ||
}, | ||
Entry( | ||
nil, []string{"--profile", "foo"}, | ||
), | ||
Entry( | ||
nil, []string{"-P", "foo"}, | ||
), | ||
) | ||
|
||
DescribeTable("profile family", | ||
func(commandLine []string) { | ||
ps := assistant.NewParamSet[store.PreviewParameterSet](rootCommand) | ||
ps.Native.BindAll(ps) | ||
|
||
execute(commandLine) | ||
}, | ||
func(args []string) string { | ||
return shouldMessage | ||
}, | ||
Entry( | ||
nil, []string{"--dry-run"}, | ||
), | ||
Entry( | ||
nil, []string{"-D"}, | ||
), | ||
) | ||
|
||
When("usage requested", func() { | ||
It("should: 🧪 show help text", func() { | ||
filtersPS := assistant.NewParamSet[store.FilterParameterSet](rootCommand) | ||
filtersPS.Native.BindAll(filtersPS) | ||
// | ||
poolPS := assistant.NewParamSet[store.WorkerPoolParameterSet](rootCommand) | ||
poolPS.Native.BindAll(poolPS) | ||
// | ||
profilePS := assistant.NewParamSet[store.ProfileParameterSet](rootCommand) | ||
profilePS.Native.BindAll(profilePS) | ||
// | ||
previewPS := assistant.NewParamSet[store.PreviewParameterSet](rootCommand) | ||
previewPS.Native.BindAll(previewPS) | ||
// | ||
commandLine := []string{"scorch", "--help"} | ||
_, err := helpers.ExecuteCommand( | ||
rootCommand, commandLine..., | ||
) | ||
Expect(err).Error().To(BeNil(), reason("BindAll", err)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.