diff options
| author | bndw <ben@bdw.to> | 2026-01-23 21:52:50 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-01-23 21:52:50 -0800 |
| commit | 87752492d0dc7df3cf78011d5ce315a3eb0cad51 (patch) | |
| tree | 76843c127fece33f5c28dd7bd533044043478825 /cmd/deploy/env/list.go | |
| parent | 57eb67df265a7a6bb544cde83a3be5eadf53fdf2 (diff) | |
Restructure CLI with Cobra
Replace custom switch-based routing with Cobra for cleaner command
hierarchy. Reorganize commands into logical groups:
- Root command handles deployment (--binary, --static, --domain, etc.)
- App management at top level: list, logs, status, restart, remove
- env subcommand group: list, set, unset
- host subcommand group: init, status, update, ssh
- Standalone: ui (renamed from webui), version
Add version command with ldflags support for build info.
Diffstat (limited to 'cmd/deploy/env/list.go')
| -rw-r--r-- | cmd/deploy/env/list.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cmd/deploy/env/list.go b/cmd/deploy/env/list.go new file mode 100644 index 0000000..af92171 --- /dev/null +++ b/cmd/deploy/env/list.go | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | package env | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "strings" | ||
| 6 | |||
| 7 | "github.com/bdw/deploy/internal/state" | ||
| 8 | "github.com/spf13/cobra" | ||
| 9 | ) | ||
| 10 | |||
| 11 | var listCmd = &cobra.Command{ | ||
| 12 | Use: "list <app>", | ||
| 13 | Short: "List environment variables for an app", | ||
| 14 | Args: cobra.ExactArgs(1), | ||
| 15 | RunE: runList, | ||
| 16 | } | ||
| 17 | |||
| 18 | func runList(cmd *cobra.Command, args []string) error { | ||
| 19 | name := args[0] | ||
| 20 | |||
| 21 | st, err := state.Load() | ||
| 22 | if err != nil { | ||
| 23 | return fmt.Errorf("error loading state: %w", err) | ||
| 24 | } | ||
| 25 | |||
| 26 | host, _ := cmd.Flags().GetString("host") | ||
| 27 | if host == "" { | ||
| 28 | host = st.GetDefaultHost() | ||
| 29 | } | ||
| 30 | |||
| 31 | if host == "" { | ||
| 32 | return fmt.Errorf("--host is required") | ||
| 33 | } | ||
| 34 | |||
| 35 | app, err := st.GetApp(host, name) | ||
| 36 | if err != nil { | ||
| 37 | return err | ||
| 38 | } | ||
| 39 | |||
| 40 | if app.Type != "app" { | ||
| 41 | return fmt.Errorf("env is only available for apps, not static sites") | ||
| 42 | } | ||
| 43 | |||
| 44 | fmt.Printf("Environment variables for %s:\n\n", name) | ||
| 45 | if len(app.Env) == 0 { | ||
| 46 | fmt.Println(" (none)") | ||
| 47 | } else { | ||
| 48 | for k, v := range app.Env { | ||
| 49 | display := v | ||
| 50 | if isSensitive(k) { | ||
| 51 | display = "***" | ||
| 52 | } | ||
| 53 | fmt.Printf(" %s=%s\n", k, display) | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | return nil | ||
| 58 | } | ||
| 59 | |||
| 60 | func isSensitive(key string) bool { | ||
| 61 | key = strings.ToLower(key) | ||
| 62 | sensitiveWords := []string{"key", "secret", "password", "token", "api"} | ||
| 63 | for _, word := range sensitiveWords { | ||
| 64 | if strings.Contains(key, word) { | ||
| 65 | return true | ||
| 66 | } | ||
| 67 | } | ||
| 68 | return false | ||
| 69 | } | ||
