cmd

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cmd contains the some commands for the program

Index

Constants

This section is empty.

Variables

View Source
var (
	// Attach is the cobra command for the attach command
	Attach = &cobra.Command{
		Use:   "attach",
		Short: "Attaches directly to the container",
		Long:  `Attaches directly to the container. This is useful for debugging`,
		RunE: func(cmd *cobra.Command, args []string) error {
			cmd.SilenceUsage = true

			cfg, err := config.Read()
			if err != nil {
				glg.Fatalf("Can't read config: %s", err)
			}
			pman := podman.New(cfg.Podman.Path)
			if !pman.Exists(cfg.Container.Name) {
				glg.Fatal("Container does not exist")
			}
			state.StartContainer(cfg.Container.Name, pman, podman.Attach{})
			return pman.Attach([]string{cfg.Container.Name}, podman.Attach{Stdin: true, Stdout: true, Stderr: true}).Run()
		},
	}
)
View Source
var (

	// Enter is the cobra command for the enter command
	Enter = &cobra.Command{
		Use:     "enter",
		Aliases: []string{"shell"},
		Short:   "Launches a shell inside the container",
		Long: `Launches a the shell defined in the config inside the container.
		
		To install packages inside the container use the develbox`,
		RunE: func(cmd *cobra.Command, args []string) error {
			cmd.SilenceUsage = true

			cfg, err := config.Read()
			if err != nil {
				glg.Failf("Can't read config: %s", err)
			}
			pman := podman.New(cfg.Podman.Path)
			if !pman.Exists(cfg.Container.Name) {
				glg.Fatal("Container does not exist")
			}
			state.StartContainer(cfg.Container.Name, pman, podman.Attach{})
			if socketExperiment && !root {
				go createSocket(&cfg)
			}
			defer os.Remove(".develbox/home/.develbox.sock")
			err = container.InstallAndEnter(cfg, root)
			return err
		},
	}
)
View Source
var (
	// Exec is the cobra command for the exec command
	Exec = &cobra.Command{
		Use:   "exec",
		Short: "Executes a program inside the container",
		Long: `Executes a program inside the container.
		
		Run with "#" or "!" prefix to run command as root.`,
		DisableFlagParsing: true,
		RunE: func(cmd *cobra.Command, args []string) error {
			cmd.SilenceUsage = true
			cfg, err := config.Read()
			if err != nil {
				return err
			}
			pman := podman.New(cfg.Podman.Path)
			if !pman.Exists(cfg.Container.Name) {
				glg.Fatal("Container does not exist")
			}
			state.StartContainer(cfg.Container.Name, pman, podman.Attach{})

			var rootOpert bool
			joinedArgs := strings.Join(args, " ")
			if strings.HasPrefix(joinedArgs, "#") {
				rootOpert = true
				joinedArgs = strings.TrimPrefix(joinedArgs, "#")
			}
			if strings.HasPrefix(joinedArgs, "!") {
				rootOpert = true
				joinedArgs = strings.TrimPrefix(joinedArgs, "!")
			}

			params := []string{cfg.Container.Name, joinedArgs}
			command := pman.Exec(params, cfg.Image.Variables, true, rootOpert,
				podman.Attach{
					Stdin:     true,
					Stdout:    true,
					Stderr:    true,
					PseudoTTY: true,
				})

			return command.Run()
		},
	}
)
View Source
var (

	// Run is the command to run command defined in config.
	Run = &cobra.Command{
		Use:   "run",
		Short: "Runs the command defined in the config file",
		Long: `Runs the command defined in the config file.
		
		Any command that is prefixed with a # inside the config will run as root. Call other commands using the "!" prefix.`,
		RunE: func(cmd *cobra.Command, args []string) error {
			cmd.SilenceUsage = true

			var err error
			cfg, err = config.Read()
			if err != nil {
				return err
			}

			pman = podman.New(cfg.Podman.Path)
			if !pman.Exists(cfg.Container.Name) {
				glg.Fatal("Container does not exist")
			}
			state.StartContainer(cfg.Container.Name, pman, podman.Attach{})

			name := strings.Join(args, " ")
			if _, ok := cfg.Commands[name]; !ok {
				return glg.Errorf("Command '%s' does not exist", name)
			}

			runArgs, err := getAllAsArray(name, "")
			if err != nil {
				return err
			}

			return runCommandList(runArgs)
		},
	}
)
View Source
var (
	// Socket is the cobra command for the experimental socket command
	Socket = &cobra.Command{
		Use:   "socket",
		Short: "Creates a socket that enables communication with the container",
		Long: `Creates a socket that enables communication with the container
		
		Used so we can install packages from inside the container (without using root).`,
		Run: func(cmd *cobra.Command, args []string) {
			cfg, err := config.Read()
			if err != nil {
				glg.Failf("Can't read config: %s", err)
			}
			pman := podman.New(cfg.Podman.Path)
			if !pman.Exists(cfg.Container.Name) {
				glg.Fatal("Container does not exist")
			}
			state.StartContainer(cfg.Container.Name, pman, podman.Attach{})

			defer os.Remove(".develbox/home/.develbox.sock")
			createSocket(&cfg)
		},
	}
)

Functions

func Execute

func Execute() error

Execute is the entrypoint for the program

func GetRootCLI added in v0.6.0

func GetRootCLI() *cobra.Command

GetRootCLI returns the root command for the program

Types

This section is empty.

Directories

Path Synopsis
Package create contains the create command
Package create contains the create command
Package dockerfile contains the logic for creating a Dockerfile
Package dockerfile contains the logic for creating a Dockerfile
Package pkg has the logic for communication with the package manager
Package pkg has the logic for communication with the package manager
Package state manages the state of the container
Package state manages the state of the container
Package version has the command to print the version of the program
Package version has the command to print the version of the program

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL