summaryrefslogtreecommitdiffstats
path: root/cmd/init.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-10 15:22:32 -0500
committers <[email protected]>2025-11-10 15:22:32 -0500
commit8383a241fc3cf5b022c9c53f8f19690edf04177b (patch)
tree887a489f7931d07373530c7e053f0343dca65e1d /cmd/init.go
parent9a9e79f232b83d3bd2a816287272515863df1299 (diff)
downloaddborg-8383a241fc3cf5b022c9c53f8f19690edf04177b.tar.gz
dborg-8383a241fc3cf5b022c9c53f8f19690edf04177b.zip
refactor: restructure client modules and add config file supportv0.8.1
- Split large osint.go client into focused modules (bssid.go, breachforum.go, buckets.go, etc.) - Add config file support with init command for API key management - Remove api-key flag in favor of config file + env var fallback - Update API paths to remove /osint prefix - Add crawl endpoint streaming support - Improve error handling with 402 payment required status
Diffstat (limited to 'cmd/init.go')
-rw-r--r--cmd/init.go59
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
+}