diff options
| author | Clawd <ai@clawd.bot> | 2026-02-17 08:11:19 -0800 |
|---|---|---|
| committer | Clawd <ai@clawd.bot> | 2026-02-17 08:11:19 -0800 |
| commit | 6f02ec84a8299fc5577f147cc8741c8a4b162b64 (patch) | |
| tree | 020f3690e92732dcba723be0cfaef649f46de137 /cmd/ship/root_v2.go | |
| parent | 4b5a2656df13181b637c59c29ff31751e11cf22a (diff) | |
| parent | 05ea98df57599775c1d5bfea336012b075531670 (diff) | |
Merge agent-mode: v2 rewrite complete
- Removed all v1 code (-2800 lines)
- Simplified state to just default_host + base_domain
- Atomic port allocation via flock
- --container-port flag for Docker
- Custom domains shown in ship list
- Caddyfiles preserved on redeploy
- JSON output by default, --pretty for humans
Diffstat (limited to 'cmd/ship/root_v2.go')
| -rw-r--r-- | cmd/ship/root_v2.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/cmd/ship/root_v2.go b/cmd/ship/root_v2.go new file mode 100644 index 0000000..aa81d1e --- /dev/null +++ b/cmd/ship/root_v2.go | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "os" | ||
| 5 | |||
| 6 | "github.com/bdw/ship/internal/output" | ||
| 7 | "github.com/spf13/cobra" | ||
| 8 | ) | ||
| 9 | |||
| 10 | var hostFlag string | ||
| 11 | |||
| 12 | // This file defines the v2 CLI structure. | ||
| 13 | // The primary command is: ship [PATH] [FLAGS] | ||
| 14 | // All output is JSON by default. | ||
| 15 | |||
| 16 | var rootV2Cmd = &cobra.Command{ | ||
| 17 | Use: "ship [PATH]", | ||
| 18 | Short: "Deploy code to a VPS. JSON output for agents.", | ||
| 19 | Long: `Ship deploys code to a VPS. Point it at a directory or binary, get a URL back. | ||
| 20 | |||
| 21 | ship ./myproject # auto-detect and deploy | ||
| 22 | ship ./site --name docs # deploy with specific name | ||
| 23 | ship ./api --health /healthz # deploy with health check | ||
| 24 | ship ./preview --ttl 24h # deploy with auto-expiry | ||
| 25 | |||
| 26 | All output is JSON. Use --pretty for human-readable output.`, | ||
| 27 | Args: cobra.MaximumNArgs(1), | ||
| 28 | RunE: runDeployV2, | ||
| 29 | SilenceUsage: true, | ||
| 30 | SilenceErrors: true, | ||
| 31 | DisableAutoGenTag: true, | ||
| 32 | } | ||
| 33 | |||
| 34 | func initV2() { | ||
| 35 | // Global flags | ||
| 36 | rootV2Cmd.PersistentFlags().StringVar(&hostFlag, "host", "", "VPS host (SSH config alias or user@host)") | ||
| 37 | rootV2Cmd.PersistentFlags().BoolVar(&output.Pretty, "pretty", false, "Human-readable output") | ||
| 38 | |||
| 39 | // Deploy flags | ||
| 40 | rootV2Cmd.Flags().String("name", "", "Deploy name (becomes subdomain)") | ||
| 41 | rootV2Cmd.Flags().String("domain", "", "Custom domain for deployment") | ||
| 42 | rootV2Cmd.Flags().String("health", "", "Health check endpoint (e.g., /healthz)") | ||
| 43 | rootV2Cmd.Flags().String("ttl", "", "Auto-delete after duration (e.g., 1h, 7d)") | ||
| 44 | rootV2Cmd.Flags().StringArray("env", nil, "Environment variable (KEY=VALUE)") | ||
| 45 | rootV2Cmd.Flags().String("env-file", "", "Path to .env file") | ||
| 46 | rootV2Cmd.Flags().Int("container-port", 80, "Port the container listens on (Docker only)") | ||
| 47 | |||
| 48 | // Check for SHIP_PRETTY env var | ||
| 49 | if os.Getenv("SHIP_PRETTY") == "1" { | ||
| 50 | output.Pretty = true | ||
| 51 | } | ||
| 52 | |||
| 53 | // Add subcommands | ||
| 54 | rootV2Cmd.AddCommand(listV2Cmd) | ||
| 55 | rootV2Cmd.AddCommand(statusV2Cmd) | ||
| 56 | rootV2Cmd.AddCommand(logsV2Cmd) | ||
| 57 | rootV2Cmd.AddCommand(removeV2Cmd) | ||
| 58 | rootV2Cmd.AddCommand(hostV2Cmd) | ||
| 59 | |||
| 60 | // Initialize host subcommands (from host_v2.go) | ||
| 61 | initHostV2() | ||
| 62 | } | ||
| 63 | |||
| 64 | func runDeployV2(cmd *cobra.Command, args []string) error { | ||
| 65 | path := "." | ||
| 66 | if len(args) > 0 { | ||
| 67 | path = args[0] | ||
| 68 | } | ||
| 69 | |||
| 70 | opts := deployV2Options{ | ||
| 71 | Host: hostFlag, | ||
| 72 | Pretty: output.Pretty, | ||
| 73 | } | ||
| 74 | |||
| 75 | // Get flag values | ||
| 76 | opts.Name, _ = cmd.Flags().GetString("name") | ||
| 77 | opts.Domain, _ = cmd.Flags().GetString("domain") | ||
| 78 | opts.Health, _ = cmd.Flags().GetString("health") | ||
| 79 | opts.TTL, _ = cmd.Flags().GetString("ttl") | ||
| 80 | opts.Env, _ = cmd.Flags().GetStringArray("env") | ||
| 81 | opts.EnvFile, _ = cmd.Flags().GetString("env-file") | ||
| 82 | opts.ContainerPort, _ = cmd.Flags().GetInt("container-port") | ||
| 83 | |||
| 84 | // deployV2 handles all output and exits | ||
| 85 | deployV2(path, opts) | ||
| 86 | |||
| 87 | // Should not reach here (deployV2 calls os.Exit) | ||
| 88 | return nil | ||
| 89 | } | ||
| 90 | |||
| 91 | // Subcommands (list, status, logs, remove) are defined in commands_v2.go | ||
| 92 | |||
| 93 | var hostV2Cmd = &cobra.Command{ | ||
| 94 | Use: "host", | ||
| 95 | Short: "Manage VPS host", | ||
| 96 | } | ||
| 97 | |||
| 98 | // hostInitV2Cmd, hostStatusV2Cmd, and initHostV2() are defined in host_v2.go | ||
