|
| 1 | +//go:build slim |
| 2 | + |
| 3 | +package cli |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + "io" |
| 9 | + "os" |
| 10 | + |
| 11 | + "github.com/spf13/cobra" |
| 12 | + "github.com/spf13/viper" |
| 13 | + |
| 14 | + "github.com/coder/coder/cli/cliui" |
| 15 | + "github.com/coder/coder/cli/deployment" |
| 16 | + "github.com/coder/coder/coderd" |
| 17 | +) |
| 18 | + |
| 19 | +func Server(vip *viper.Viper, _ func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *cobra.Command { |
| 20 | + root := &cobra.Command{ |
| 21 | + Use: "server", |
| 22 | + Short: "Start a Coder server", |
| 23 | + Hidden: true, |
| 24 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 25 | + serverUnsupported(cmd.ErrOrStderr()) |
| 26 | + return nil |
| 27 | + }, |
| 28 | + } |
| 29 | + |
| 30 | + var pgRawURL bool |
| 31 | + postgresBuiltinURLCmd := &cobra.Command{ |
| 32 | + Use: "postgres-builtin-url", |
| 33 | + Short: "Output the connection URL for the built-in PostgreSQL deployment.", |
| 34 | + Hidden: true, |
| 35 | + RunE: func(cmd *cobra.Command, _ []string) error { |
| 36 | + serverUnsupported(cmd.ErrOrStderr()) |
| 37 | + return nil |
| 38 | + }, |
| 39 | + } |
| 40 | + postgresBuiltinServeCmd := &cobra.Command{ |
| 41 | + Use: "postgres-builtin-serve", |
| 42 | + Short: "Run the built-in PostgreSQL deployment.", |
| 43 | + Hidden: true, |
| 44 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | + serverUnsupported(cmd.ErrOrStderr()) |
| 46 | + return nil |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + // We still have to attach the flags to the commands so users don't get |
| 51 | + // an error when they try to use them. |
| 52 | + postgresBuiltinURLCmd.Flags().BoolVar(&pgRawURL, "raw-url", false, "Output the raw connection URL instead of a psql command.") |
| 53 | + postgresBuiltinServeCmd.Flags().BoolVar(&pgRawURL, "raw-url", false, "Output the raw connection URL instead of a psql command.") |
| 54 | + |
| 55 | + root.AddCommand(postgresBuiltinURLCmd, postgresBuiltinServeCmd) |
| 56 | + |
| 57 | + deployment.AttachFlags(root.Flags(), vip, false) |
| 58 | + |
| 59 | + return root |
| 60 | +} |
| 61 | + |
| 62 | +func serverUnsupported(w io.Writer) { |
| 63 | + _, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.Styles.Code.Render("server")) |
| 64 | + _, _ = fmt.Fprintln(w, "") |
| 65 | + _, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:") |
| 66 | + _, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases") |
| 67 | + os.Exit(1) |
| 68 | +} |
0 commit comments