feat: domain/storage/billing/config cmds + rainyun domain/storage/billing services
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/config"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Manage ry configuration",
|
||||
}
|
||||
|
||||
var configShowCmd = &cobra.Command{
|
||||
Use: "show",
|
||||
Short: "Show current configuration",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Config file: %s\n", cfgPath)
|
||||
fmt.Printf("Current provider: %s\n", cfg.CurrentProvider)
|
||||
fmt.Printf("Output format: %s\n", cfg.Output)
|
||||
fmt.Println("Providers:")
|
||||
for name, pc := range cfg.Providers {
|
||||
masked := pc.APIKey
|
||||
if len(masked) > 4 {
|
||||
masked = masked[:2] + strings.Repeat("*", len(masked)-4) + masked[len(masked)-2:]
|
||||
}
|
||||
marker := " "
|
||||
if name == cfg.CurrentProvider {
|
||||
marker = "*"
|
||||
}
|
||||
fmt.Printf(" %s %s: api_key=%s\n", marker, name, masked)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var configSetCmd = &cobra.Command{
|
||||
Use: "set <key> <value>",
|
||||
Short: "Set a config value",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
key, value := args[0], args[1]
|
||||
switch key {
|
||||
case "output":
|
||||
cfg.Output = value
|
||||
default:
|
||||
return fmt.Errorf("unknown config key: %s", key)
|
||||
}
|
||||
if err := config.Save(cfgPath, cfg); err != nil {
|
||||
return fmt.Errorf("save config: %w", err)
|
||||
}
|
||||
fmt.Printf("Set %s = %s\n", key, value)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var configPathCmd = &cobra.Command{
|
||||
Use: "path",
|
||||
Short: "Print config file path",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println(cfgPath)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
configCmd.AddCommand(configShowCmd)
|
||||
configCmd.AddCommand(configSetCmd)
|
||||
configCmd.AddCommand(configPathCmd)
|
||||
rootCmd.AddCommand(configCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user