Skip to content

Commit

Permalink
refactor: flags caches, emptyInput
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Dec 18, 2024
1 parent 7597568 commit 9dc55d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
18 changes: 12 additions & 6 deletions cmd/pimo/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ type flag[T any] struct {
usage string // Description of the flag
}

// flags
// flags with default values
//
//nolint:gochecknoglobals
var (
maxBufferCapacity int
catchErrors string
maxBufferCapacity = 64
catchErrors = ""
maskingFile = "masking.yml"
mockConfigFile = "routes.yaml"
cachesToDump = map[string]string{}
cachesToLoad = map[string]string{}
emptyInput = false
)

var (
flagBufferSize = flag[int]{name: "buffer-size", variable: &maxBufferCapacity, usage: "buffer size in kB to load data from uri for each line"}
flagCatchErrors = flag[string]{name: "catch-errors", variable: &catchErrors, usage: "catch errors and write line in file, same as using skip-field-on-error + skip-log-file"}
flagConfigMasking = flag[string]{name: "config", variable: &maskingFile, usage: "name and location of the masking config file"}
flagConfigRoute = flag[string]{name: "config", variable: &mockConfigFile, usage: "name and location of the routes config file"}
flagCatchErrors = flag[string]{name: "catch-errors", shorthand: "e", variable: &catchErrors, usage: "catch errors and write line in file, same as using skip-field-on-error + skip-log-file"}
flagConfigMasking = flag[string]{name: "config", shorthand: "c", variable: &maskingFile, usage: "name and location of the masking config file"}
flagConfigRoute = flag[string]{name: "config", shorthand: "c", variable: &mockConfigFile, usage: "name and location of the routes config file"}
flagCachesToDump = flag[map[string]string]{name: "dump-cache", variable: &cachesToDump, usage: "path for dumping cache into file"}
flagCachesToLoad = flag[map[string]string]{name: "load-cache", variable: &cachesToLoad, usage: "path for loading cache from file"}
flagEmptyInput = flag[bool]{name: "empty-input", variable: &emptyInput, usage: "generate data without any input, to use with repeat flag"}
)

func addFlag[T any](cmd *cobra.Command, flag flag[T]) {
Expand Down
13 changes: 7 additions & 6 deletions cmd/pimo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ var (
jsonlog bool
colormode string
iteration int
emptyInput bool
cachesToDump map[string]string
cachesToLoad map[string]string
skipLineOnError bool
skipFieldOnError bool
skipLogFile string
Expand Down Expand Up @@ -100,9 +97,6 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
rootCmd.PersistentFlags().BoolVar(&jsonlog, "log-json", false, "output logs in JSON format")
rootCmd.PersistentFlags().StringVar(&colormode, "color", "auto", "use colors in log outputs : yes, no or auto")
rootCmd.PersistentFlags().IntVarP(&iteration, "repeat", "r", 1, "number of iteration to mask each input")
rootCmd.PersistentFlags().BoolVar(&emptyInput, "empty-input", false, "generate data without any input, to use with repeat flag")
rootCmd.PersistentFlags().StringToStringVar(&cachesToDump, "dump-cache", map[string]string{}, "path for dumping cache into file")
rootCmd.PersistentFlags().StringToStringVar(&cachesToLoad, "load-cache", map[string]string{}, "path for loading cache from file")
rootCmd.PersistentFlags().BoolVar(&skipLineOnError, "skip-line-on-error", false, "skip a line if an error occurs while masking a field")
rootCmd.PersistentFlags().BoolVar(&skipFieldOnError, "skip-field-on-error", false, "remove a field if an error occurs while masking this field")
rootCmd.PersistentFlags().StringVar(&skipLogFile, "skip-log-file", "", "skipped lines will be written to this log file")
Expand All @@ -118,6 +112,9 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
addFlag(rootCmd, flagBufferSize)
addFlag(rootCmd, flagCatchErrors)
addFlag(rootCmd, flagConfigMasking)
addFlag(rootCmd, flagCachesToDump)
addFlag(rootCmd, flagCachesToLoad)
addFlag(rootCmd, flagEmptyInput)

rootCmd.AddCommand(&cobra.Command{
Use: "jsonschema",
Expand Down Expand Up @@ -191,6 +188,8 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
xmlCmd.Flags().Int64VarP(&seedValue, "seed", "s", 0, "set seed")
addFlag(xmlCmd, flagBufferSize)
addFlag(xmlCmd, flagCatchErrors)
addFlag(xmlCmd, flagCachesToDump)
addFlag(xmlCmd, flagCachesToLoad)
rootCmd.AddCommand(xmlCmd)

// Add command for parquet transformer
Expand All @@ -214,6 +213,8 @@ There is NO WARRANTY, to the extent permitted by law.`, version, commit, buildDa
addFlag(parquetCmd, flagBufferSize)
addFlag(parquetCmd, flagCatchErrors)
addFlag(parquetCmd, flagConfigMasking)
addFlag(parquetCmd, flagCachesToDump)
addFlag(parquetCmd, flagCachesToLoad)
rootCmd.AddCommand(parquetCmd)

flowCmd := &cobra.Command{
Expand Down
2 changes: 2 additions & 0 deletions cmd/pimo/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func setupMockCommand(rootCmd *cobra.Command) {
mockCmd.Flags().Int64VarP(&seedValue, "seed", "s", 0, "set seed")
addFlag(mockCmd, flagBufferSize)
addFlag(mockCmd, flagConfigRoute)
addFlag(mockCmd, flagCachesToDump)
addFlag(mockCmd, flagCachesToLoad)

rootCmd.AddCommand(mockCmd)
}
Expand Down

0 comments on commit 9dc55d0

Please sign in to comment.