Skip to content
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
31 changes: 31 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -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)
}
63 changes: 22 additions & 41 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
"bytes"
"fmt"
"os"
"os/exec"
"runtime"
"strings"

"github.com/spf13/cobra"
)
Expand All @@ -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()))
}
49 changes: 49 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -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
}