NewEnterCmd creates a new enter command
(f factory.Factory, globalFlags *flags.GlobalFlags)
| 46 | |
| 47 | // NewEnterCmd creates a new enter command |
| 48 | func NewEnterCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command { |
| 49 | cmd := &EnterCmd{GlobalFlags: globalFlags} |
| 50 | |
| 51 | enterCmd := &cobra.Command{ |
| 52 | Use: "enter", |
| 53 | Short: "Open a shell to a container", |
| 54 | Long: ` |
| 55 | ####################################################### |
| 56 | ################## devspace enter ##################### |
| 57 | ####################################################### |
| 58 | Execute a command or start a new terminal in your |
| 59 | devspace: |
| 60 | |
| 61 | devspace enter |
| 62 | devspace enter --pick # Select pod to enter |
| 63 | devspace enter bash |
| 64 | devspace enter -c my-container |
| 65 | devspace enter bash -n my-namespace |
| 66 | devspace enter bash -l release=test |
| 67 | devspace enter bash --image-selector nginx:latest |
| 68 | devspace enter bash --image-selector "${runtime.images.app.image}:${runtime.images.app.tag}" |
| 69 | #######################################################`, |
| 70 | RunE: func(cobraCmd *cobra.Command, args []string) error { |
| 71 | plugin.SetPluginCommand(cobraCmd, args) |
| 72 | return cmd.Run(f, args) |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | enterCmd.Flags().StringVarP(&cmd.Container, "container", "c", "", "Container name within pod where to execute command") |
| 77 | enterCmd.Flags().StringVar(&cmd.Pod, "pod", "", "Pod to open a shell to") |
| 78 | enterCmd.Flags().StringVarP(&cmd.LabelSelector, "label-selector", "l", "", "Comma separated key=value selector list (e.g. release=test)") |
| 79 | enterCmd.Flags().StringVar(&cmd.ImageSelector, "image-selector", "", "The image to search a pod for (e.g. nginx, nginx:latest, ${runtime.images.app}, nginx:${runtime.images.app.tag})") |
| 80 | enterCmd.Flags().StringVar(&cmd.WorkingDirectory, "workdir", "", "The working directory where to open the terminal or execute the command") |
| 81 | |
| 82 | enterCmd.Flags().BoolVar(&cmd.TTY, "tty", true, "If to use a tty to start the command") |
| 83 | enterCmd.Flags().BoolVar(&cmd.Pick, "pick", true, "Select a pod / container if multiple are found") |
| 84 | enterCmd.Flags().BoolVar(&cmd.Wait, "wait", false, "Wait for the pod(s) to start if they are not running") |
| 85 | enterCmd.Flags().BoolVar(&cmd.Reconnect, "reconnect", false, "Will reconnect the terminal if an unexpected return code is encountered") |
| 86 | enterCmd.Flags().BoolVar(&cmd.Screen, "screen", false, "Use a screen session to connect") |
| 87 | enterCmd.Flags().StringVar(&cmd.ScreenSession, "screen-session", "enter", "The screen session to create or connect to") |
| 88 | |
| 89 | return enterCmd |
| 90 | } |
| 91 | |
| 92 | // Run executes the command logic |
| 93 | func (cmd *EnterCmd) Run(f factory.Factory, args []string) error { |
no test coverage detected