Beispiel #1
0
// NewApp creates a new cli app
func NewApp(eh *ErrorHandler) *cli.App {
	app := cli.NewApp()
	app.Version = VERSION
	app.Name = "cfops"
	app.Usage = "Cloud Foundry Operations Tool"
	app.Commands = []cli.Command{
		cli.Command{
			Name:  "version",
			Usage: "shows the application version currently in use",
			Action: func(c *cli.Context) {
				cli.ShowVersion(c)
			},
		},
		cli.Command{
			Name:  "list-tiles",
			Usage: "shows a list of available backup/restore target tiles",
			Action: func(c *cli.Context) {
				fmt.Println("Available Tiles:")
				for n, _ := range tileregistry.GetRegistry() {
					fmt.Println(n)
				}
			},
		},
		CreateBURACliCommand("backup", "creates a backup archive of the target tile", eh),
		CreateBURACliCommand("restore", "restores from an archive to the target tile", eh),
	}
	return app
}
Beispiel #2
0
// NewApp creates a new cli app
func NewApp() *cli.App {
	app := cli.NewApp()
	app.Version = VERSION
	app.Name = "cfops"
	app.Usage = "Cloud Foundry Operations Tool"
	app.Flags = append(app.Flags,
		cli.StringFlag{
			Name:   "logLevel",
			Value:  "info",
			Usage:  "set the log level by setting the LOG_LEVEL environment variable",
			EnvVar: "LOG_LEVEL",
		},
	)
	app.Commands = append(app.Commands, []cli.Command{
		cli.Command{
			Name: "version",
			Action: func(c *cli.Context) {
				cli.ShowVersion(c)
			},
		},
		backupCli,
		restoreCli,
	}...)
	return app
}
Beispiel #3
0
func Main(args []string, journal, output io.Writer) {
	App := cli.NewApp()

	App.Name = "repeatr"
	App.Usage = "Run it. Run it again."
	App.Version = "0.0.1"

	App.Writer = journal

	App.Commands = []cli.Command{
		RunCommandPattern(output),
		ScanCommandPattern(output),
		TwerkCommandPattern(os.Stdin, output, output), // FIXME this is too much loss of precision already
	}

	// Reporting "no help topic for 'zyx'" and exiting with a *zero* is... silly.
	// A failure to hit a command should be an error.  Like, if a bash script does `repeatr somethingimportant`, there's no way it shouldn't *stop* when that's not there.
	App.CommandNotFound = func(ctx *cli.Context, command string) {
		fmt.Fprintf(ctx.App.Writer, "'%s %v' is not a repeatr subcommand\n", ctx.App.Name, command)
		os.Exit(int(EXIT_BADARGS))
	}

	// Put some more info in our version printer.
	// Global var.  Womp womp.
	// Also, version goes to stdout.
	cli.VersionPrinter = func(ctx *cli.Context) {
		fmt.Fprintf(os.Stdout, "%v v%v\n", ctx.App.Name, ctx.App.Version)
		fmt.Fprintf(os.Stdout, "git commit %v\n", GITCOMMIT)
		fmt.Fprintf(os.Stdout, "build date %v\n", BUILDDATE)
	}

	// Invoking version as a subcommand should also fly.
	App.Commands = append(App.Commands,
		cli.Command{
			Name:  "version",
			Usage: "Shows the version of repeatr",
			Action: func(ctx *cli.Context) {
				cli.ShowVersion(ctx)
			},
		},
	)

	App.Run(args)
}
Beispiel #4
0
func TestAppVersionPrinter(t *testing.T) {
	oldPrinter := cli.VersionPrinter
	defer func() {
		cli.VersionPrinter = oldPrinter
	}()

	var wasCalled = false
	cli.VersionPrinter = func(c *cli.Context) {
		wasCalled = true
	}

	app := cli.NewApp()
	ctx := cli.NewContext(app, nil, nil)
	cli.ShowVersion(ctx)

	if wasCalled == false {
		t.Errorf("Version printer expected to be called, but was not")
	}
}
Beispiel #5
0
/*NewApp - Creates a new CLI App instance*/
func NewApp() *cli.App {
	app := cli.NewApp()
	app.Version = VERSION
	app.Name = "cfdatamanager"
	app.Usage = "Cloud Foundry Data Tile Tool"
	app.Flags = append(app.Flags,
		cli.StringFlag{
			Name:  "logLevel",
			Value: "info",
			Usage: "log level: debug, info, error, fatal",
		},
	)
	app.Commands = append(app.Commands, []cli.Command{
		cli.Command{
			Name: "version",
			Action: func(c *cli.Context) {
				cli.ShowVersion(c)
			},
		},
		backupCli,
	}...)
	return app
}
Beispiel #6
0
func (c *contextCommandLine) ShowVersion() {
	cli.ShowVersion(c.Context)
}
Beispiel #7
0
	timeout     = 10 * time.Second

	commands = []cli.Command{
		// health check
		{
			Name:        "proxyHealthCheck",
			ShortName:   "phc",
			Usage:       "upproxy health check",
			Description: "upproxy health check with get_topology",
			Flags:       flags,
			Action: func(c *cli.Context) {
				if c.IsSet("default-file") {
					defaultFile = c.String("default-file")
				}
				if c.Bool("version") {
					cli.ShowVersion(c)
					return
				}

				f, err := os.Open(defaultFile)
				if err == nil {
					r := bufio.NewReader(f)
					for {
						b, _, err := r.ReadLine()
						if err != nil {
							if err == io.EOF {
								break
							}
							panic(err)
						}
Beispiel #8
0
func main() {
	app := cli.NewApp()
	app.Name = "httpcap"
	app.Usage = "A simple network analyzer that capture http network traffic."
	app.Version = "0.1.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "interface, i",
			Value: "",
			Usage: "interface to listen on (e.g. eth0, en1, or 192.168.1.1, 127.0.0.1 etc.)",
		},
		cli.StringFlag{
			Name:  "port, p",
			Value: "",
			Usage: "port to listen on (default listen on all port)",
		},
		cli.BoolFlag{
			Name:  "raw, r",
			Usage: "show raw stream. it is a shortcut for -l %request%response",
		},
		cli.StringFlag{
			Name:  "format, f",
			Value: "",
			Usage: "output format. You can specify the output string format containing reserved keyword that will be replaced with the proper value",
		},
		cli.StringFlag{
			Name:  "keyword, k",
			Value: "",
			Usage: "filte output with the keyword in request url",
		},
		cli.IntFlag{
			Name:  "body, b",
			Value: 0,
			Usage: "the length to truncate response body (0 - not show body, -1 - show all body)",
		},
		cli.StringFlag{
			Name:  "service, s",
			Value: "http",
			Usage: "limit output service (http|memcache|redis|mongodb|twemproxy|mysql)",
		},
		cli.BoolFlag{
			Name:  "verbose, vv",
			Usage: "output debug message",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:  "list",
			Usage: "show all interfaces",
			Action: func(c *cli.Context) {
				common.ShowAllInterfaces()
			},
		}}
	app.Action = func(c *cli.Context) {
		config.Setting.Verbose = c.Bool("verbose")
		config.Setting.InterfaceName = c.String("interface")
		config.Setting.Port = c.String("port")
		config.Setting.Format = c.String("format")
		config.Setting.Filter = c.String("keyword")
		config.Setting.TruncateBodyLength = c.Int("body")
		config.Setting.Raw = c.Bool("raw")
		config.Setting.Service = c.String("service")

		if c.Bool("version") {
			cli.ShowVersion(c)
			return
		}

		if c.Bool("help") {
			cli.ShowAppHelp(c)
			return
		}

		startCapture()
	}

	app.Run(os.Args)
}
Beispiel #9
0
Datei: cf.go Projekt: rendon/cf
func main() {
	var app = cli.NewApp()
	app.Name = "cf"
	app.Version = "0.1.0"
	app.Usage = "Codeforces client"
	app.Action = func(c *cli.Context) {
		if c.Bool("version") {
			cli.ShowVersion(c)
			return
		}
		cli.ShowAppHelp(c)
	}
	app.Before = func(c *cli.Context) error {
		if c.GlobalBool("verbose") {
			log.SetLevel(log.InfoLevel)
		}
		return nil
	}
	app.Commands = []cli.Command{
		{
			Name:      "get",
			Usage:     "Retrieves test cases for a single codeforces problem",
			ArgsUsage: "<ProblemURL>",
			Action:    get,
		},
		{
			Name:      "setup",
			Usage:     "Setup environment for contest or single problem",
			ArgsUsage: "<ContestID | ProblemURL>",
			Action:    setup,
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Usage: "programming language for sample solutions",
				},
			},
		},
		{
			Name:      "gen",
			Usage:     "Generates sample solution",
			ArgsUsage: "<source_file.ext>",
			Action:    gen,
		},
		{
			Name:   "test",
			Usage:  "Runs solution against test cases",
			Action: test,
		},
		{
			Name:      "config",
			Usage:     "Set or show settings",
			ArgsUsage: "[<key> <value>]",
			Action:    config,
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "list",
					Usage: "Display current settings",
				},
				cli.BoolFlag{
					Name:  "global",
					Usage: "Settings for ~/.cf.yml file",
				},
			},
		},
	}
	app.HideVersion = true
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "verbose, v",
			Usage: "Display detailed information of the operations",
		},
		cli.BoolFlag{
			Name:  "version, V",
			Usage: "print the version",
		},
	}

	app.Run(os.Args)
}