diff options
Diffstat (limited to 'cmd/init.go')
| -rw-r--r-- | cmd/init.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cmd/init.go b/cmd/init.go new file mode 100644 index 0000000..954dd31 --- /dev/null +++ b/cmd/init.go @@ -0,0 +1,59 @@ +package cmd + +import ( + "bufio" + "fmt" + "os" + "strings" + + "git.db.org.ai/dborg/internal/config" + "github.com/spf13/cobra" +) + +var initCmd = &cobra.Command{ + Use: "init", + Short: "Initialize dborg CLI configuration", + Long: `Initialize the dborg CLI by setting up your API key and other configuration`, + RunE: runInit, +} + +func init() { + rootCmd.AddCommand(initCmd) +} + +func runInit(cmd *cobra.Command, args []string) error { + reader := bufio.NewReader(os.Stdin) + + fmt.Println("Welcome to dborg CLI setup!") + fmt.Println("----------------------------") + fmt.Print("\nEnter your DB.org.ai API key: ") + + apiKey, err := reader.ReadString('\n') + if err != nil { + return fmt.Errorf("failed to read API key: %w", err) + } + + apiKey = strings.TrimSpace(apiKey) + if apiKey == "" { + return fmt.Errorf("API key cannot be empty") + } + + configPath, err := config.GetConfigPath() + if err != nil { + return fmt.Errorf("failed to get config path: %w", err) + } + + cfg := &config.FileConfig{ + APIKey: apiKey, + } + + if err := config.SaveConfig(cfg); err != nil { + return fmt.Errorf("failed to save config: %w", err) + } + + fmt.Printf("\n✓ Configuration saved to: %s\n", configPath) + fmt.Println("\nYou can now use dborg commands without specifying an API key.") + fmt.Println("Example: dborg osint username john_doe") + + return nil +} |
