コード例 #1
0
ファイル: dev.go プロジェクト: mbrodala/otto
func (c *DevCommand) Run(args []string) int {
	fs := c.FlagSet("dev", FlagSetNone)
	fs.Usage = func() { c.Ui.Error(c.Help()) }
	args, execArgs, posArgs := flag.FilterArgs(fs, args)
	if err := fs.Parse(args); err != nil {
		return 1
	}

	// Get the remaining args to determine if we have an action.
	var action string
	if len(posArgs) > 0 {
		action = posArgs[0]
		execArgs = append(execArgs, posArgs[1:]...)
	}

	// Load the appfile
	app, err := c.Appfile()
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	// Get a core
	core, err := c.Core(app)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error loading core: %s", err))
		return 1
	}

	// If we have an action, then we use Execute(). Otherwise, we're
	// building the dev environment with Dev().
	if action == "" {
		// Build the development environment
		if err := core.Dev(); err != nil {
			c.Ui.Error(fmt.Sprintf(
				"Error building dev environment: %s", err))
			return 1
		}

		return 0
	}

	// Execute the task
	err = core.Execute(&otto.ExecuteOpts{
		Task:   otto.ExecuteTaskDev,
		Action: action,
		Args:   execArgs,
	})
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	return 0
}
コード例 #2
0
ファイル: deploy.go プロジェクト: mbrodala/otto
func (c *DeployCommand) Run(args []string) int {
	fs := c.FlagSet("deploy", FlagSetNone)
	fs.Usage = func() { c.Ui.Error(c.Help()) }
	args, execArgs, posArgs := flag.FilterArgs(fs, args)
	if err := fs.Parse(args); err != nil {
		return 1
	}

	// Get the remaining args to determine if we have an action.
	var action string
	if len(posArgs) > 0 {
		action = posArgs[0]
		execArgs = append(execArgs, posArgs[1:]...)
	}

	// Load the appfile
	app, err := c.Appfile()
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	// Get a core
	core, err := c.Core(app)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error loading core: %s", err))
		return 1
	}

	// Destroy action gets an extra double-check
	if action == "destroy" {
		msg := "Otto will delete all resources associated with the deploy."
		if !c.confirmDestroy(msg, execArgs) {
			return 1
		}
	}

	// Deploy the artifact
	if err := core.Deploy(action, execArgs); err != nil {
		// Display errors without prefix, we expect them to be formatted in a way
		// that's suitable for UI.
		c.Ui.Error(err.Error())
		return 1
	}

	return 0
}
コード例 #3
0
ファイル: infra.go プロジェクト: mbrodala/otto
func (c *InfraCommand) Run(args []string) int {
	fs := c.FlagSet("infra", FlagSetNone)
	fs.Usage = func() { c.Ui.Error(c.Help()) }
	args, execArgs, posArgs := flag.FilterArgs(fs, args)
	if err := fs.Parse(args); err != nil {
		return 1
	}

	// Get the remaining args to determine if we have an action.
	var action string
	if len(posArgs) > 0 {
		action = posArgs[0]
		execArgs = append(execArgs, posArgs[1:]...)
	}

	// Load the appfile
	app, err := c.Appfile()
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	// Get a core
	core, err := c.Core(app)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error loading core: %s", err))
		return 1
	}

	// Destroy action gets an extra double-check
	if action == "destroy" {
		msg := "Otto will delete all your managed infrastructure."
		if !c.confirmDestroy(msg, execArgs) {
			return 1
		}
	}

	// Execute the task
	err = core.Infra(action, execArgs)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(
			"Error occurred: %s", err))
		return 1
	}

	return 0
}