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"}, }, }, } }
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, }, } }
func setupPingCommand(app *cli.App) { app.Commands = append(app.Commands, cli.Command{ Name: "ping", Aliases: []string{"p"}, Usage: "ping the cluster to see if it's available", Action: ping, }, ) }
func setupGlobalCommands(app *cli.App) { app.Commands = []cli.Command{ { Name: "help", Aliases: []string{"man"}, Usage: "prints this help message", Action: cli.ShowAppHelp, }, } }
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"}, }, }, } }
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, }, } }
func setCommands(app *cli.App) { commands := []cli.Command{} // TODO: Automaticaly load the commands based on the cmd directory content. commands = append(commands, cmd.Init()) commands = append(commands, cmd.List()) commands = append(commands, cmd.On()) commands = append(commands, cmd.Log()) commands = append(commands, cmd.Stop()) commands = append(commands, cmd.Done()) commands = append(commands, cmd.Status()) app.Commands = commands }
func main() { var app *cli.App app = cli.NewApp() app.Name = APP_NAME app.Version = APP_VER app.Usage = "email for mail sending, or web or none for run web interface!" app.Commands = []cli.Command{ task.CmdWeb, task.CmdEmail, } app.Flags = append(app.Flags, []cli.Flag{}...) app.Run(os.Args) }
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, }, } }
// Set application commands func setCommands(app *cli.App, config *configuration) { app.Commands = []cli.Command{ { Name: "checkout", Aliases: []string{"co"}, Usage: "Checkout branch", Flags: []cli.Flag{ cli.BoolFlag{ Name: "b", Usage: "Create new branch while checkout", }, }, Action: func(c *cli.Context) { valid := validateConfiguration(config) if !valid { fmt.Println(errorDecorator("Please provide valid configuration")) os.Exit(1) } checkoutBranch(c, config) }, }, { Name: "version", Aliases: []string{"v"}, Usage: "Get version issues", Action: func(c *cli.Context) { valid := validateConfiguration(config) if !valid { fmt.Println(errorDecorator("Please provide valid configuration")) os.Exit(1) } getVersionIssues(c, config) }, }, { Name: "description", Aliases: []string{"d"}, Usage: "Show issue description", Action: func(c *cli.Context) { valid := validateConfiguration(config) if !valid { fmt.Println(errorDecorator("Please provide valid configuration")) os.Exit(1) } showIssueDetails(c, config) }, }, } }
//import "encoding/json" // maybe pass in a points to Commands, so we can register // subcommands? Or a register module to do the registering. func Register(app *cli.App) string { app.Commands = []cli.Command{ { Name: "cloudformation", Subcommands: []cli.Command{ { Name: "follow-stack-events", Usage: "NAME...", Action: followStackEvents, }, }, }, } return "Finished" }
func AddToCLI(a *cli.App) { commands := []cli.Command{ { Name: "ec2", Usage: "find EC2 instances that match a regex", Aliases: []string{"e"}, Subcommands: []cli.Command{ { Name: "match", Aliases: []string{"m"}, Usage: "find EC2 instances that match a regex", Action: Match, }, }, }, } a.Commands = append(a.Commands, commands...) }
func setupCommands(app *cli.App) { app.Commands = []cli.Command{ { Name: "signature", Aliases: []string{"s"}, Usage: "Signature generate use blake2 algorithm\n" + " -b, --block-size=BYTES Signature block size\n" + " -s, --sum-size=BYTES Set signature strength\n", Flags: []cli.Flag{ cli.IntFlag{ Name: "block-size,b", Value: 2048, Usage: "Set signature block size", }, cli.IntFlag{ Name: "sum-size,s", Value: 32, Usage: "Set signature strong checksum strength, 32 or 64", }, }, Action: doSign, }, { Name: "delta", Aliases: []string{"d"}, Usage: "Delta-encoding options:\n" + " -b, --block-size=BYTES Signature block size\n" + " -s, --sum-size=BYTES Set signature strength\n", Action: doDelta, }, { Name: "patch", Aliases: []string{"p"}, Usage: "complete a task on the list\n" + " -b, --block-size=BYTES Signature block size\n" + " -s, --sum-size=BYTES Set signature strength\n", Action: doPatch, }, } }
func initCommands(app *gcli.App) { app.Commands = []gcli.Command{ createAlertCommand(), getAlertCommand(), attachFileCommand(), acknowledgeCommand(), renotifyCommand(), takeOwnershipCommand(), assignOwnerCommand(), addTeamCommand(), addRecipientCommand(), addTagsCommand(), addNoteCommand(), executeActionCommand(), closeAlertCommand(), deleteAlertCommand(), heartbeatCommand(), enableCommand(), disableCommand(), } }
func setupClusterCommand(app *cli.App) { app.Commands = append( app.Commands, cli.Command{ Name: "cluster", Aliases: []string{"c"}, Usage: "get information about the connected cluster", Action: cli.ShowSubcommandHelp, HideHelp: true, Subcommands: []cli.Command{ cli.Command{ Name: "health", Aliases: []string{"h"}, Usage: "get health information about the cluster", Action: getClusterHealth, }, cli.Command{ Name: "stats", Aliases: []string{"s"}, Usage: "get cluster-wide statistics, including indices, storage and nodes", Action: getClusterStats, }, cli.Command{ Name: "nodes", Aliases: []string{"n"}, Usage: "get information on the nodes in the cluster", Action: getClusterNodes, }, cli.Command{ Name: "update", Aliases: []string{"u"}, Usage: "update the cluster settings via JSON", Description: "esu cluster update [PATH] -- Where PATH is a JSON document to update with. Alternatively, JSON can be piped into this command", Action: putClusterSettings, }, }, }, ) }
Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{1})) }) }) Describe("App.Before", func() { Context("when running the target command", func() { It("does not verify the current target", func() { cliConfig.SetTarget("my-lattice.example.com") Expect(cliConfig.Save()).To(Succeed()) commandRan := false cliApp.Commands = []cli.Command{ cli.Command{ Name: "target", Action: func(ctx *cli.Context) { commandRan = true }, }, } Expect(cliApp.Run([]string{"ltc", "target"})).To(Succeed()) Expect(commandRan).To(BeTrue()) Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(0)) }) }) Context("when running the help command", func() { It("does not verify the current target", func() { cliConfig.SetTarget("my-lattice.example.com") Expect(cliConfig.Save()).To(Succeed())
func BuildCommand(app *cli.App) { app.Commands = append(app.Commands, SubCommand()) }
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"}, }, }, { Name: "drop", Usage: "Give up ownership of a pull request assigned to you", Action: dropCmd, Flags: []cli.Flag{}, }, { 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"}, }, }, } }
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"}, }, }, } }
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"}, }, }, } }
Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{1})) }) }) Describe("App.Before", func() { Context("when running the target command", func() { It("does not verify the current target", func() { cliConfig.SetTarget("my-lattice.example.com") cliConfig.Save() commandRan := false cliApp.Commands = []cli.Command{ cli.Command{ Name: config_command_factory.TargetCommandName, Action: func(ctx *cli.Context) { commandRan = true }, }, } cliAppArgs := []string{"ltc", config_command_factory.TargetCommandName} err := cliApp.Run(cliAppArgs) Expect(err).ToNot(HaveOccurred()) Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(BeZero()) Expect(commandRan).To(BeTrue()) }) }) Context("when running the help command", func() {
func WrapApp(app *cli.App, wrappers ...CmdWrapper) { app.Commands = WrapAll(app.Commands, wrappers...) }
func SetAction(a *cli.App) { a.Commands = []cli.Command{ { Name: "auth", Usage: "authorize", Action: func(c *cli.Context) { _, raw, err := auth.Exec(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, Flags: []cli.Flag{ cli.StringFlag{ Name: "email, e", Value: "email", EnvVar: "SORACOM_EMAIL", }, cli.StringFlag{ Name: "password, p", Value: "password", EnvVar: "SORACOM_PASSWORD", }, cli.IntFlag{ Name: "token-timeout-seconds, t", Usage: "Timeout seconds of token", Value: 86400, }, }, }, { Name: "password-reset", Usage: "password reset", Subcommands: []cli.Command{ { Name: "issue", Usage: "get token of password reset from email", Flags: []cli.Flag{ cli.StringFlag{ Name: "email, e", Value: "email", EnvVar: "SORACOM_EMAIL", }, }, Action: func(c *cli.Context) { _, raw, err := auth.ExecPasswordResetTheIssue(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "verify", Usage: "verify token of password reset", Flags: []cli.Flag{ cli.StringFlag{ Name: "new-password, p", Value: "new-password", }, cli.StringFlag{ Name: "verify-token, t", Value: "verify-token", }, }, Action: func(c *cli.Context) { _, raw, err := auth.ExecPasswordResetTheVerify(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, }, }, { Name: "operator", Usage: "operator", Subcommands: []cli.Command{ { Name: "token", Usage: "Update token of operator", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.IntFlag{ Name: "token-timeout-seconds, timeout", Usage: "Timeout seconds of token (default 86400)", Value: 86400, }, cli.StringFlag{ Name: "operator-id, i", Value: "operator-id", Usage: "Set operator id", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecToken(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "password", Usage: "Update password", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.StringFlag{ Name: "operator-id, i", Value: "operator-id", Usage: "Set operator id", }, cli.StringFlag{ Name: "current-password, c", Value: "current-password", Usage: "current password for SORACOM", }, cli.StringFlag{ Name: "new-password, n", Value: "new-password", Usage: "new password for SORACOM", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecPassword(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "support_token", Usage: "get of token for support", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.StringFlag{ Name: "operator-id, i", Value: "operator-id", Usage: "Set operator id", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecSupportToken(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "invitation", Usage: "invitation new user", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.StringFlag{ Name: "email, e", Value: "email", Usage: "email for invitaiton", }, cli.StringFlag{ Name: "password, p", Value: "password", Usage: "password for invitation user", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecOperators(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "verify", Usage: "verify of invitation user", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.StringFlag{ Name: "verify-token", Value: "verify-token", Usage: "verify token for intivation user", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecVerify(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, { Name: "info", Usage: "get information of operator", Flags: []cli.Flag{ cli.StringFlag{ Name: "api-key, a", Value: "api-key", Usage: "api key for SORACOM", EnvVar: "SORACOM_API_KEY", }, cli.StringFlag{ Name: "token, t", Value: "token", Usage: "token for SORACOM", EnvVar: "SORACOM_TOKEN", }, cli.StringFlag{ Name: "operator-id, i", Value: "operator-id", Usage: "Set operator id", }, }, Action: func(c *cli.Context) { _, raw, err := operator.ExecOperatorInfo(c) if err != nil { log.Fatal(err) return } println(string(raw)) return }, }, }, }, } }
func main() { var app *cli.App app = cli.NewApp() app.Name = "awsutils" app.Usage = "automation of Amazon Web Services configurations through their API" app.EnableBashCompletion = true app.Commands = []cli.Command{ { Name: "iam", Usage: "use the AWS iam API", Subcommands: []cli.Command{ { Name: "certs", Usage: "summarise certificate configurations available in your AWS account", Action: func(c *cli.Context) { out, err := exec.Command("aws", "iam", "list-server-certificates").Output() if err != nil { fmt.Println(err.Error()) return } var r ListServerCertificatesResponse err = json.Unmarshal(out, &r) if err != nil { fmt.Println(err.Error()) return } w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0) fmt.Fprint(w, "ID\tName\tStatus\n") for _, cm := range r.ServerCertificateMetadataList { fmt.Fprintf(w, "%s\t%s\t%s\n", cm.ServerCertificateID, cm.ServerCertificateName, ResolveStatus(cm.Expiration)) } w.Flush() // fmt.Printf("%+v\n", r) }, }, }, }, { Name: "cloudfront", Aliases: []string{"cf"}, Usage: "use the AWS cloudfront API", Subcommands: []cli.Command{ { Name: "export-configs", Usage: "export the cloudfront distribution configurations", Action: func(c *cli.Context) { out, err := exec.Command("aws", "cloudfront", "list-distributions").Output() if err != nil { fmt.Println(err.Error()) return } var r CloudFrontListDistributionsResponse err = json.Unmarshal(out, &r) if err != nil { fmt.Println(err.Error()) return } w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0) fmt.Fprint(w, "DomainName\n") for _, d := range r.Distributionlist.Items { fmt.Fprintf(w, "%+v\n", d.Origins.Items[0]["DomainName"]) json, _ := json.MarshalIndent(d, "", " ") fn := fmt.Sprintf("%s.json", d.Origins.Items[0]["Id"]) f, err := os.Create(fn) if err != nil { cwd, _ := os.Getwd() fmt.Printf("Unable to create file '%s' in '%s'", fn, cwd) continue } f.Write(json) f.Close() } w.Flush() }, }, { Name: "dists", Usage: "summarize the cloudfront distribution configurations", Flags: []cli.Flag{ cli.StringFlag{ Name: "order-by", Value: "alias", Usage: "sort results on alias|origin|status", }, cli.BoolFlag{ Name: "csv", Usage: "output as csv", }, }, Action: func(c *cli.Context) { out, err := exec.Command("aws", "cloudfront", "list-distributions").Output() if err != nil { fmt.Println(err.Error()) return } var r CloudFrontListDistributionsResponse err = json.Unmarshal(out, &r) if err != nil { fmt.Println(err.Error()) return } var list []DistSummary for _, d := range r.Distributionlist.Items { id := d.ID distDomain := d.DomainName status := d.Status origin := "" alias := "" if len(d.Origins.Items) > 0 { for _, o := range d.Origins.Items { if op, ok := o["OriginPath"].(string); ok && op == "" { origin = o["DomainName"].(string) } } } if len(d.Aliases.Items) > 0 { alias = strings.Join(d.Aliases.Items, ",") } list = append(list, DistSummary{ID: id, Domain: distDomain, Alias: alias, Origin: origin, Status: status}) } switch c.String("order-by") { case "origin": sort.Sort(ByOrigin(list)) case "status": sort.Sort(ByStatus(list)) case "alias": sort.Sort(ByAlias(list)) default: fmt.Println("Unrecognised value for", c.String("order-by"), ". Sorting by alias instead.") sort.Sort(ByAlias(list)) } if c.Bool("csv") { fmt.Println("ID;Domain;Alias;Origin;Status") for _, s := range list { fmt.Printf(`"%s";"%s";"%s";"%s";"%s"`, s.ID, s.Domain, s.Alias, s.Origin, s.Status) fmt.Println() } } else { w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0) fmt.Fprint(w, "ID\tDomain\tAlias\tOrigin\tStatus\n") for _, s := range list { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", s.ID, s.Domain, s.Alias, s.Origin, s.Status) } w.Flush() } }, }, }, }, } app.Run(os.Args) }
func cmds(app *cli.App) { app.Commands = []cli.Command{ { Name: "clean", Usage: "Clean package cache", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "generate", Usage: "Generate package buildfiles", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "info", Usage: "Print package info", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "install", Usage: "Install packages", BashComplete: func(c *cli.Context) { flags := []string{ "--force", "--no-script", "--skip-checksum", } if len(c.Args()) > 0 { return } for _, f := range flags { fmt.Println(f) } }, Flags: []cli.Flag{ cli.BoolFlag{ Name: "force, f", Usage: "Force install", }, cli.BoolFlag{ Name: "no-script, n", Usage: "Do not run install script", }, cli.BoolFlag{ Name: "skip-checksum, s", Usage: "Skip checksum", }, }, Action: func(c *cli.Context) error { if len(c.Args()) > 0 { for i := 0; i < len(c.Args()); i++ { p := parcel.New(c.GlobalString("root")) p.Install(c.Args()[i], c) } } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "list", Usage: "List packages", Flags: []cli.Flag{ cli.BoolFlag{ Name: "all, a", Usage: "List all info", }, cli.BoolFlag{ Name: "checksum, c", Usage: "List installation status", }, cli.BoolFlag{ Name: "description, d", Usage: "List description", }, cli.BoolFlag{ Name: "status, s", Usage: "List installation status", }, }, Action: func(c *cli.Context) error { p := parcel.New(c.GlobalString("root")) p.List(c) return nil }, }, { Name: "make", Usage: "Make package from source", Action: func(c *cli.Context) error { p := parcel.New(c.GlobalString("root")) if _, err := os.Stat("Makefile"); err == nil { p.Make(c.Args()) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "pack", Usage: "Pack package tarball", Flags: []cli.Flag{ cli.BoolFlag{ Name: "test, t", Usage: "Test package. Do not update database.", }, }, Action: func(c *cli.Context) error { p := parcel.New(c.GlobalString("root")) if _, err := os.Stat("Makefile"); err == nil && len(c.Args()) == 2 { p.Pack(c) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "fetch", Usage: "Fetch package from server", Action: func(c *cli.Context) error { p := parcel.New(c.GlobalString("root")) if len(c.Args()) == 1 { p.Fetch(c.Args()[0], "/") } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "remove", Usage: "Remove packages", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "search", Usage: "Search for packages", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "show", Usage: "Show package files", Action: func(c *cli.Context) error { if len(c.Args()) == 1 { println(c.Args()[0]) } else { cli.ShowSubcommandHelp(c) } return nil }, }, { Name: "update", Usage: "Update package database", Action: func(c *cli.Context) error { config := cfg.Load("/etc/parcel/settings.ini") parcel.UpdateDatabase(c.GlobalString("root"), config) return nil }, }, } }
Expect(flagList).Should(ContainElement(t.Name)) case cli.BoolFlag: Expect(flagList).Should(ContainElement(t.Name)) case cli.DurationFlag: Expect(flagList).Should(ContainElement(t.Name)) } } }) It("does not append unexpected flag types", func() { cliApp = cli.NewApp() cliGenericFlag := cli.GenericFlag{Name: "capture-the-flag"} cliApp.Commands = []cli.Command{ cli.Command{ Name: "commander-keen", Flags: []cli.Flag{ cliGenericFlag, }, }, } flagList := main.GetCommandFlags(cliApp, "commander-keen") Expect(flagList).ToNot(ContainElement(cliGenericFlag.Name)) }) }) Describe("GetByCmdName", func() { It("returns command not found error", func() { _, err := main.GetByCmdName(cliApp, "zz") Expect(err).To(MatchError("Command not found")) })