()
| 21 | } |
| 22 | |
| 23 | func (*RootCmd) existsCmd() *serpent.Command { |
| 24 | cmd := &serpent.Command{ |
| 25 | Use: "exists <hostname>", |
| 26 | Short: "Checks if the given hostname exists via Coder Connect.", |
| 27 | Long: "This command is designed to be used in scripts to check if the given hostname exists via Coder " + |
| 28 | "Connect. It prints no output. It returns exit code 0 if it does exist and code 1 if it does not.", |
| 29 | Middleware: serpent.Chain( |
| 30 | serpent.RequireNArgs(1), |
| 31 | ), |
| 32 | Handler: func(inv *serpent.Invocation) error { |
| 33 | hostname := inv.Args[0] |
| 34 | exists, err := workspacesdk.ExistsViaCoderConnect(inv.Context(), hostname) |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | if !exists { |
| 39 | // we don't want to print any output, since this command is designed to be a check in scripts / SSH config. |
| 40 | return ErrSilent |
| 41 | } |
| 42 | return nil |
| 43 | }, |
| 44 | } |
| 45 | return cmd |
| 46 | } |
no test coverage detected