NewAttachCmd creates a new attach command
(f factory.Factory, globalFlags *flags.GlobalFlags)
| 28 | |
| 29 | // NewAttachCmd creates a new attach command |
| 30 | func NewAttachCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command { |
| 31 | cmd := &AttachCmd{GlobalFlags: globalFlags} |
| 32 | |
| 33 | attachCmd := &cobra.Command{ |
| 34 | Use: "attach", |
| 35 | Short: "Attaches to a container", |
| 36 | Long: ` |
| 37 | ####################################################### |
| 38 | ################# devspace attach ##################### |
| 39 | ####################################################### |
| 40 | Attaches to a running container |
| 41 | |
| 42 | devspace attach |
| 43 | devspace attach --pick # Select pod to enter |
| 44 | devspace attach -c my-container |
| 45 | devspace attach -n my-namespace |
| 46 | #######################################################`, |
| 47 | RunE: func(cobraCmd *cobra.Command, args []string) error { |
| 48 | plugin.SetPluginCommand(cobraCmd, args) |
| 49 | return cmd.Run(f, cobraCmd, args) |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | attachCmd.Flags().StringVarP(&cmd.Container, "container", "c", "", "Container name within pod where to execute command") |
| 54 | attachCmd.Flags().StringVar(&cmd.Pod, "pod", "", "Pod to open a shell to") |
| 55 | attachCmd.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})") |
| 56 | attachCmd.Flags().StringVarP(&cmd.LabelSelector, "label-selector", "l", "", "Comma separated key=value selector list (e.g. release=test)") |
| 57 | |
| 58 | attachCmd.Flags().BoolVar(&cmd.Pick, "pick", true, "Select a pod") |
| 59 | |
| 60 | return attachCmd |
| 61 | } |
| 62 | |
| 63 | // Run executes the command logic |
| 64 | func (cmd *AttachCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []string) error { |
no test coverage detected