blob: 954dd31cca4007030a77f5e4f27ab3a408a34312 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
}
|