refactor: move cmd handlers to cmd/cli/commands/ following tag_file architecture
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var billingCmd = &cobra.Command{
|
||||
Use: "billing",
|
||||
Short: "Billing and orders",
|
||||
}
|
||||
|
||||
var ordersCmd = &cobra.Command{
|
||||
Use: "orders",
|
||||
Short: "List orders",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Billing()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("billing not supported by current provider")
|
||||
}
|
||||
orders, err := svc.Orders(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(orders)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
billingCmd.AddCommand(ordersCmd)
|
||||
rootCmd.AddCommand(billingCmd)
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var domainCmd = &cobra.Command{
|
||||
Use: "domain",
|
||||
Short: "Manage domains",
|
||||
}
|
||||
|
||||
var domainListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List domains",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Domain()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("domain management not supported by current provider")
|
||||
}
|
||||
domains, err := svc.List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(domains)
|
||||
},
|
||||
}
|
||||
|
||||
var dnsCmd = &cobra.Command{
|
||||
Use: "dns <domain>",
|
||||
Short: "Manage DNS records",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
|
||||
var dnsListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List DNS records",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Domain()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("domain management not supported")
|
||||
}
|
||||
records, err := svc.DNSList(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(records)
|
||||
},
|
||||
}
|
||||
|
||||
var dnsAddCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add a DNS record",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Domain()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("domain management not supported")
|
||||
}
|
||||
recType, _ := cmd.Flags().GetString("type")
|
||||
name, _ := cmd.Flags().GetString("name")
|
||||
value, _ := cmd.Flags().GetString("value")
|
||||
ttl, _ := cmd.Flags().GetInt("ttl")
|
||||
return svc.DNSAdd(cmd.Context(), args[0],
|
||||
provider.DNSRecord{Type: recType, Name: name, Value: value, TTL: ttl})
|
||||
},
|
||||
}
|
||||
|
||||
var dnsDeleteCmd = &cobra.Command{
|
||||
Use: "delete <record-id>",
|
||||
Short: "Delete a DNS record",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Domain()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("domain management not supported")
|
||||
}
|
||||
return svc.DNSDelete(cmd.Context(), args[0], args[1])
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
dnsAddCmd.Flags().String("type", "A", "Record type (A, CNAME, TXT)")
|
||||
dnsAddCmd.Flags().String("name", "@", "Record name")
|
||||
dnsAddCmd.Flags().String("value", "", "Record value")
|
||||
dnsAddCmd.Flags().Int("ttl", 600, "TTL in seconds")
|
||||
dnsAddCmd.MarkFlagRequired("value")
|
||||
|
||||
dnsCmd.AddCommand(dnsListCmd)
|
||||
dnsCmd.AddCommand(dnsAddCmd)
|
||||
dnsCmd.AddCommand(dnsDeleteCmd)
|
||||
domainCmd.AddCommand(domainListCmd)
|
||||
domainCmd.AddCommand(dnsCmd)
|
||||
rootCmd.AddCommand(domainCmd)
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/config"
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var providerCmd = &cobra.Command{
|
||||
Use: "provider",
|
||||
Short: "Manage cloud providers",
|
||||
}
|
||||
|
||||
var providerListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List configured providers",
|
||||
Annotations: map[string]string{"skipProvider": "true"},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// show all registered providers, mark current with *
|
||||
current := ""
|
||||
if cfg != nil {
|
||||
current = cfg.CurrentProvider
|
||||
}
|
||||
for _, name := range provider.List() {
|
||||
marker := " "
|
||||
if name == current {
|
||||
marker = "*"
|
||||
}
|
||||
fmt.Printf("%s %s\n", marker, name)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var providerUseCmd = &cobra.Command{
|
||||
Use: "use <name>",
|
||||
Short: "Switch the current cloud provider",
|
||||
Annotations: map[string]string{"skipProvider": "true"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
if _, ok := cfg.Providers[name]; !ok {
|
||||
return fmt.Errorf("provider %q not configured — run 'ry provider add %s' first", name, name)
|
||||
}
|
||||
cfg.CurrentProvider = name
|
||||
if err := config.Save(cfgPath, cfg); err != nil {
|
||||
return fmt.Errorf("save config: %w", err)
|
||||
}
|
||||
fmt.Printf("Switched to provider %q\n", name)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var providerAddCmd = &cobra.Command{
|
||||
Use: "add <name>",
|
||||
Short: "Add a new cloud provider",
|
||||
Annotations: map[string]string{"skipProvider": "true"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
fmt.Printf("Adding provider %q...\n", name)
|
||||
fmt.Print("Enter API Key: ")
|
||||
var apiKey string
|
||||
fmt.Scanln(&apiKey)
|
||||
if apiKey == "" {
|
||||
return fmt.Errorf("API Key is required")
|
||||
}
|
||||
if cfg.Providers == nil {
|
||||
cfg.Providers = make(map[string]config.ProviderConfig)
|
||||
}
|
||||
cfg.Providers[name] = config.ProviderConfig{APIKey: apiKey}
|
||||
if cfg.CurrentProvider == "" {
|
||||
cfg.CurrentProvider = name
|
||||
}
|
||||
if err := config.Save(cfgPath, cfg); err != nil {
|
||||
return fmt.Errorf("save config: %w", err)
|
||||
}
|
||||
fmt.Printf("Provider %q added successfully\n", name)
|
||||
if cfg.CurrentProvider == name {
|
||||
fmt.Printf("Set as current provider\n")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
providerCmd.AddCommand(providerListCmd)
|
||||
providerCmd.AddCommand(providerUseCmd)
|
||||
providerCmd.AddCommand(providerAddCmd)
|
||||
rootCmd.AddCommand(providerCmd)
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/config"
|
||||
"git.yoresee.cc/nightstar/ry/internal/output"
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *config.Config
|
||||
cfgPath string
|
||||
prov provider.Provider
|
||||
out *output.Printer
|
||||
flagProvider string
|
||||
flagOutput string
|
||||
flagRaw bool
|
||||
flagDebug bool
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "ry",
|
||||
Short: "Multi-cloud CLI — manage cloud resources from your terminal",
|
||||
Long: `ry is a multi-cloud CLI that lets you manage cloud resources from your terminal.
|
||||
|
||||
Use "ry [command] --help" for more information about a command.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
cfg, err = config.Load(cfgPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load config: %w", err)
|
||||
}
|
||||
|
||||
// provider subcommands don't need an initialized provider
|
||||
if cmd.Annotations != nil && cmd.Annotations["skipProvider"] == "true" {
|
||||
return nil
|
||||
}
|
||||
|
||||
providerName := cfg.CurrentProvider
|
||||
if flagProvider != "" {
|
||||
providerName = flagProvider
|
||||
}
|
||||
if env := os.Getenv("RY_PROVIDER"); env != "" {
|
||||
providerName = env
|
||||
}
|
||||
|
||||
if providerName == "" {
|
||||
return fmt.Errorf("no provider configured — run 'ry provider add <name>' first")
|
||||
}
|
||||
|
||||
pc := cfg.Providers[providerName]
|
||||
prov, err = provider.New(providerName, provider.ProviderConfig{
|
||||
APIKey: pc.APIKey,
|
||||
AccessKeyID: pc.AccessKeyID,
|
||||
AccessKeySecret: pc.AccessKeySecret,
|
||||
Endpoint: pc.Endpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outputFormat := cfg.Output
|
||||
if flagOutput != "" {
|
||||
outputFormat = flagOutput
|
||||
}
|
||||
if flagRaw {
|
||||
outputFormat = "raw"
|
||||
}
|
||||
out = output.New(outputFormat, os.Stdout)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func init() {
|
||||
cfgPath = config.DefaultPath()
|
||||
rootCmd.PersistentFlags().StringVarP(&flagProvider, "provider", "p", "", "Cloud provider to use")
|
||||
rootCmd.PersistentFlags().StringVarP(&flagOutput, "output", "o", "", "Output format: table, json, yaml, raw")
|
||||
rootCmd.PersistentFlags().BoolVar(&flagRaw, "raw", false, "Output raw API response")
|
||||
rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Enable debug output")
|
||||
|
||||
completionCmd := &cobra.Command{
|
||||
Use: "completion [bash|zsh|fish]",
|
||||
Short: "Generate shell completion script",
|
||||
Annotations: map[string]string{"skipProvider": "true"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
switch args[0] {
|
||||
case "bash":
|
||||
return rootCmd.GenBashCompletion(os.Stdout)
|
||||
case "zsh":
|
||||
return rootCmd.GenZshCompletion(os.Stdout)
|
||||
case "fish":
|
||||
return rootCmd.GenFishCompletion(os.Stdout, true)
|
||||
default:
|
||||
return fmt.Errorf("unsupported shell: %s", args[0])
|
||||
}
|
||||
},
|
||||
}
|
||||
rootCmd.AddCommand(completionCmd)
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var serverCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Manage cloud servers",
|
||||
}
|
||||
|
||||
var serverListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List servers",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported by current provider")
|
||||
}
|
||||
servers, err := svc.List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if flagRaw {
|
||||
var raw []any
|
||||
for _, s := range servers {
|
||||
raw = append(raw, s.Raw)
|
||||
}
|
||||
return out.Print(raw)
|
||||
}
|
||||
return out.Print(servers)
|
||||
},
|
||||
}
|
||||
|
||||
var serverGetCmd = &cobra.Command{
|
||||
Use: "get <id>",
|
||||
Short: "Get server details",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
s, err := svc.Get(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if flagRaw {
|
||||
return out.Print(s.Raw)
|
||||
}
|
||||
return out.Print(s)
|
||||
},
|
||||
}
|
||||
|
||||
var serverStartCmd = &cobra.Command{
|
||||
Use: "start <id>",
|
||||
Short: "Start a server",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
if err := svc.Start(cmd.Context(), args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Server %s started\n", args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverStopCmd = &cobra.Command{
|
||||
Use: "stop <id>",
|
||||
Short: "Stop a server",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
if err := svc.Stop(cmd.Context(), args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Server %s stopped\n", args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverRebootCmd = &cobra.Command{
|
||||
Use: "reboot <id>",
|
||||
Short: "Reboot a server",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
if err := svc.Reboot(cmd.Context(), args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Server %s rebooted\n", args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverReinstallCmd = &cobra.Command{
|
||||
Use: "reinstall <id>",
|
||||
Short: "Reinstall server OS",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
osTemplate, _ := cmd.Flags().GetString("os")
|
||||
if osTemplate == "" {
|
||||
return fmt.Errorf("--os flag is required (e.g. --os ubuntu-22.04)")
|
||||
}
|
||||
if err := svc.Reinstall(cmd.Context(), args[0], osTemplate); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Server %s reinstalling with %s\n", args[0], osTemplate)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverResetPasswordCmd = &cobra.Command{
|
||||
Use: "reset-password <id>",
|
||||
Short: "Reset server password",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
if err := svc.ResetPassword(cmd.Context(), args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Password reset for server %s\n", args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var serverVNCCmd = &cobra.Command{
|
||||
Use: "vnc <id>",
|
||||
Short: "Get VNC connection URL",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Server()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("server management not supported")
|
||||
}
|
||||
url, err := svc.GetVNC(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(url)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
serverReinstallCmd.Flags().String("os", "", "OS template name (required)")
|
||||
serverReinstallCmd.MarkFlagRequired("os")
|
||||
|
||||
serverCmd.AddCommand(serverListCmd)
|
||||
serverCmd.AddCommand(serverGetCmd)
|
||||
serverCmd.AddCommand(serverStartCmd)
|
||||
serverCmd.AddCommand(serverStopCmd)
|
||||
serverCmd.AddCommand(serverRebootCmd)
|
||||
serverCmd.AddCommand(serverReinstallCmd)
|
||||
serverCmd.AddCommand(serverResetPasswordCmd)
|
||||
serverCmd.AddCommand(serverVNCCmd)
|
||||
rootCmd.AddCommand(serverCmd)
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var storageCmd = &cobra.Command{
|
||||
Use: "storage",
|
||||
Short: "Manage object storage",
|
||||
}
|
||||
|
||||
var storageListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List storage instances",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported by current provider")
|
||||
}
|
||||
instances, err := svc.List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(instances)
|
||||
},
|
||||
}
|
||||
|
||||
var bucketCmd = &cobra.Command{
|
||||
Use: "bucket <instance-id>",
|
||||
Short: "Manage buckets",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
|
||||
var bucketListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List buckets",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported")
|
||||
}
|
||||
buckets, err := svc.BucketList(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(buckets)
|
||||
},
|
||||
}
|
||||
|
||||
var bucketCreateCmd = &cobra.Command{
|
||||
Use: "create <name>",
|
||||
Short: "Create a bucket",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported")
|
||||
}
|
||||
if err := svc.BucketCreate(cmd.Context(), args[0], args[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Bucket %q created\n", args[1])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
bucketCmd.AddCommand(bucketListCmd)
|
||||
bucketCmd.AddCommand(bucketCreateCmd)
|
||||
storageCmd.AddCommand(storageListCmd)
|
||||
storageCmd.AddCommand(bucketCmd)
|
||||
rootCmd.AddCommand(storageCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user