First commit of golang CLI.

This commit is contained in:
2025-08-31 11:51:11 -07:00
parent 4ca06aecb6
commit f0a2098f11
51 changed files with 8840 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
package secret
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/wild-cloud/wild-cli/internal/config"
"github.com/wild-cloud/wild-cli/internal/environment"
)
var checkMode bool
func newGetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "get <path>",
Short: "Get a secret value",
Long: `Get a secret value from secrets.yaml using a dot-notation path.
For security reasons, secret values are displayed as-is. Be careful when using
in scripts or logs that might be shared.
Examples:
wild secret get database.password
wild secret get apps.myapp.api_key
wild secret get certificates.tls.key`,
Args: cobra.ExactArgs(1),
RunE: runGet,
}
cmd.Flags().BoolVar(&checkMode, "check", false, "exit 1 if key doesn't exist (no output)")
return cmd
}
func runGet(cmd *cobra.Command, args []string) error {
path := args[0]
// Initialize environment
env := environment.New()
if err := env.RequiresProject(); err != nil {
return err
}
// Create config manager
mgr := config.NewManager(env.ConfigPath(), env.SecretsPath())
// Get the secret value
value, err := mgr.GetSecret(path)
if err != nil {
if checkMode {
os.Exit(1)
}
return fmt.Errorf("getting secret value: %w", err)
}
// Handle null/missing values
if value == nil {
if checkMode {
os.Exit(1)
}
return fmt.Errorf("key path '%s' not found in secrets file", path)
}
// In check mode, exit 0 if key exists (don't output value)
if checkMode {
return nil
}
// Output the value (no logging to avoid secrets in logs)
fmt.Println(value)
return nil
}

View File

@@ -0,0 +1,30 @@
package secret
import (
"github.com/spf13/cobra"
)
// NewSecretCommand creates the secret command and its subcommands
func NewSecretCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "secret",
Short: "Manage Wild Cloud secrets",
Long: `Manage Wild Cloud secrets stored in secrets.yaml.
Secret values are stored as YAML and can be accessed using dot-notation paths.
Secret values are typically not displayed in output for security reasons.
Examples:
wild secret get database.password
wild secret set database.password mysecretpassword
wild secret get apps.myapp.api_key`,
}
// Add subcommands
cmd.AddCommand(
newGetCommand(),
newSetCommand(),
)
return cmd
}

View File

@@ -0,0 +1,53 @@
package secret
import (
"fmt"
"github.com/spf13/cobra"
"github.com/wild-cloud/wild-cli/internal/config"
"github.com/wild-cloud/wild-cli/internal/environment"
"github.com/wild-cloud/wild-cli/internal/output"
)
func newSetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "set <path> <value>",
Short: "Set a secret value",
Long: `Set a secret value in secrets.yaml using a dot-notation path.
The value will be stored as-is in the secrets file. Be careful with sensitive data.
Examples:
wild secret set database.password mySecretPassword123
wild secret set apps.myapp.api_key abc123def456
wild secret set certificates.tls.key "-----BEGIN PRIVATE KEY-----..."`,
Args: cobra.ExactArgs(2),
RunE: runSet,
}
return cmd
}
func runSet(cmd *cobra.Command, args []string) error {
path := args[0]
value := args[1]
// Initialize environment
env := environment.New()
if err := env.RequiresProject(); err != nil {
return err
}
// Create config manager
mgr := config.NewManager(env.ConfigPath(), env.SecretsPath())
// Set the secret value
if err := mgr.SetSecret(path, value); err != nil {
return fmt.Errorf("setting secret value: %w", err)
}
// Don't show the actual value in output for security
output.Success(fmt.Sprintf("Set secret %s", path))
return nil
}