cmd

package
v0.0.1-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Create = &cobra.Command{
		Use:        "create [CONFIG_NAME]",
		SuggestFor: []string{"config"},
		Short:      "Creates a new container/config for this project",
		Args:       cobra.MaximumNArgs(1),
		Example:    "develbox create -c alpine/latest",
		Run: func(cmd *cobra.Command, args []string) {
			configExists := config.ConfigExists()

			if createCfg {
				if configExists && !forceReplace {
					glg.Errorf("Config file already exists!")
					os.Exit(1)
				}

				cfg := config.Struct{}

				if len(args) == 1 {
					cfg = downloadConfig(args[0])
				}

				err := exec.Command(cfg.Podman.Path, "--version").Run()
				if err != nil {
					err = exec.Command("docker", "--version").Run()
					if err == nil {
						cfg.Podman.Path = "docker"
						glg.Warn("Couldn't find podman! Using docker instead.")
					} else {
						glg.Warn("Couldn't find podman nor docker on PATH!")
					}
				}
				config.SetDefaults(&cfg)

				err = config.Write(&cfg)
				if err != nil {
					glg.Error(err)
				}
				fmt.Println("Config file created!")
				return
			}

			cfg, err := config.Read()
			if err != nil {
				glg.Errorf("Failed to read .develbox/config.json! Try running 'develbox create -c --force' to create a new one.")
				return
			}
			container.Create(cfg, forceReplace)
		},
	}
)
View Source
var (
	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 {
			cfg, err := config.Read()
			if err != nil {
				return err
			}
			pman := podman.New(cfg.Podman.Path)
			pman.Start([]string{cfg.Podman.Container.Name}, podman.Attach{})
			return container.Enter(cfg, root)
		},
	}
)
View Source
var (
	Exec = &cobra.Command{
		Use:                "exec",
		Short:              "Executes a program inside the container",
		DisableFlagParsing: true,
		RunE: func(cmd *cobra.Command, args []string) error {
			cfg, err := config.Read()
			if err != nil {
				return err
			}
			pman := podman.New(cfg.Podman.Path)
			pman.Start([]string{cfg.Podman.Container.Name}, podman.Attach{})

			params := []string{cfg.Podman.Container.Name}
			params = append(params, strings.Join(args, " "))
			command := pman.Exec(params, false, false,
				podman.Attach{
					Stdin:     true,
					Stdout:    true,
					Stderr:    true,
					PseudoTTY: true,
				})

			return command.Run()
		},
	}
)
View Source
var (
	Run = &cobra.Command{
		Use:   "run",
		Short: "Runs the command defined in the config file",
		RunE: func(cmd *cobra.Command, args []string) error {
			cfg, err := config.Read()
			if err != nil {
				return err
			}
			pman := podman.New(cfg.Podman.Path)
			pman.Start([]string{cfg.Podman.Container.Name}, podman.Attach{})

			params := []string{cfg.Podman.Container.Name}
			params = append(params, cfg.Commands[args[0]])

			command := pman.Exec(params, true, false,
				podman.Attach{
					Stdin:     true,
					Stdout:    true,
					Stderr:    true,
					PseudoTTY: true,
				})

			return command.Run()
		},
	}
)

Functions

func Execute

func Execute()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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