diff options
Diffstat (limited to 'cmd/ship/host/set_domain.go')
| -rw-r--r-- | cmd/ship/host/set_domain.go | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/cmd/ship/host/set_domain.go b/cmd/ship/host/set_domain.go deleted file mode 100644 index fed3b31..0000000 --- a/cmd/ship/host/set_domain.go +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | package host | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/bdw/ship/internal/state" | ||
| 7 | "github.com/spf13/cobra" | ||
| 8 | ) | ||
| 9 | |||
| 10 | var setDomainCmd = &cobra.Command{ | ||
| 11 | Use: "set-domain [domain]", | ||
| 12 | Short: "Set base domain for auto-generated subdomains", | ||
| 13 | Long: `Set the base domain used to auto-generate subdomains for deployments. | ||
| 14 | |||
| 15 | When a base domain is configured (e.g., apps.example.com), every deployment | ||
| 16 | will automatically get a subdomain ({name}.apps.example.com). | ||
| 17 | |||
| 18 | Examples: | ||
| 19 | ship host set-domain apps.example.com # Set base domain | ||
| 20 | ship host set-domain --clear # Remove base domain`, | ||
| 21 | RunE: runSetDomain, | ||
| 22 | } | ||
| 23 | |||
| 24 | func init() { | ||
| 25 | setDomainCmd.Flags().Bool("clear", false, "Clear the base domain") | ||
| 26 | } | ||
| 27 | |||
| 28 | func runSetDomain(cmd *cobra.Command, args []string) error { | ||
| 29 | st, err := state.Load() | ||
| 30 | if err != nil { | ||
| 31 | return fmt.Errorf("error loading state: %w", err) | ||
| 32 | } | ||
| 33 | |||
| 34 | host, _ := cmd.Flags().GetString("host") | ||
| 35 | if host == "" { | ||
| 36 | host = st.GetDefaultHost() | ||
| 37 | } | ||
| 38 | |||
| 39 | if host == "" { | ||
| 40 | return fmt.Errorf("--host is required") | ||
| 41 | } | ||
| 42 | |||
| 43 | clear, _ := cmd.Flags().GetBool("clear") | ||
| 44 | |||
| 45 | if !clear && len(args) == 0 { | ||
| 46 | // Show current base domain | ||
| 47 | hostState := st.GetHost(host) | ||
| 48 | if hostState.BaseDomain == "" { | ||
| 49 | fmt.Printf("No base domain configured for %s\n", host) | ||
| 50 | } else { | ||
| 51 | fmt.Printf("Base domain for %s: %s\n", host, hostState.BaseDomain) | ||
| 52 | } | ||
| 53 | return nil | ||
| 54 | } | ||
| 55 | |||
| 56 | hostState := st.GetHost(host) | ||
| 57 | |||
| 58 | if clear { | ||
| 59 | hostState.BaseDomain = "" | ||
| 60 | if err := st.Save(); err != nil { | ||
| 61 | return fmt.Errorf("error saving state: %w", err) | ||
| 62 | } | ||
| 63 | fmt.Printf("Cleared base domain for %s\n", host) | ||
| 64 | return nil | ||
| 65 | } | ||
| 66 | |||
| 67 | hostState.BaseDomain = args[0] | ||
| 68 | if err := st.Save(); err != nil { | ||
| 69 | return fmt.Errorf("error saving state: %w", err) | ||
| 70 | } | ||
| 71 | |||
| 72 | fmt.Printf("Set base domain for %s: %s\n", host, args[0]) | ||
| 73 | fmt.Println("\nNew deployments will automatically use subdomains like:") | ||
| 74 | fmt.Printf(" myapp.%s\n", args[0]) | ||
| 75 | return nil | ||
| 76 | } | ||
