diff --git a/cmd/gen/all.go b/cmd/gen/all.go new file mode 100644 index 0000000..19f5f08 --- /dev/null +++ b/cmd/gen/all.go @@ -0,0 +1,44 @@ +package gen + +import ( + "fmt" + + "github.com/shiron-dev/arcanum-hue/internal/converter" + "github.com/spf13/cobra" +) + +const allRequiredArgs = 2 + +var allCmd = &cobra.Command{ + Use: "all", + Short: "Generate color themes", + Long: `Generate a color themes. +Usage: arcanumhue gen all [config file path] [output file path]`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("gen all called") + + if len(args) < allRequiredArgs { + fmt.Println(`Please specify the config file path and the output file path. + Usage: arcanumhue gen all [config file path] [output file path]`) + + return + } + + cfgPath := args[0] + fmt.Println("config path:", cfgPath) + + outPath := args[1] + fmt.Println("output path:", outPath) + + err := converter.GetAllTheme(cfgPath, outPath) + if err != nil { + fmt.Println("Error generating theme:", err) + } + + fmt.Println("Theme generated successfully!") + }, +} + +func init() { + genCmd.AddCommand(allCmd) +} diff --git a/cmd/gen/all_test.go b/cmd/gen/all_test.go new file mode 100644 index 0000000..c7691ed --- /dev/null +++ b/cmd/gen/all_test.go @@ -0,0 +1,45 @@ +package gen + +import ( + "testing" +) + +func TestAllCmd(t *testing.T) { + t.Parallel() + + configFilePath, tempDir := genTestDir(t) + + type args struct { + args []string + } + + tests := []struct { + name string + args args + }{ + { + name: "2 args", + args: args{args: []string{configFilePath, tempDir}}, + }, + { + name: "1 arg", + args: args{args: []string{configFilePath}}, + }, + { + name: "0 args", + args: args{args: []string{}}, + }, + { + name: "reversed args", + args: args{args: []string{tempDir, configFilePath}}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + allCmd.Run(allCmd, tt.args.args) + }) + } +} diff --git a/internal/converter/all.go b/internal/converter/all.go new file mode 100644 index 0000000..047b7e4 --- /dev/null +++ b/internal/converter/all.go @@ -0,0 +1,30 @@ +package converter + +import ( + "os" + "path" +) + +func GetAllTheme(cfgPath string, outPath string) error { + cfg, err := LoadConfigPath(cfgPath) + if err != nil { + return err + } + + outPath = path.Join(outPath, toKebabCase(cfg.Name)) + if err := os.MkdirAll(outPath, WriteFilePerm); err != nil { + return err + } + + err = GetItermTheme(cfgPath, outPath) + if err != nil { + return err + } + + err = GetVSCodeTheme(cfgPath, outPath) + if err != nil { + return err + } + + return nil +} diff --git a/internal/converter/iterm.go b/internal/converter/iterm.go index 3cb2655..3087290 100644 --- a/internal/converter/iterm.go +++ b/internal/converter/iterm.go @@ -21,7 +21,6 @@ func GetItermTheme(cfgPath string, outPath string) error { return err } - outPath = path.Join(outPath, cfg.Name) if err := os.MkdirAll(outPath, WriteFilePerm); err != nil { return err }