diff --git a/cmd/config.go b/cmd/config.go index a793f2c..0fdc58a 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -21,11 +21,25 @@ var configInitCmd = &cobra.Command{ fmt.Println("ℹ️", err.Error()) return } - fmt.Println("Config created at:", path) + fmt.Println("✅ Config created at:", path) + }, +} + +var configViewCmd = &cobra.Command{ + Use: "view", + Short: "View Codewise config", + Run: func(cmd *cobra.Command, args []string) { + data, err := config.ReadConfig() + if err != nil { + fmt.Println("ℹ️", err.Error()) + return + } + fmt.Println(string(data)) }, } func init() { configCmd.AddCommand(configInitCmd) + configCmd.AddCommand(configViewCmd) rootCmd.AddCommand(configCmd) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 14500d6..13e859e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -47,3 +47,19 @@ func InitConfig() (string, error) { return configPath, nil } + +// ReadConfig reads and returns the config file contents +func ReadConfig() ([]byte, error) { + home, err := os.UserHomeDir() + if err != nil { + return nil, err + } + + configPath := filepath.Join(home, ConfigDirName, ConfigFileName) + + if _, err := os.Stat(configPath); err != nil { + return nil, fmt.Errorf("config file not found") + } + + return os.ReadFile(configPath) +}