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: add gen all command #17

Merged
merged 3 commits into from
Dec 19, 2024
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
44 changes: 44 additions & 0 deletions cmd/gen/all.go
Original file line number Diff line number Diff line change
@@ -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)
}
45 changes: 45 additions & 0 deletions cmd/gen/all_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
30 changes: 30 additions & 0 deletions internal/converter/all.go
Original file line number Diff line number Diff line change
@@ -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
}

Check warning on line 17 in internal/converter/all.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/all.go#L16-L17

Added lines #L16 - L17 were not covered by tests

err = GetItermTheme(cfgPath, outPath)
if err != nil {
return err
}

Check warning on line 22 in internal/converter/all.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/all.go#L21-L22

Added lines #L21 - L22 were not covered by tests

err = GetVSCodeTheme(cfgPath, outPath)
if err != nil {
return err
}

Check warning on line 27 in internal/converter/all.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/all.go#L26-L27

Added lines #L26 - L27 were not covered by tests

return nil
}
1 change: 0 additions & 1 deletion internal/converter/iterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading