Example #1
0
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
}
Example #2
0
func addDriverFlagsToCommand(cliFlags []cli.Flag, cmd *cli.Command) *cli.Command {
	cmd.Flags = append(SharedCreateFlags, cliFlags...)
	cmd.SkipFlagParsing = false
	cmd.Action = runCommand(cmdCreateInner)
	sort.Sort(ByFlagName(cmd.Flags))

	return cmd
}
Example #3
0
func getRunCommand() cli.Command {

	actionRun := func(c *cli.Context) {
		cliApplicationAction(c)
		if !c.IsSet("db-host") {
			cli.ShowCommandHelp(c, "run")
			return
		}

		goAuthApp := app.NewApplication(c.String("db-user"), c.String("db-password"),
			c.String("database"), c.String("db-host"), c.Int("db-port"), c.Int("port"))

		goAuthApp.Run()

	}

	cmdRun := cli.Command{
		Name:   "run",
		Usage:  "Run the authentication service",
		Action: actionRun,
	}

	cmdRun.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "db-host",
			Usage: "The Database Hostname",
		},
		cli.IntFlag{
			Name:  "db-port",
			Usage: "The Database port",
			Value: 3306,
		},
		cli.StringFlag{
			Name:  "db-user",
			Usage: "The Database Username",
			Value: "messenger",
		},
		cli.StringFlag{
			Name:  "db-password",
			Usage: "The Database Password",
			Value: "messenger",
		},
		cli.StringFlag{
			Name:  "database",
			Usage: "The Database name",
			Value: "messenger",
		},
		cli.IntFlag{
			Name:  "port, p",
			Usage: "The port on which this app will serve requests",
			Value: 8080,
		},
	}

	return cmdRun
}
Example #4
0
func (w *YAMLConfigLoader) Wrap(cmd cli.Command) cli.Command {
	cmd.Flags = append(cmd.Flags, []cli.Flag{
		cli.StringFlag{"config", w.DefaultPath, "path to YAML config file", ""},
	}...)
	oldAction := cmd.Action
	cmd.Action = func(c *cli.Context) {
		configFile := c.String("config")
		if configFile != "" {
			err := w.LoadFromFile(configFile)
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
		}
		oldAction(c)
	}
	return cmd
}
Example #5
0
func (w *Logged) Wrap(cmd cli.Command) cli.Command {
	cmd.Flags = append(cmd.Flags, []cli.Flag{
		cli.StringFlag{"log", w.DefaultTarget, "path to log file, 'stdout', 'stderr' or 'false'", ""},
		cli.StringFlag{"log-level", w.DefaultLevel, "logging level", ""},
		cli.StringFlag{"log-format", w.DefaultFormat, "log record format: 'term', 'logfmt', 'json'", ""},
	}...)
	oldAction := cmd.Action
	cmd.Action = func(c *cli.Context) {
		handler, err := w.HandlerFor(c.String("log"), c.String("log-level"), c.String("log-format"))
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		for _, l := range w.Loggers {
			l.SetHandler(handler)
		}
		oldAction(c)
	}
	return cmd
}
Example #6
0
func main() {
	app := cli.NewApp()
	app.Name = "upx"
	app.Usage = "a tool for managing files in UPYUN"
	app.Author = "Hongbo.Mo"
	app.Email = "*****@*****.**"
	app.Version = fmt.Sprintf("%s %s/%s %s", version, runtime.GOOS,
		runtime.GOARCH, runtime.Version())
	app.Commands = make([]cli.Command, 0)

	sort.Strings(cmds)
	for _, cmd := range cmds {
		cm, exist := CmdMap[cmd]
		if exist {
			Cmd := cli.Command{
				Name:  cmd,
				Usage: cm.Desc,
				Action: func(c *cli.Context) error {
					if c.Command.FullName() != "login" && driver == nil {
						fmt.Println("Log in first.")
						os.Exit(-1)
					}
					opts := make(map[string]interface{})
					for k, v := range cm.Flags {
						if c.IsSet(k) {
							switch v.typ {
							case "bool":
								opts[k] = c.Bool(k)
							case "string":
								opts[k] = c.String(k)
							case "int":
								opts[k] = c.Int(k)
							}
						}
					}
					cm.Func(c.Args(), opts)
					return nil
				},
			}
			if cm.Alias != "" {
				Cmd.Aliases = []string{cm.Alias}
			}
			if cm.Flags != nil {
				Cmd.Flags = []cli.Flag{}
				for k, v := range cm.Flags {
					var flag cli.Flag
					switch v.typ {
					case "bool":
						flag = cli.BoolFlag{Name: k, Usage: v.usage}
					case "int":
						flag = cli.StringFlag{Name: k, Usage: v.usage}
					case "string":
						flag = cli.IntFlag{Name: k, Usage: v.usage}
					}
					Cmd.Flags = append(Cmd.Flags, flag)
				}
			}

			app.Commands = append(app.Commands, Cmd)
		}
	}

	app.Run(os.Args)
}