MCPcopy Index your code
hub / github.com/devspace-sh/devspace / NewEnterCmd

Function NewEnterCmd

cmd/enter.go:48–90  ·  view source on GitHub ↗

NewEnterCmd creates a new enter command

(f factory.Factory, globalFlags *flags.GlobalFlags)

Source from the content-addressed store, hash-verified

46
47// NewEnterCmd creates a new enter command
48func 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#######################################################
58Execute a command or start a new terminal in your
59devspace:
60
61devspace enter
62devspace enter --pick # Select pod to enter
63devspace enter bash
64devspace enter -c my-container
65devspace enter bash -n my-namespace
66devspace enter bash -l release=test
67devspace enter bash --image-selector nginx:latest
68devspace 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
93func (cmd *EnterCmd) Run(f factory.Factory, args []string) error {

Callers 1

BuildRootFunction · 0.85

Calls 2

RunMethod · 0.95
SetPluginCommandFunction · 0.92

Tested by

no test coverage detected