Ejemplo n.º 1
0
func Example() {
	app := cli.NewApp()
	app.Name = "todo"
	app.Usage = "task list on the command line"
	app.Commands = []cli.Command{
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a task to the list",
			Action: func(c *cli.Context) {
				println("added task: ", c.Args().First())
			},
		},
		{
			Name:    "complete",
			Aliases: []string{"c"},
			Usage:   "complete a task on the list",
			Action: func(c *cli.Context) {
				println("completed task: ", c.Args().First())
			},
		},
	}

	app.Run(os.Args)
}
Ejemplo n.º 2
0
func Test_ShowAppHelp_NoAuthor(t *testing.T) {
	output := new(bytes.Buffer)
	app := cli.NewApp()
	app.Writer = output

	c := cli.NewContext(app, nil, nil)

	cli.ShowAppHelp(c)

	if bytes.Index(output.Bytes(), []byte("AUTHOR(S):")) != -1 {
		t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
	}
}
Ejemplo n.º 3
0
func TestCommandDoNotIgnoreFlags(t *testing.T) {
	app := cli.NewApp()
	set := flag.NewFlagSet("test", 0)
	test := []string{"blah", "blah", "-break"}
	set.Parse(test)

	c := cli.NewContext(app, set, set)

	command := cli.Command{
		Name:        "test-cmd",
		Aliases:     []string{"tc"},
		Usage:       "this is for testing",
		Description: "testing",
		Action:      func(_ *cli.Context) {},
	}
	err := command.Run(c)

	expect(t, err.Error(), "flag provided but not defined: -break")
}
Ejemplo n.º 4
0
func TestCommandIgnoreFlags(t *testing.T) {
	app := cli.NewApp()
	set := flag.NewFlagSet("test", 0)
	test := []string{"blah", "blah"}
	set.Parse(test)

	c := cli.NewContext(app, set, set)

	command := cli.Command{
		Name:            "test-cmd",
		Aliases:         []string{"tc"},
		Usage:           "this is for testing",
		Description:     "testing",
		Action:          func(_ *cli.Context) {},
		SkipFlagParsing: true,
	}
	err := command.Run(c)

	expect(t, err, nil)
}
Ejemplo n.º 5
0
func main() {
	fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())

	// Apply bare tendermint/* configuration.
	cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "notice"}))

	rootDir := os.Getenv("DEBROOT")
	if rootDir == "" {
		rootDir = os.Getenv("HOME") + "/.debora"
	}

	var (
		groupFlag = cli.StringFlag{
			Name:  "group",
			Value: "default",
			Usage: "uses ~/.debora/<group>.cfg",
		}
		labelFlag = cli.StringFlag{
			Name:  "label",
			Value: "_",
			Usage: "label of the process, or _ by default",
		}
		bgFlag = cli.BoolFlag{
			Name:  "bg",
			Usage: "if set, runs as a background daemon",
		}
		inputFlag = cli.StringFlag{
			Name:  "input",
			Value: "",
			Usage: "input to the program (e.g. stdin)",
		}
	)

	app := cli.NewApp()
	app.Name = "debora"
	app.Usage = "summons commands to barak"
	app.Version = "0.0.1"
	app.Email = "[email protected],[email protected]"
	app.Flags = []cli.Flag{
		groupFlag,
	}
	app.Before = func(c *cli.Context) error {
		configFile := rootDir + "/" + c.String("group") + ".cfg"
		fmt.Printf("Using configuration from %v\n", configFile)
		ReadConfig(configFile)
		return nil
	}
	app.Commands = []cli.Command{
		cli.Command{
			Name:   "status",
			Usage:  "shows remote status",
			Action: cliGetStatus,
		},
		cli.Command{
			Name:   "run",
			Usage:  "run process",
			Action: cliStartProcess,
			Flags: []cli.Flag{
				labelFlag,
				bgFlag,
				inputFlag,
			},
		},
		cli.Command{
			Name:   "stop",
			Usage:  "stop process",
			Action: cliStopProcess,
		},
		cli.Command{
			Name:   "list",
			Usage:  "list processes",
			Action: cliListProcesses,
		},
		cli.Command{
			Name:   "open",
			Usage:  "open barak listener",
			Action: cliOpenListener,
		},
		cli.Command{
			Name:   "close",
			Usage:  "close barka listener",
			Action: cliCloseListener,
		},
		cli.Command{
			Name:   "download",
			Usage:  "download file <remote-path> <local-path-prefix>",
			Action: cliDownloadFile,
		},
		cli.Command{
			Name:   "quit",
			Usage:  "quit barak",
			Action: cliQuit,
		},
	}
	app.Run(os.Args)
}
Ejemplo n.º 6
0
func ExampleSubcommand() {
	app := cli.NewApp()
	app.Name = "say"
	app.Commands = []cli.Command{
		{
			Name:        "hello",
			Aliases:     []string{"hi"},
			Usage:       "use it to see a description",
			Description: "This is how we describe hello the function",
			Subcommands: []cli.Command{
				{
					Name:        "english",
					Aliases:     []string{"en"},
					Usage:       "sends a greeting in english",
					Description: "greets someone in english",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "name",
							Value: "Bob",
							Usage: "Name of the person to greet",
						},
					},
					Action: func(c *cli.Context) {
						println("Hello, ", c.String("name"))
					},
				}, {
					Name:    "spanish",
					Aliases: []string{"sp"},
					Usage:   "sends a greeting in spanish",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "surname",
							Value: "Jones",
							Usage: "Surname of the person to greet",
						},
					},
					Action: func(c *cli.Context) {
						println("Hola, ", c.String("surname"))
					},
				}, {
					Name:    "french",
					Aliases: []string{"fr"},
					Usage:   "sends a greeting in french",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "nickname",
							Value: "Stevie",
							Usage: "Nickname of the person to greet",
						},
					},
					Action: func(c *cli.Context) {
						println("Bonjour, ", c.String("nickname"))
					},
				},
			},
		}, {
			Name:  "bye",
			Usage: "says goodbye",
			Action: func(c *cli.Context) {
				println("bye")
			},
		},
	}

	app.Run(os.Args)
}