-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset.go
More file actions
54 lines (44 loc) · 1.23 KB
/
set.go
File metadata and controls
54 lines (44 loc) · 1.23 KB
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
package config
import (
"fmt"
"github.com/spf13/cobra"
internalConfig "github.com/OpenLabsHQ/OpenLabs/cli/internal/config"
"github.com/OpenLabsHQ/OpenLabs/cli/internal/progress"
"github.com/OpenLabsHQ/OpenLabs/cli/internal/utils"
)
func newSetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "set [key] [value]",
Short: "Set configuration value",
Long: "Set a configuration value. Available keys: api-url, format",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return runSet(args[0], args[1])
},
}
return cmd
}
func runSet(key, value string) error {
config, err := internalConfig.Load()
if err != nil {
return fmt.Errorf("failed to load configuration: %w", err)
}
switch key {
case "api-url":
if err := config.SetAPIURL(value); err != nil {
return err
}
progress.ShowSuccess(fmt.Sprintf("API URL set to: %s", value))
case "format":
if err := utils.ValidateOutputFormat(value); err != nil {
return err
}
if err := config.SetOutputFormat(value); err != nil {
return err
}
progress.ShowSuccess(fmt.Sprintf("Output format set to: %s", value))
default:
return fmt.Errorf("unknown configuration key: %s (valid: api-url, format)", key)
}
return nil
}