예제 #1
0
파일: service.go 프로젝트: carriercomm/os
func serviceCommand() cli.Command {
	factory := &projectFactory{}

	app := cli.Command{}
	app.Name = "service"
	app.ShortName = "s"
	app.Usage = "Command line interface for services and compose."
	app.Before = beforeApp
	app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
	app.Subcommands = append(serviceSubCommands(),
		command.BuildCommand(factory),
		command.CreateCommand(factory),
		command.UpCommand(factory),
		command.StartCommand(factory),
		command.LogsCommand(factory),
		command.RestartCommand(factory),
		command.StopCommand(factory),
		command.ScaleCommand(factory),
		command.RmCommand(factory),
		command.PullCommand(factory),
		command.KillCommand(factory),
		command.PortCommand(factory),
		command.PsCommand(factory),
	)

	return app
}
예제 #2
0
파일: ahoy.go 프로젝트: dkinzer/ahoy
func getCommands(config Config) []cli.Command {
	exportCmds := []cli.Command{}

	var keys []string
	for k := range config.Commands {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, name := range keys {
		cmd := config.Commands[name]
		cmdName := name
		subCommands := []cli.Command{}

		// Handle the import of subcommands.
		if cmd.Import != "" {
			// If the first character isn't "/" or "~" we assume a relative path.
			subSource := cmd.Import
			if cmd.Import[0] != "/"[0] || cmd.Import[0] != "~"[0] {
				subSource = filepath.Join(sourcedir, cmd.Import)
			}
			logger("info", "Importing commands into '"+name+"' command from "+subSource)
			subConfig, _ := getConfig(subSource)
			subCommands = getCommands(subConfig)
		}

		newCmd := cli.Command{
			Name:            name,
			SkipFlagParsing: true,
			HideHelp:        cmd.Hide,
		}

		if cmd.Usage != "" {
			newCmd.Usage = cmd.Usage
		}

		if cmd.Cmd != "" {
			newCmd.Action = func(c *cli.Context) {
				args = c.Args()
				runCommand(cmdName, cmd.Cmd)
			}
		}

		if subCommands != nil {
			newCmd.Subcommands = subCommands
		}

		//log.Println("found command: ", name, " > ", cmd.Cmd )
		exportCmds = append(exportCmds, newCmd)
	}

	return exportCmds
}
예제 #3
0
func getCommand(baseName string, metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command {
	command := cli.Command{
		Name:        metadata.Name,
		Aliases:     metadata.Aliases,
		ShortName:   metadata.ShortName,
		Description: metadata.Description,
		Usage:       strings.Replace(metadata.Usage, "BROOKLYN_NAME", baseName, -1),
		Action: func(context *cli.Context) {
			err := runner.RunCmdByName(metadata.Name, context)
			if err != nil {
				error_handler.ErrorExit(err)
			}
		},
		Flags:           metadata.Flags,
		SkipFlagParsing: metadata.SkipFlagParsing,
	}

	if nil != metadata.Operands {
		command.Subcommands = make([]cli.Command, 0)
		for _, operand := range metadata.Operands {
			command.Subcommands = append(command.Subcommands, cli.Command{
				Name:            operand.Name,
				Aliases:         operand.Aliases,
				ShortName:       operand.ShortName,
				Description:     operand.Description,
				Usage:           operand.Usage,
				Flags:           operand.Flags,
				SkipFlagParsing: operand.SkipFlagParsing,
				Action:          subCommandAction(command.Name, operand.Name, runner),
			})
			command.Usage = strings.Join([]string{
				command.Usage, "\n... ", operand.Usage, "\t", operand.Description,
			}, "")
		}
	}

	return command
}
예제 #4
0
파일: host.go 프로젝트: thiderman/sagacity
// MakeCLI creates the CLI tree for a Host info
func (h HostInfo) MakeCLI() []cli.Command {
	sc := make([]cli.Command, 0, len(h.Types))
	for _, key := range h.Types.List() {
		cat := h.Types[key]
		cc := cli.Command{ // cc = category command
			Name:        key,
			Usage:       cat.Summary,
			HideHelp:    true,
			Subcommands: make([]cli.Command, 0, len(cat.Hosts)),
			Action: func(c *cli.Context) {
				cat.PrimaryHost().Execute("")
			},
		}

		for _, host := range cat.Hosts {
			hc := cli.Command{ // hc = host command
				Name:     host.FQDN,
				Usage:    host.Summary,
				HideHelp: true,
				Action: func(c *cli.Context) {
					var host *Host
					args := c.Args()

					if len(args) == 0 {
						// No extra arguments - go to the primary host
						host = cat.PrimaryHost()
					} else {
						// Arguments were defined - go to the fqdn specified
						// TODO(thiderman): Error handling, integer index handling
						host = cat.GetHost(args[0])
					}

					host.Execute("")
				},
			}
			cc.Subcommands = append(cc.Subcommands, hc)
		}

		sc = append(sc, cc)
	}
	return sc
}
예제 #5
0
파일: ahoy.go 프로젝트: DevinciHQ/ahoy
func getCommands(config Config) []cli.Command {
	exportCmds := []cli.Command{}

	var keys []string
	for k := range config.Commands {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, name := range keys {
		cmd := config.Commands[name]
		cmdName := name

		newCmd := cli.Command{
			Name:            name,
			SkipFlagParsing: true,
			HideHelp:        cmd.Hide,
		}

		if cmd.Usage != "" {
			newCmd.Usage = cmd.Usage
		}

		if cmd.Cmd != "" {
			newCmd.Action = func(c *cli.Context) {
				args = c.Args()
				runCommand(cmdName, cmd.Cmd)
			}
		}

		subCommands := getSubCommands(cmd.Imports)
		if subCommands != nil {
			newCmd.Subcommands = subCommands
		}

		//log.Println("found command: ", name, " > ", cmd.Cmd )
		exportCmds = append(exportCmds, newCmd)
	}

	return exportCmds
}
예제 #6
0
func init() {
	cmd := &ExecCommand{}

	flags := clihelpers.GetFlagsFromStruct(cmd)
	cliCmd := cli.Command{
		Name:  "exec",
		Usage: "execute a build locally",
	}

	for _, executor := range common.GetExecutors() {
		subCmd := cli.Command{
			Name:   executor,
			Usage:  "use " + executor + " executor",
			Action: cmd.Execute,
			Flags:  flags,
		}
		cliCmd.Subcommands = append(cliCmd.Subcommands, subCmd)
	}

	common.RegisterCommand(cliCmd)
}
예제 #7
0
func init() {
	catalogCmd := cli.Command{
		Name:  "catalog",
		Usage: "Manage Otsimo catalogs",
	}
	catalogCmd.Subcommands = []cli.Command{
		{
			Name:   "push",
			Usage:  "push catalog",
			Action: catalogPush,
		},
		{
			Name:   "validate",
			Usage:  "validate catalog file",
			Action: catalogValidate,
		},
		{
			Name:   "current",
			Usage:  "get current accessible catalog",
			Action: catalogCurrent,
		},
		{
			Name:   "approve",
			Usage:  "approve a catalog",
			Action: catalogApprove,
		},
		{
			Name:   "list",
			Usage:  "list catalogs",
			Action: catalogList,
			Flags: []cli.Flag{
				cli.BoolFlag{Name: "hide-expired"},
				cli.IntFlag{Name: "limit", Value: 100},
				cli.StringFlag{Name: "status", Value: "both", Usage: "catalog status: both, draft, approved"},
			},
		},
	}
	commands = append(commands, catalogCmd)
}
예제 #8
0
파일: game.go 프로젝트: otsimo/otsimoctl
func init() {
	gameCmd := cli.Command{
		Name:  "game",
		Usage: "Manage games",
	}

	gameCmd.Subcommands = []cli.Command{{
		Name:   "init",
		Action: gameInit,
		Usage:  "Creates a new empty game",
	}, {
		Name:   "list",
		Action: gameList,
		Usage:  "Shows list of games",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "state", Value: "any", Usage: "available values are: any, created, dev, waiting, validated, production"},
			cli.IntFlag{Name: "limit", Value: 100, Usage: "limit return results"},
		},
	}, {
		Name:   "publish",
		Action: gamePublish,
		Usage:  "Upload the game at current directory",
	}, {
		Name:        "change-state",
		Action:      gameChangeState,
		Usage:       "Changes a game's state",
		Description: "ex: 'otsimoctl change-state sample-game 0.1.2 validated'",
	}, {
		Name:   "info",
		Action: gameEnv,
		Usage:  "Info of the game at current directory",
		Flags: []cli.Flag{
			cli.BoolFlag{Name: "env"},
		},
	}}

	commands = append(commands, gameCmd)
}
예제 #9
0
파일: repo.go 프로젝트: thiderman/sagacity
// MakeCLI generates a cli.Command chain based on the repository structure
func (r *Repo) MakeCLI() (c cli.Command) {
	c = cli.Command{
		Name:     r.Key,
		Usage:    r.Summary,
		HideHelp: true,
	}

	// Make a list of subcommands to add into the Command.
	subcommands := make([]cli.Command, 0, len(r.Items)+len(r.Subrepos))

	// Loop over the subrepositories first, making sure that they are on top.
	for _, key := range r.SubrepoKeys() {
		subrepo := r.Subrepos[key]
		subcommands = append(subcommands, subrepo.MakeCLI())
	}

	// Then loop the item files.
	for _, key := range r.Keys() {
		item := r.Items[key]

		sc := cli.Command{
			Name:     item.ID(),
			Usage:    item.Summary(),
			HideHelp: true,
			Action:   item.Execute,
		}

		sc.Subcommands = append(sc.Subcommands, item.MakeCLI()...)

		subcommands = append(subcommands, sc)
	}

	c.Subcommands = subcommands

	return
}