本文整理汇总了Golang中github.com/codegangsta/cli.App.Action方法的典型用法代码示例。如果您正苦于以下问题:Golang App.Action方法的具体用法?Golang App.Action怎么用?Golang App.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.App
的用法示例。
在下文中一共展示了App.Action方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setDefaultAction
func setDefaultAction(app *cli.App) {
app.Action = func(c *cli.Context) {
// TODO: If in a focused directory show the list of tasks
// If not show the app help or some basic direction to init it
cli.ShowAppHelp(c)
}
}
示例2: 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.BoolFlag{"no-trunc", "do not truncate the issue name"},
}
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: "auth",
Usage: "Add a github token for authentication",
Action: authCmd,
Flags: []cli.Flag{
cli.StringFlag{"add", "", "add new token for authentication"},
},
},
}
}
示例3: 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"},
},
},
}
}
示例4: 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,
},
}
}
示例5: 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,
},
}
}
示例6: mainLoop
func mainLoop(app *cli.App) {
app.Action = func(c *cli.Context) {
//host := c.GlobalString("host")
cfg, err := getConfig(c)
if err != nil {
log.WithFields(log.Fields{
"file:": "main.go",
"func:": "main",
"line:": 74,
}).Fatal("getConfig return error")
return
}
svc := OnionService{}
if err = svc.Run(cfg); err != nil {
log.Fatal(err)
}
}
}
示例7:
It("defaults the version", func() {
Expect(cliApp).NotTo(BeNil())
Expect(cliApp.Version).To(Equal("development (not versioned) (diego unknown)"))
})
})
Describe("App.Action", func() {
Context("when ltc is run without argument(s)", func() {
It("prints app help", func() {
cli.AppHelpTemplate = "HELP_TEMPLATE"
flagSet := flag.NewFlagSet("flag_set", flag.ContinueOnError)
flagSet.Parse([]string{})
testContext := cli.NewContext(cliApp, flagSet, nil)
cliApp.Action(testContext)
Expect(outputBuffer).To(test_helpers.Say("ltc - Command line interface for Lattice."))
})
})
Context("when ltc is run with argument(s)", func() {
It("prints unknown command message", func() {
flagSet := flag.NewFlagSet("flag_set", flag.ContinueOnError)
flagSet.Parse([]string{"one_arg"})
testContext := cli.NewContext(cliApp, flagSet, nil)
cliApp.Action(testContext)
Expect(outputBuffer).To(test_helpers.Say("ltc: 'one_arg' is not a registered command. See 'ltc help'"))
})
示例8: loadCommands
func loadCommands(app *cli.App) {
// Add top level flags and commands
app.Action = mainCmd
app.Flags = []cli.Flag{
cli.StringFlag{"remote", "origin", "git remote to treat as origin"},
}
// 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.StringFlag{"state", "open", "display prs based on their state"},
cli.BoolFlag{"new", "display prs opened in the last 24 hours"},
cli.BoolFlag{"mine", "display only PRs I care about based on the MAINTAINERS files"},
cli.StringFlag{"maintainer", "", "display only PRs a maintainer cares about based on the MAINTAINERS files"},
cli.StringFlag{"sort", "updated", "sort the prs by (created, updated, popularity, long-running)"},
cli.StringFlag{"assigned", "", "display only prs assigned to a user"},
cli.BoolFlag{"unassigned", "display only unassigned prs"},
cli.StringFlag{"dir", "", "display only prs that touch this dir"},
cli.StringFlag{"extension", "", "display only prs that have files with this extension (no dot)"},
cli.BoolFlag{"cleanup", "display only cleanup prs"},
}
app.Flags = append(app.Flags, filters...)
// 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(app.Flags, options...)
// Add subcommands
app.Commands = []cli.Command{
{
Name: "repo",
Usage: "List information about the current repository",
Action: repositoryInfoCmd,
},
{
Name: "comment",
Usage: "Leave a comment on a pull request",
Action: commentCmd,
},
{
Name: "comments",
Usage: "Show comments on a pull request",
Action: commentsCmd,
},
{
Name: "auth",
Usage: "Add a github token for authentication",
Action: authCmd,
Flags: []cli.Flag{
cli.StringFlag{"add", "", "add new token for authentication"},
cli.StringFlag{"user", "", "add github user name"},
},
},
{
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: "close",
Usage: "Close a pull request without merging it",
Action: closeCmd,
Flags: []cli.Flag{},
},
{
Name: "checkout",
Usage: "Checkout a pull request into your local repo",
Action: checkoutCmd,
},
{
Name: "send",
Usage: "Send a new pull request, or overwrite an existing one",
Action: sendCmd,
},
{
Name: "approve",
Usage: "Approve a pull request by adding LGTM to the comments",
Action: approveCmd,
},
{
Name: "take",
Usage: "Assign a pull request to your github account",
Action: takeCmd,
Flags: []cli.Flag{
cli.BoolFlag{"steal", "steal the pull request from its current owner"},
//.........这里部分代码省略.........
示例9: 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.StringFlag{"state", "open", "display prs based on their state"},
cli.BoolFlag{"new", "display prs opened in the last 24 hours"},
cli.BoolFlag{"mine", "display only PRs I care about based on the MAINTAINERS files"},
cli.StringFlag{"sort", "updated", "sort the prs by (created, updated, popularity, long-running)"},
}
// 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"},
cli.StringFlag{"user", "", "add github user name"},
},
},
{
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,
},
{
Name: "diff",
Usage: "Print the patch submitted by a pull request",
Action: showCmd,
},
{
Name: "reviewers",
Usage: "Use the hierarchy of MAINTAINERS files to list who should review a pull request",
Action: reviewersCmd,
},
{
Name: "contributors",
Usage: "Show the contributors list with additions, deletions, and commit counts. Default: sorted by Commits",
Action: contributorsCmd,
Flags: []cli.Flag{
cli.BoolFlag{"additions", "sort by additions"},
cli.BoolFlag{"deletions", "sort by deletions"},
cli.BoolFlag{"commits", "sort by commits"},
cli.IntFlag{"top", 10, "top N contributors"},
},
},
}
}
示例10: loadCommands
func loadCommands(app *cli.App) {
app.Action = mainCmd
app.Flags = []cli.Flag{
cli.StringFlag{Name: "assigned", Value: "", Usage: "display issues assigned to <user>. Use '*' for all assigned, or 'none' for all unassigned."},
cli.StringFlag{Name: "remote", Value: gordon.GetDefaultGitRemote(), Usage: "git remote to treat as origin"},
cli.StringFlag{Name: "milestone", Value: "", Usage: "display issues inside a particular <milestone>."},
cli.BoolFlag{Name: "no-trunc", Usage: "do not truncate the issue name"},
cli.BoolFlag{Name: "verbose", Usage: "show more verbose output on actions"},
cli.IntFlag{Name: "votes", Value: -1, Usage: "display the number of votes '+1' filtered by the <number> specified."},
cli.BoolFlag{Name: "vote", Usage: "add '+1' to an specific issue."},
cli.BoolFlag{Name: "proposals", Usage: "Only show proposal issues"},
}
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{Name: "overwrite", Usage: "overwrites a taken issue"},
},
},
{
Name: "close",
Usage: "Close an issue",
Description: "Provide the issue number for issue(s) to close for this repository",
Action: closeCmd,
Flags: []cli.Flag{},
},
{
Name: "search",
Usage: "Find issues by state and keyword.",
Action: searchCmd,
Flags: []cli.Flag{
cli.StringFlag{Name: "author", Value: "", Usage: "Finds issues created by a certain user"},
cli.StringFlag{Name: "assignee", Value: "", Usage: "Finds issues that are assigned to a certain user"},
cli.StringFlag{Name: "mentions", Value: "", Usage: "Finds issues that mention a certain user"},
cli.StringFlag{Name: "commenter", Value: "", Usage: "Finds issues that a certain user commented on"},
cli.StringFlag{Name: "involves", Value: "", Usage: "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{Name: "labels", Value: "", Usage: "Filters issues based on their labels"},
cli.StringFlag{Name: "state", Value: "", Usage: "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{Name: "add", Value: "", Usage: "add new token for authentication"},
},
},
}
}