Example #1
0
// execute
func execute(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	//
	if len(args) == 0 {
		args = append(args, Print.Prompt("Please specify a command you wish to exec: "))
	}

	//
	v := url.Values{}

	// if a container is found that matches args[0] then set that as a qparam, and
	// remove it from the argument list
	if Server.IsContainerExec(args) {
		v.Add("container", args[0])
		args = args[1:]
	}
	v.Add("cmd", strings.Join(args, " "))

	//
	if err := server.Exec("exec", v.Encode()); err != nil {
		server.Error("[commands/exec] Server.Exec failed", err.Error())
	}

	// PostRun: halt
}
Example #2
0
// dev
func dev(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	// don't rebuild
	if !nobuild {

		// if the vm has no been created or deployed, the rebuild flag, or the VM has
		// recently been reloaded do a deploy
		if Vagrant.Status() == "not created" || !config.VMfile.HasDeployed() || rebuild || config.VMfile.HasReloaded() {

			fmt.Printf(stylish.Bullet("Deploying codebase..."))

			// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
			// will be used during the deploy
			if err := engineutil.RemountLocal(); err != nil {
				config.Debug("No engine mounted (not found locally).")
			}

			// run a deploy
			if err := server.Deploy(""); err != nil {
				server.Fatal("[commands/dev] server.Deploy() failed", err.Error())
			}

			// stream log output
			go Mist.Stream([]string{"log", "deploy"}, Mist.PrintLogStream)

			// listen for status updates
			errch := make(chan error)
			go func() {
				errch <- Mist.Listen([]string{"job", "deploy"}, Mist.DeployUpdates)
			}()

			// wait for a status update (blocking)
			err := <-errch

			//
			if err != nil {
				fmt.Printf(err.Error())
				return
			}
		}
	}

	//
	if err := server.Exec("develop", ""); err != nil {
		server.Error("[commands/dev] Server.Exec failed", err.Error())
	}

	// PostRun: halt
}
Example #3
0
// console
func console(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	//
	switch {

	// if no args are passed provide instruction
	case len(args) == 0:
		fmt.Printf(stylish.ErrBullet("Unable to console. Please provide a service to connect to.\n"))

	// if 1 args is passed it's assumed to be a container to console into
	case len(args) == 1:
		if err := server.Console("container=" + args[0]); err != nil {
			server.Error("[commands/console] Server.Console failed", err.Error())
		}
	}

	// PostRun: halt
}
Example #4
0
// dev
func dev(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	// check to see if the devconfig option is one of our predetermined values. If
	// not indicate as much and return
	switch devconfig {
	case "mount", "copy", "none":
		break
	default:
		fmt.Printf("--dev-config option '%s' is not accepted. Please choose either 'mount', 'copy', or 'none'\n", devconfig)
		os.Exit(1)
	}

	// stream log output; this is done here because there might be output from hooks
	// that needs to be streamed to the client. This will also capture any output
	// that would come from a deploy (if one is run).
	mist, err := Mist.Connect([]string{"log", "deploy"}, Mist.PrintLogStream)
	if err != nil {
		config.Fatal("[commands/dev] mist.Connect() failed", err.Error())
	}

	// don't rebuild
	if !nobuild {

		// if the vm has no been created or deployed, the rebuild flag, or the VM has
		// recently been reloaded do a deploy
		if Vagrant.Status() == "not created" || !config.VMfile.HasDeployed() || rebuild || config.VMfile.HasReloaded() {

			fmt.Printf(stylish.Bullet("Deploying codebase..."))

			// remount the engine file at ~/.nanobox/apps/<app>/<engine> so any new scripts
			// will be used during the deploy
			if err := engineutil.RemountLocal(); err != nil {
				config.Debug("No engine mounted (not found locally).")
			}

			// run a deploy
			if err := server.Deploy(""); err != nil {
				server.Fatal("[commands/dev] server.Deploy() failed", err.Error())
			}

			// listen for status updates
			errch := make(chan error)
			go func() {
				errch <- Mist.Listen([]string{"job", "deploy"}, Mist.DeployUpdates)
			}()

			// wait for a status update (blocking)
			err := <-errch

			//
			if err != nil {
				fmt.Printf(err.Error())
				return
			}
		}
	}

	//
	v := url.Values{}
	v.Add("dev_config", devconfig)

	//
	if err := server.Develop(v.Encode(), mist); err != nil {
		server.Error("[commands/dev] Server.Develop failed", err.Error())
	}

	// PostRun: halt
}