本文整理汇总了Golang中github.com/codegangsta/cli.App类的典型用法代码示例。如果您正苦于以下问题:Golang App类的具体用法?Golang App怎么用?Golang App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: describeApp
func describeApp(app *cli.App, version string) {
app.Name = "init-exporter"
app.Usage = "exports services described by Procfile to systemd"
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "n, appname",
Usage: "Application name (This name only affects the names of generated files)",
},
cli.BoolFlag{
Name: "c, uninstall",
Usage: "Remove scripts and helpers for a particular application",
},
cli.StringFlag{
Name: "config",
Value: defaultConfigPath,
Usage: "path to configuration file",
},
cli.StringFlag{
Name: "p, procfile",
Usage: "path to procfile",
},
cli.StringFlag{
Name: "f, format",
Usage: "Format of init files (upstart | systemd)",
},
}
}
示例2: loadCommands
func loadCommands(app *cli.App) {
// Add top level flags and commands
app.Action = mainCmd
// Filters modify what type of pr to display
filters := []cli.Flag{
cli.BoolFlag{"no-merge", "display only prs that cannot be merged"},
cli.BoolFlag{"lgtm", "display the number of LGTM"},
cli.BoolFlag{"closed", "display closed prs"},
cli.BoolFlag{"new", "display prs opened in the last 24 hours"},
}
// Options modify how to display prs
options := []cli.Flag{
cli.BoolFlag{"no-trunc", "don't truncate pr name"},
cli.StringFlag{"user", "", "display only prs from <user>"},
cli.StringFlag{"comment", "", "add a comment to the pr"},
}
app.Flags = append(filters, options...)
// Add subcommands
app.Commands = []cli.Command{
{
Name: "repo",
Usage: "List information about the current repository",
Action: repositoryInfoCmd,
},
{
Name: "auth",
Usage: "Add a github token for authentication",
Action: authCmd,
Flags: []cli.Flag{
cli.StringFlag{"add", "", "add new token for authentication"},
},
},
{
Name: "alru",
Usage: "Show the Age of the Least Recently Updated pull request for this repo. Lower is better.",
Action: alruCmd,
},
{
Name: "merge",
Usage: "Merge a pull request",
Action: mergeCmd,
Flags: []cli.Flag{
cli.StringFlag{"m", "", "commit message for merge"},
cli.BoolFlag{"force", "merge a pull request that has not been approved"},
},
},
{
Name: "checkout",
Usage: "Checkout a pull request into your local repo",
Action: checkoutCmd,
},
{
Name: "approve",
Usage: "Approve a pull request by adding LGTM to the comments",
Action: approveCmd,
},
}
}
示例3: setBasicInfos
func setBasicInfos(app *cli.App, appName string, version string) {
app.Name = appName
app.Version = version
app.Usage = "Focus on your tasks and let your code flow."
t := time.Now()
app.Copyright = "TechMantra - " + strconv.Itoa(t.Year())
}
示例4: SetupCPUProfile
func SetupCPUProfile(app *cli.App) {
app.Flags = append(app.Flags, cli.StringFlag{
Name: "cpuprofile",
Usage: "write cpu profile to file",
EnvVar: "CPU_PROFILE",
})
appBefore := app.Before
appAfter := app.After
app.Before = func(c *cli.Context) error {
if cpuProfile := c.String("cpuprofile"); cpuProfile != "" {
f, err := os.Create(cpuProfile)
if err != nil {
return err
}
pprof.StartCPUProfile(f)
}
if appBefore != nil {
return appBefore(c)
}
return nil
}
app.After = func(c *cli.Context) error {
pprof.StopCPUProfile()
if appAfter != nil {
return appAfter(c)
}
return nil
}
}
示例5: callCoreCommand
func callCoreCommand(args []string, theApp *cli.App) {
err := theApp.Run(args)
if err != nil {
os.Exit(1)
}
gateways := gatewaySliceFromMap(deps.gateways)
warningsCollector := net.NewWarningsCollector(deps.termUI, gateways...)
warningsCollector.PrintWarnings()
}
示例6: newCmdPresenter
func newCmdPresenter(app *cli.App, maxNameLen int, cmdName string) (presenter cmdPresenter) {
cmd := app.Command(cmdName)
presenter.Name = presentCmdName(*cmd)
padding := strings.Repeat(" ", maxNameLen-len(presenter.Name))
presenter.Name = presenter.Name + padding
presenter.Description = cmd.Description
return
}
示例7: loadCommands
func loadCommands(app *cli.App) {
app.Action = mainCmd
app.Flags = []cli.Flag{
cli.StringFlag{"assigned", "", "display issues assigned to <user>. Use '*' for all assigned, or 'none' for all unassigned."},
cli.StringFlag{"remote", "origin", "git remote to treat as origin"},
cli.BoolFlag{"no-trunc", "do not truncate the issue name"},
cli.IntFlag{"votes", -1, "display the number of votes '+1' filtered by the <number> specified."},
cli.BoolFlag{"vote", "add '+1' to an specific issue."},
}
app.Commands = []cli.Command{
{
Name: "alru",
Usage: "Show the Age of the Least Recently Updated issue for this repo. Lower is better.",
Action: alruCmd,
},
{
Name: "repo",
Usage: "List information about the current repository",
Action: repositoryInfoCmd,
},
{
Name: "take",
Usage: "Assign an issue to your github account",
Action: takeCmd,
Flags: []cli.Flag{
cli.BoolFlag{"overwrite", "overwrites a taken issue"},
},
},
{
Name: "search",
Usage: "Find issues by state and keyword.",
Action: searchCmd,
Flags: []cli.Flag{
cli.StringFlag{"author", "", "Finds issues created by a certain user"},
cli.StringFlag{"assignee", "", "Finds issues that are assigned to a certain user"},
cli.StringFlag{"mentions", "", "Finds issues that mention a certain user"},
cli.StringFlag{"commenter", "", "Finds issues that a certain user commented on"},
cli.StringFlag{"involves", "", "Finds issues that were either created by a certain user, assigned to that user, mention that user, or were commented on by that user"},
cli.StringFlag{"labels", "", "Filters issues based on their labels"},
cli.StringFlag{"state", "", "Filter issues based on whether they’re open or closed"},
},
},
{
Name: "auth",
Usage: "Add a github token for authentication",
Action: authCmd,
Flags: []cli.Flag{
cli.StringFlag{"add", "", "add new token for authentication"},
},
},
}
}
示例8: run
// so we can catch panics
func run(app *cli.App) {
defer func() {
if r := recover(); r != nil {
trace := make([]byte, 2048)
count := runtime.Stack(trace, true)
fmt.Println("Panic: ", r)
fmt.Printf("Stack of %d bytes: %s", count, trace)
}
}()
app.Run(os.Args)
}
示例9: GetByCmdName
func GetByCmdName(app *cli.App, cmdName string) (cmd *cli.Command, err error) {
cmd = app.Command(cmdName)
if cmd == nil {
for _, c := range app.Commands {
if c.ShortName == cmdName {
return &c, nil
}
}
err = errors.New("Command not found")
}
return
}
示例10: loadCommands
func loadCommands(app *cli.App) {
// default to listing a service
app.Action = getAction
app.Flags = []cli.Flag{
cli.BoolFlag{"json", "output to json"},
cli.StringFlag{"host", os.Getenv("SKYDNS"), "url to SkyDNS's HTTP endpoints (defaults to env. var. SKYDNS)"},
cli.StringFlag{"dns",
func() string {
if x := os.Getenv("SKYDNS_DNS"); x != "" {
if strings.HasPrefix(x, "http") {
return x
}
return "http://" + x // default to http for now
}
return "127.0.0.1:53"
}(), "DNS port of SkyDNS's DNS endpoint (defaults to env. var. SKYDNS_DNS)"},
cli.StringFlag{"domain",
func() string {
if x := os.Getenv("SKYDNS_DOMAIN"); x != "" {
return x
}
return "skydns.local"
}(), "DNS domain of SkyDNS (defaults to env. var. SKYDNS_DOMAIN))"},
cli.StringFlag{"secret", "", "secret to authenticate with"},
}
app.Commands = []cli.Command{
{
Name: "list",
Usage: "list a service from skydns",
Action: getAction,
Flags: []cli.Flag{cli.BoolFlag{"d", "use DNS instead of HTTP"}},
},
{
Name: "add",
Usage: "add a new service to skydns",
Action: addAction,
},
{
Name: "delete",
Usage: "delete a service from skydns",
Action: deleteAction,
},
{
Name: "update",
Usage: "update a service's ttl in skydns",
Action: updateAction,
},
}
}
示例11: loadCommands
func loadCommands(app *cli.App) {
// default to listing a service
app.Action = getAction
app.Flags = []cli.Flag{
cli.BoolFlag{"json", "output to json"},
cli.StringFlag{"host", os.Getenv("SKYDNS"), "url to SkyDNS's HTTP endpoints (defaults to env. var. SKYDNS)"},
cli.StringFlag{"dnsport",
func() string {
x := os.Getenv("SKYDNS_DNSPORT")
if x == "" {
x = "53"
}
return x
}(), "DNS port of SkyDNS's DNS endpoint (defaults to env. var. SKYDNS_DNSPORT or 53)"},
cli.StringFlag{"dnsdomain",
func() string {
x := os.Getenv("SKYDNS_DNSDOMAIN")
if x == "" {
x = "skydns.local"
}
return x
}(), "DNS domain of SkyDNS (defaults to env. var. SKYDNS_DNSDOMAIN or skydns.local)"},
cli.StringFlag{"secret", "", "secret to authenticate with"},
}
app.Commands = []cli.Command{
{
Name: "list",
Usage: "list a service from skydns",
Action: getAction,
Flags: []cli.Flag{cli.BoolFlag{"d", "use DNS instead of HTTP"}},
},
{
Name: "add",
Usage: "add a new service to skydns",
Action: addAction,
},
{
Name: "delete",
Usage: "delete a service from skydns",
Action: deleteAction,
},
{
Name: "update",
Usage: "update a service's ttl in skydns",
Action: updateAction,
},
}
}
示例12: TestParseGenericFromEnvCascade
func TestParseGenericFromEnvCascade(t *testing.T) {
os.Clearenv()
os.Setenv("APP_FOO", "99,2000")
a := cli.App{
Flags: []cli.Flag{
cli.GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
},
Action: func(ctx *cli.Context) {
if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
t.Errorf("value not set from env")
}
},
}
a.Run([]string{"run"})
}
示例13: Run
func Run(app *cli.App) {
app.Before = func(c *cli.Context) error {
if c.GlobalString("key") == "" {
log.Fatal("No aio key provided. Use --key KEY_HERE or export AIO_KEY=KEY_HERE")
}
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
log.Debug("Debug Mode ON")
log.Debug("AIO_KEY: ", c.GlobalString("key"))
}
return nil
}
app.Run(os.Args)
}
示例14: cmdConsole
func cmdConsole(app *cli.App, c *cli.Context) {
for {
fmt.Printf("> ")
bufReader := bufio.NewReader(os.Stdin)
line, more, err := bufReader.ReadLine()
if more {
Exit("input is too long")
} else if err != nil {
Exit(err.Error())
}
args := []string{"tmsp"}
args = append(args, strings.Split(string(line), " ")...)
app.Run(args)
}
}
示例15: AddAdditinalFlags
func AddAdditinalFlags(a *cli.App) {
// nop
a.Flags = append(a.Flags,
cli.StringFlag{memProfileFlagName, "", "If set, the given file will contain the memory profile of the previous run"},
cli.StringFlag{cpuProfileFlagName, "", "If set, the given file will contain the CPU profile of the previous run"},
)
}