diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 0000000..a793f2c --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "fmt" + + "github.com/aryansharma9917/codewise-cli/pkg/config" + "github.com/spf13/cobra" +) + +var configCmd = &cobra.Command{ + Use: "config", + Short: "Manage Codewise configuration", +} + +var configInitCmd = &cobra.Command{ + Use: "init", + Short: "Initialize Codewise config file", + Run: func(cmd *cobra.Command, args []string) { + path, err := config.InitConfig() + if err != nil { + fmt.Println("ℹ️", err.Error()) + return + } + fmt.Println("Config created at:", path) + }, +} + +func init() { + configCmd.AddCommand(configInitCmd) + rootCmd.AddCommand(configCmd) +} diff --git a/cmd/doctor.go b/cmd/doctor.go index 3f0ce6a..bb48726 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -1,11 +1,10 @@ package cmd import ( - "bytes" "fmt" + "os" "os/exec" "runtime" - "strings" "github.com/spf13/cobra" ) @@ -17,53 +16,35 @@ var doctorCmd = &cobra.Command{ fmt.Println("Codewise CLI Doctor") fmt.Println("-------------------") - // Go + // Go info fmt.Println("Go version:", runtime.Version()) - - // OS fmt.Println("OS/Arch:", runtime.GOOS, runtime.GOARCH) - // Codewise + // Codewise version fmt.Println("Codewise version:", rootCmd.Version) - // Docker - checkDocker() - - // Git - checkGit() + // Working directory + if wd, err := os.Getwd(); err == nil { + fmt.Println("Working directory:", wd) + } + + // Git version + if out, err := exec.Command("git", "--version").Output(); err == nil { + fmt.Println("Git:", string(out)) + } else { + fmt.Println("Git: not found") + } + + // Config path (future use) + configPath := os.ExpandEnv("$HOME/.codewise/config.yaml") + if _, err := os.Stat(configPath); err == nil { + fmt.Println("Config file:", configPath) + } else { + fmt.Println("Config file:", configPath, "(not found)") + } }, } func init() { rootCmd.AddCommand(doctorCmd) } - -// ---- helpers ---- - -func checkDocker() { - cmd := exec.Command("docker", "--version") - - var out bytes.Buffer - cmd.Stdout = &out - - if err := cmd.Run(); err != nil { - fmt.Println("Docker: not installed") - return - } - - fmt.Println("Docker:", strings.TrimSpace(out.String())) -} - -func checkGit() { - cmd := exec.Command("git", "--version") - - var out bytes.Buffer - cmd.Stdout = &out - - if err := cmd.Run(); err != nil { - fmt.Println("Git: not installed") - return - } - - fmt.Println("Git:", strings.TrimSpace(out.String())) -} diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 0000000..14500d6 --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,49 @@ +package config + +import ( + "fmt" + "os" + "path/filepath" +) + +const ( + ConfigDirName = ".codewise" + ConfigFileName = "config.yaml" +) + +// DefaultConfig is the initial config content +var DefaultConfig = []byte(`version: v1 +user: + name: aryan +defaults: + app_name: myapp + repo_url: https://github.com/example/repo +`) + +// InitConfig creates the config directory and file +func InitConfig() (string, error) { + home, err := os.UserHomeDir() + if err != nil { + return "", err + } + + configDir := filepath.Join(home, ConfigDirName) + configPath := filepath.Join(configDir, ConfigFileName) + + // Create directory if not exists + if err := os.MkdirAll(configDir, 0755); err != nil { + return "", err + } + + // If config already exists, do nothing + if _, err := os.Stat(configPath); err == nil { + return configPath, fmt.Errorf("config already exists") + } + + // Write default config + if err := os.WriteFile(configPath, DefaultConfig, 0644); err != nil { + return "", err + } + + return configPath, nil +}