commands

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BootstrapCmd = cli.Command{
	Name:  "bootstrap",
	Usage: "bootstrap an environment for the current project",
	Flags: append(
		[]cli.Flag{
			cli.StringFlag{Name: "repository, r", Usage: "set the container repository name"},
		},
		dockerRunFlags...,
	),
	BashComplete: func(c *cli.Context) {
		bashCompleteRunArgs(c)
		args := c.Args()
		if len(args) == 0 {
			fmt.Println("-r")
			fmt.Println("--repository")
		}
	},
	Action: func(c *cli.Context) {
		if repo := c.String("repository"); repo != "" {
			project.Config().RepositoryName = repo
		}

		runOpts := parseRunOpts(c)
		err := project.Bootstrap(client, runOpts)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var BuildCmd = cli.Command{
	Name:         "build",
	Usage:        "build a docker image for the current project",
	Flags:        dockerRunFlags,
	BashComplete: bashCompleteRunArgs,
	Action: func(c *cli.Context) {
		runOpts := parseRunOpts(c)
		err := project.Build(client, runOpts)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var CleanCmd = cli.Command{
	Name:  "clean",
	Usage: "remove previously built images for the current environment",
	Flags: []cli.Flag{
		cli.BoolFlag{Name: "force, f", Usage: "skip confirmation"},
	},
	BashComplete: func(c *cli.Context) {
		args := c.Args()
		if len(args) == 0 {
			fmt.Println("-f")
			fmt.Println("--force")
		}
	},
	Action: func(c *cli.Context) {
		if !c.Bool("force") {
			if ok := prompt.Confirm("Are you sure? [y/n]"); !ok {
				fmt.Println("Aborting")
				os.Exit(1)
			}
		}

		err := project.Clean(client)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var CommitCmd = cli.Command{
	Name:  "commit",
	Usage: "commits the currently running container into a Docker image (EXPERIMENTAL)",
	Action: func(c *cli.Context) {
		containerName := os.Getenv("DEVSTEP_CONTAINER_NAME")
		if containerName == "" {
			fmt.Println("This command should be executed from within a Devstep environment")
			os.Exit(1)
		}

		err := project.Commit(client, containerName)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var ExecCmd = cli.Command{
	Name:  "exec",
	Usage: "Run a one off command against the last container created for the current project",
	Action: func(c *cli.Context) {
		execCmd := c.Args()

		if len(execCmd) == 0 {
			fmt.Printf("No command provided to `devstep exec`\n\n")
			cli.ShowCommandHelp(c, "exec")
			os.Exit(1)
		}

		execCmd = append([]string{"--"}, execCmd...)

		err := project.Exec(client, execCmd)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var HackCmd = cli.Command{
	Name:  "hack",
	Usage: "start a hacking session for the current project",
	Flags: append(
		[]cli.Flag{cli.StringFlag{Name: "name", Usage: "Name to be assigned to the container"}},
		dockerRunFlags...,
	),
	BashComplete: func(c *cli.Context) {
		bashCompleteRunArgs(c)
		args := c.Args()
		if len(args) == 0 {
			fmt.Println("--name")
		}
	},
	Action: func(c *cli.Context) {
		runOpts := parseRunOpts(c)
		err := project.Hack(client, runOpts)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
}
View Source
var InfoCmd = cli.Command{
	Name:  "info",
	Usage: "show information about the current environment",
	Action: func(c *cli.Context) {
		printConfig(project.Config())
	},
}
View Source
var InitCmd = cli.Command{
	Name: "init",
	Action: func(c *cli.Context) {
		projectRoot, err := os.Getwd()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		configPath := projectRoot + "/devstep.yml"

		if _, err := os.Stat(configPath); err == nil {
			fmt.Println("`devstep.yml` already exists in this directory. Remove it before running `devstep init`.")
			os.Exit(1)
		}
		configFile := []byte(sampleConfig)
		err = ioutil.WriteFile(configPath, configFile, 0755)
		if err != nil {
			fmt.Printf("Error creating config file '%s'\n%s\n", configPath, err)
			os.Exit(1)
		}
		fmt.Printf("Generated sample configuration file in '%s'\n", configPath)
	},
}
View Source
var PristineCmd = cli.Command{
	Name:  "pristine",
	Usage: "rebuild project image from scratch",
	Flags: append(
		[]cli.Flag{
			cli.BoolFlag{Name: "force, f", Usage: "skip clean confirmation"},
			cli.BoolFlag{Name: "bootstrap, b", Usage: "manually bootstrap your environment"},
			cli.StringFlag{Name: "repository, r", Usage: "set the container repository name"},
		},
		dockerRunFlags...,
	),
	BashComplete: func(c *cli.Context) {
		bashCompleteRunArgs(c)
		args := c.Args()
		if len(args) == 0 {
			fmt.Println("-f")
			fmt.Println("--force")
			fmt.Println("-b")
			fmt.Println("--bootstrap")
			fmt.Println("--repository")
		}
	},
	Action: func(c *cli.Context) {
		CleanCmd.Action(c)
		reloadProject()
		if c.Bool("bootstrap") {
			BootstrapCmd.Action(c)
		} else {
			BuildCmd.Action(c)
		}
	},
}
View Source
var RunCmd = cli.Command{
	Name:  "run",
	Usage: "Run a one off command against the current base image",
	Flags: append(
		[]cli.Flag{cli.StringFlag{Name: "name", Usage: "Name to be assigned to the container"}},
		dockerRunFlags...,
	),
	BashComplete: func(c *cli.Context) {
		bashCompleteRunArgs(c)
		args := c.Args()
		if len(args) == 0 {
			fmt.Println("--name")
		}
	},
	Action: func(c *cli.Context) {
		project := newProject()

		runOpts := parseRunOpts(c)
		runOpts.Cmd = c.Args()

		if len(runOpts.Cmd) == 0 {
			fmt.Printf("No command provided to `devstep run`\n\n")
			cli.ShowCommandHelp(c, "run")
			os.Exit(1)
		}

		runOpts.Cmd = append([]string{"--"}, runOpts.Cmd...)

		result, err := project.Run(client, runOpts)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		os.Exit(result.ExitCode)
	},
}

Functions

func InitDevstepEnv added in v0.4.0

func InitDevstepEnv()

Types

This section is empty.

Jump to

Keyboard shortcuts

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