本文整理汇总了Golang中github.com/codegangsta/cli.ShowSubcommandHelp函数的典型用法代码示例。如果您正苦于以下问题:Golang ShowSubcommandHelp函数的具体用法?Golang ShowSubcommandHelp怎么用?Golang ShowSubcommandHelp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShowSubcommandHelp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkArgs
func checkArgs(c *cli.Context) {
if len(c.Args()) == 0 {
fmt.Println("You must provide at least one package name")
cli.ShowSubcommandHelp(c)
os.Exit(2)
}
}
示例2: slackMethod
func slackMethod() cli.Command {
return cli.Command{
Name: "run",
Usage: "[method]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "token",
Usage: "Your Slack API token",
EnvVar: "SLACK_TOKEN",
},
},
Description: "Hits the SlackAPI using the format: https://slack.com/api/{method}",
Action: func(ctx *cli.Context) {
if len(ctx.Args()) == 0 {
cli.ShowSubcommandHelp(ctx)
return
}
method := ctx.Args()[0]
token := ctx.String("token")
client := slacker.NewAPIClient(token, "")
b, err := client.RunMethod(method)
if err != nil {
fmt.Printf("Error running method: %s", err.Error())
return
}
fmt.Println(string(b))
},
}
}
示例3: eventCommand
func eventCommand() cli.Command {
eventFlag := cli.StringFlag{
Name: "event.name",
Usage: "event name",
}
return cli.Command{
Name: "event",
Aliases: []string{"e"},
Usage: "event related actions",
Action: func(c *cli.Context) {
cli.ShowSubcommandHelp(c)
os.Exit(1)
},
Subcommands: []cli.Command{
cli.Command{
Name: "list",
Aliases: []string{"l"},
Usage: "list latest events an agent has seen",
Flags: append([]cli.Flag{eventFlag}, queryOptionFlags()...),
Action: func(c *cli.Context) {
cc := consulClient(c)
name := c.String(eventFlag.Name)
events, _, err := cc.Event().List(name, queryOptions(c))
if err != nil {
log.Fatalf("failed to fetch agent events: %v", err)
}
prettyPrint(events)
},
},
},
}
}
示例4: createBundle
func createBundle(c *cli.Context) {
if !c.Args().Present() {
cli.ShowSubcommandHelp(c)
log.Fatalf("Usage: %v name (common name defaults to name, use --cn and "+
"different name if you need multiple certs for same cn)", c.Command.FullName())
}
commonName := strings.Join(c.Args()[:], " ")
var filename string
if filename = c.String("filename"); len(filename) == 0 {
filename = strings.Replace(commonName, " ", "_", -1)
filename = strings.Replace(filename, "*", "wildcard", -1)
}
subject := pkix.Name{CommonName: commonName}
if str := c.String("organization"); len(str) > 0 {
subject.Organization = []string{str}
}
if str := c.String("locality"); len(str) > 0 {
subject.Locality = []string{str}
}
if str := c.String("country"); len(str) > 0 {
subject.Country = []string{str}
}
if str := c.String("province"); len(str) > 0 {
subject.Province = []string{str}
}
if str := c.String("organizational-unit"); len(str) > 0 {
subject.OrganizationalUnit = []string{str}
}
template := &x509.Certificate{
Subject: subject,
NotAfter: time.Now().AddDate(0, 0, c.Int("expire")),
}
if c.Bool("ca") {
template.IsCA = true
filename = "ca"
} else if c.Bool("client") {
template.ExtKeyUsage = append(template.ExtKeyUsage, x509.ExtKeyUsageClientAuth)
template.EmailAddresses = c.StringSlice("email")
} else {
// We default to server
template.ExtKeyUsage = append(template.ExtKeyUsage, x509.ExtKeyUsageServerAuth)
IPs := make([]net.IP, 0, len(c.StringSlice("ip")))
for _, ipStr := range c.StringSlice("ip") {
if i := net.ParseIP(ipStr); i != nil {
IPs = append(IPs, i)
}
}
template.IPAddresses = IPs
template.DNSNames = c.StringSlice("dns")
}
err := easypki.GenerateCertifcate(c.GlobalString("root"), filename, template)
if err != nil {
log.Fatal(err)
}
}
示例5: cmdScriptRun
// cmdScriptRun serviced script run filename
func (c *ServicedCli) cmdScriptRun(ctx *cli.Context) {
args := ctx.Args()
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "Incorrect Usage.\n\n")
if !ctx.Bool("help") {
fmt.Fprintf(os.Stderr, "Incorrect Usage.\n\n")
}
cli.ShowSubcommandHelp(ctx)
return
}
var svc *service.Service
if svcID := ctx.String("service"); svcID != "" {
//verify service or translate to ID
var err error
svc, err = c.searchForService(svcID)
if err != nil {
fmt.Fprintln(os.Stderr, err)
c.exit(1)
return
}
if svc == nil {
fmt.Fprintf(os.Stderr, "service %s not found\n", svcID)
c.exit(1)
return
}
}
fileName := args[0]
config := &script.Config{}
if svc != nil {
config.ServiceID = svc.ID
}
// exec unix script command to log output
if isWithin := os.Getenv("IS_WITHIN_UNIX_SCRIPT"); isWithin != "TRUE" {
os.Setenv("IS_WITHIN_UNIX_SCRIPT", "TRUE") // prevent inception problem
// DO NOT EXIT ON ANY ERRORS - continue without logging
logdir := utils.ServicedLogDir()
if userrec, err := user.Current(); err != nil {
fmt.Fprintf(os.Stderr, "Unable to retrieve userid to log output: %s", err)
} else {
logfile := time.Now().Format(fmt.Sprintf("%s/script-2006-01-02-150405-%s.log", logdir, userrec.Username))
// unix exec ourselves
cmd := []string{"/usr/bin/script", "--append", "--return", "--flush",
"-c", strings.Join(os.Args, " "), logfile}
fmt.Fprintf(os.Stderr, "Logging to logfile: %s\n", logfile)
glog.V(1).Infof("syscall.exec unix script with command: %+v", cmd)
if err := syscall.Exec(cmd[0], cmd[0:], os.Environ()); err != nil {
fmt.Fprintf(os.Stderr, "Unable to log output with command:%+v err:%s\n", cmd, err)
}
}
}
glog.V(1).Infof("runScript filename:%s %+v\n", fileName, config)
runScript(c, ctx, fileName, config)
}
示例6: secretAdd
func secretAdd(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := parseRepo(repo)
if err != nil {
return err
}
tail := c.Args().Tail()
if len(tail) != 2 {
cli.ShowSubcommandHelp(c)
return nil
}
secret := &model.Secret{}
secret.Name = tail[0]
secret.Value = tail[1]
secret.Images = c.StringSlice("image")
secret.Events = c.StringSlice("event")
if len(secret.Images) == 0 {
return fmt.Errorf("Please specify the --image parameter")
}
client, err := newClient(c)
if err != nil {
return err
}
return client.SecretPost(owner, name, secret)
}
示例7: createPastie
// Create a pastie.
func createPastie(c *cli.Context) {
fn := strings.TrimSpace(c.Args().First())
if fn == "" {
cli.ShowSubcommandHelp(c)
return
}
content, err := ioutil.ReadFile(fn)
if err != nil {
fmt.Printf("Can't read '%s'\n", fn)
return
}
pastie, resp, _ := pst.Create(string(content), c.String("lang"), c.Bool("restricted"))
if resp.StatusCode != http.StatusOK {
fmt.Println(resp.Status)
}
shortURL, err := isgd.Short(pastie)
if err != nil {
panic(err)
}
fmt.Printf("File: %s\nPastie URL: %s\nShort URL: %s\n",
fn, pastie, shortURL)
}
示例8: echo_command
func echo_command(cfg *watch.Config, action func(*watch.Config)) cli.Command {
return cli.Command{
Name: "echo",
Usage: "echo the full filepath",
ArgsUsage: "DIR",
Action: func(c *cli.Context) {
args := c.Args()
bail := func() {
cli.ShowSubcommandHelp(c)
os.Exit(1)
}
if !args.Present() {
bail()
}
cfg.Actions = []watch.Action{
&watch.EchoAction{},
}
cfg.Dir = args.First()
action(cfg)
},
}
}
示例9: zoneInfo
func zoneInfo(c *cli.Context) {
if err := checkEnv(); err != nil {
fmt.Println(err)
return
}
var zone string
if len(c.Args()) > 0 {
zone = c.Args()[0]
} else if c.String("zone") != "" {
zone = c.String("zone")
} else {
cli.ShowSubcommandHelp(c)
return
}
zones, err := api.ListZones(zone)
if err != nil {
fmt.Println(err)
return
}
var output []table
for _, z := range zones {
output = append(output, table{
"ID": z.ID,
"Zone": z.Name,
"Plan": z.Plan.LegacyID,
"Status": z.Status,
"Name Servers": strings.Join(z.NameServers, ", "),
"Paused": fmt.Sprintf("%t", z.Paused),
"Type": z.Type,
})
}
makeTable(output, "ID", "Zone", "Plan", "Status", "Name Servers", "Paused", "Type")
}
示例10: cloud_list
func cloud_list(c *cli.Context) {
args := c.Args()
L := len(args)
if L != 0 {
fmt.Println("Error: bad args to 'cloud list'")
cli.ShowSubcommandHelp(c)
return
}
appname := APPCFG.Name
// get a directory listing
finfos, err := ioutil.ReadDir(APPCFG.SourcePath + "/clouds")
if err != nil {
fmt.Println("while reading clouds directory: ", err)
}
fmt.Printf("\n%-16s %-15s %-12s %s\n", "Name", "Host", "Status", "Master:Worker counts")
for _, fi := range finfos {
if fi.IsDir() {
continue
}
cloudname := strings.Replace(fi.Name(), ".yaml", "", -1)
cloudcfg, err := readCloudConfig(appname, cloudname)
if err != nil {
fmt.Println("while reading cloud config: ", err)
}
fmt.Printf("%-16s %-15s %-12s %d:%d\n", cloudcfg.Name, cloudcfg.URI, cloudcfg.Status, cloudcfg.NumMaster, cloudcfg.NumWorker)
}
}
示例11: cloud_status
func cloud_status(c *cli.Context) {
args := c.Args()
L := len(args)
if L != 1 {
fmt.Println("Error: bad args to 'cloud status <cloudname>'")
cli.ShowSubcommandHelp(c)
return
}
appname := APPCFG.Name
cloudname := args[0]
cloudcfg, err := readCloudConfig(appname, cloudname)
if err != nil {
fmt.Println("while reading cloud config: ", err)
return
}
// print status known in the config file
fmt.Printf("\n%-16s %-15s %-12s %s\n", "Name", "Host", "Status", "Master:Worker counts")
fmt.Printf("%-16s %-15s %-12s %d:%d\n\n", cloudcfg.Name, cloudcfg.URI, cloudcfg.Status, cloudcfg.NumMaster, cloudcfg.NumWorker)
// print status from mesos
providers.CloudStatus(cloudcfg)
// print status for the app
// print status from mesosphere ? or is the service status
}
示例12: secretAdd
func secretAdd(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := parseRepo(repo)
if err != nil {
return err
}
tail := c.Args().Tail()
if len(tail) != 2 {
cli.ShowSubcommandHelp(c)
return nil
}
secret, err := secretParseCmd(tail[0], tail[1], c)
if err != nil {
return err
}
client, err := newClient(c)
if err != nil {
return err
}
return client.SecretPost(owner, name, secret)
}
示例13: checkArgCount
func checkArgCount(c *cli.Context, num int) error {
args := c.Args()
if len(args) < num {
if c.App != nil { // may be nill during tests, can cause panic
cli.ShowSubcommandHelp(c)
}
return fmt.Errorf("Insufficient arguments: expected %d, provided %d", num, len(args))
}
if len(args) > num {
if c.App != nil { // may be nill during tests, can cause panic
cli.ShowSubcommandHelp(c)
}
return fmt.Errorf("Unknown arguments: %v", args[num:])
}
return nil
}
示例14: nodeName
func nodeName(c *cli.Context) string {
name := c.String(nodeFlag.Name)
if name == "" {
cli.ShowSubcommandHelp(c)
log.Fatal("node is required")
}
return name
}
示例15: db_import
func db_import(c *cli.Context) {
if len(c.Args()) != 0 {
fmt.Println("Error: bad args to 'db import' !!!")
cli.ShowSubcommandHelp(c)
return
}
fmt.Println("Not implemented yet...")
}