本文整理汇总了Golang中github.com/codegangsta/cli.ShowCommandHelp函数的典型用法代码示例。如果您正苦于以下问题:Golang ShowCommandHelp函数的具体用法?Golang ShowCommandHelp怎么用?Golang ShowCommandHelp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShowCommandHelp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: loadPlugin
func loadPlugin(ctx *cli.Context) {
pAsc := ctx.String("plugin-asc")
var paths []string
if len(ctx.Args()) != 1 {
fmt.Println("Incorrect usage:")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
paths = append(paths, ctx.Args().First())
if pAsc != "" {
if !strings.Contains(pAsc, ".asc") {
fmt.Println("Must be a .asc file for the -a flag")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
paths = append(paths, pAsc)
}
r := pClient.LoadPlugin(paths)
if r.Err != nil {
if r.Err.Fields()["error"] != nil {
fmt.Printf("Error loading plugin:\n%v\n%v\n", r.Err.Error(), r.Err.Fields()["error"])
} else {
fmt.Printf("Error loading plugin:\n%v\n", r.Err.Error())
}
os.Exit(1)
}
for _, p := range r.LoadedPlugins {
fmt.Println("Plugin loaded")
fmt.Printf("Name: %s\n", p.Name)
fmt.Printf("Version: %d\n", p.Version)
fmt.Printf("Type: %s\n", p.Type)
fmt.Printf("Signed: %v\n", p.Signed)
fmt.Printf("Loaded Time: %s\n\n", p.LoadedTime().Format(timeFormat))
}
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:35,代码来源:plugin.go
示例2: cmdServer
func cmdServer(ctx *cli.Context) {
c, err := config.GetConfiguration(ctx)
if err != nil {
cli.ShowCommandHelp(ctx, "server")
fmt.Println("Could not get configuration. Reason:", err)
log.Fatalln("Exiting....")
}
if ctx.String("port") == "" {
cli.ShowCommandHelp(ctx, "server")
fmt.Println("Missing port")
log.Fatalln("Exiting....")
}
executor := execution.NewExecutor(c.AggregateOutput, c.FailuresOnly, c.StateChangeOnly, c.ResultFormatter(), c.Writer(), c.Workers)
asrt := NewAsrtHandler(c, executor)
asrt.refreshServerCache()
go asrt.loopServerCacheRefresh()
http.Handle("/data", asrt)
http.HandleFunc("/", serveStaticWebFiles)
fmt.Println("Listening on port:", ctx.String("port"))
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", ctx.String("port")), nil))
}
开发者ID:mkboudreau,项目名称:asrt,代码行数:26,代码来源:server.go
示例3: cliDeleteRevNat
func cliDeleteRevNat(ctx *cli.Context) {
if ctx.Bool("all") {
if err := client.RevNATDeleteAll(); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}
} else {
if len(ctx.Args()) == 0 {
cli.ShowCommandHelp(ctx, "delete-rev-nat")
os.Exit(1)
}
id, err := strconv.ParseUint(ctx.Args().Get(0), 10, 16)
if err != nil {
cli.ShowCommandHelp(ctx, "delete-rev-nat")
os.Exit(1)
}
if err := client.RevNATDelete(types.ServiceID(id)); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
fmt.Printf("Successfully deleted\n")
}
开发者ID:cilium-team,项目名称:cilium,代码行数:25,代码来源:main.go
示例4: oci2docker
func oci2docker(c *cli.Context) {
ociPath := c.String("oci-bundle")
imgName := c.String("image-name")
port := c.String("port")
if ociPath == "" {
cli.ShowCommandHelp(c, "convert")
return
}
if imgName == "" {
cli.ShowCommandHelp(c, "convert")
return
}
_, err := os.Stat(ociPath)
if os.IsNotExist(err) {
cli.ShowCommandHelp(c, "convert")
return
}
convert.RunOCI2Docker(ociPath, imgName, port)
return
}
开发者ID:ChengTiesheng,项目名称:oci2docker,代码行数:25,代码来源:main.go
示例5: cmdSetAdmin
func cmdSetAdmin(c *cli.Context) error {
s, err := openAndCheck(c)
if err != nil {
return cli.NewExitError(err.Error(), 3)
}
username := c.Args().First()
if username == "" {
cli.ShowCommandHelp(c, "set-admin")
return cli.NewExitError("", 0)
}
isAdmin, err := strconv.ParseBool(c.Args().Get(1))
if err != nil {
cli.ShowCommandHelp(c, "set-admin")
return cli.NewExitError("", 0)
}
if err := s.GetInterface().SetAdmin(username, isAdmin); err != nil {
return cli.NewExitError(fmt.Sprintf("Error changing admin status of user '%s': %s", username, err), 3)
}
if isAdmin {
return cli.NewExitError(fmt.Sprintf("user '%s' is now an admin!", username), 0)
} else {
return cli.NewExitError(fmt.Sprintf("user '%s' is now a normal user!", username), 0)
}
}
开发者ID:whawty,项目名称:auth,代码行数:28,代码来源:main.go
示例6: getClientCredentials
func getClientCredentials(c *cli.Context) []string {
credentials := []string{c.GlobalString("client-id"), c.GlobalString("client-secret")}
if credentials[0] == "" || credentials[1] == "" {
color.Yellow("No client credentials given. Fallback to builtin default...")
color.Yellow("Keep in mind that your document might be visible to other users.")
color.Yellow("Your unique user-id is the only secret to protect your data.\n\n")
superSecretSecret := []byte("V;4nJvuANmoywKNYk.yewNhqwmAQctc3BvByxeozQVpiK")
// Decode HEX default credentials
credentialsBytes, err := hex.DecodeString(defaultClientCredentials)
if err != nil {
color.Red("Error: client-id and client-secret missing and fallback decoding (step 1) failed: %s\n\n", err)
cli.ShowCommandHelp(c, c.Command.FullName())
os.Exit(1)
}
decodedCredentials := strings.Split(string(xorBytes(credentialsBytes, superSecretSecret)), ":")
if len(decodedCredentials) < 2 {
color.Red("Error: client-id and client-secret missing and fallback decoding (step 2) failed: %s\n\n", err)
cli.ShowCommandHelp(c, c.Command.FullName())
os.Exit(1)
}
credentials = decodedCredentials
}
return credentials
}
开发者ID:gini,项目名称:gapicmd,代码行数:30,代码来源:utils.go
示例7: unloadPlugin
func unloadPlugin(ctx *cli.Context) {
pType := ctx.String("plugin-type")
pName := ctx.String("plugin-name")
pVer := ctx.Int("plugin-version")
if pName == "" {
fmt.Println("Must provide plugin name")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
if pVer < 1 {
fmt.Println("Must provide plugin version")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
r := pClient.UnloadPlugin(pType, pName, pVer)
if r.Err != nil {
fmt.Printf("Error unloading plugin:\n%v\n", r.Err.Error())
os.Exit(1)
}
fmt.Println("Plugin unloaded")
fmt.Printf("Name: %s\n", r.Name)
fmt.Printf("Version: %d\n", r.Version)
fmt.Printf("Type: %s\n", r.Type)
}
开发者ID:gitter-badger,项目名称:snap-1,代码行数:26,代码来源:plugin.go
示例8: getConfig
func getConfig(ctx *cli.Context) {
pDetails := filepath.SplitList(ctx.Args().First())
var ptyp string
var pname string
var pver int
var err error
if len(pDetails) == 3 {
ptyp = pDetails[0]
pname = pDetails[1]
pver, err = strconv.Atoi(pDetails[2])
if err != nil {
fmt.Println("Can't convert version string to integer")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
} else {
ptyp = ctx.String("plugin-type")
pname = ctx.String("plugin-name")
pver = ctx.Int("plugin-version")
}
if ptyp == "" {
fmt.Println("Must provide plugin type")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
if pname == "" {
fmt.Println("Must provide plugin name")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
if pver < 1 {
fmt.Println("Must provide plugin version")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
os.Exit(1)
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
defer w.Flush()
printFields(w, false, 0,
"NAME",
"VALUE",
"TYPE",
)
r := pClient.GetPluginConfig(ptyp, pname, strconv.Itoa(pver))
for k, v := range r.Table() {
switch t := v.(type) {
case ctypes.ConfigValueInt:
printFields(w, false, 0, k, t.Value, t.Type())
case ctypes.ConfigValueBool:
printFields(w, false, 0, k, t.Value, t.Type())
case ctypes.ConfigValueFloat:
printFields(w, false, 0, k, t.Value, t.Type())
case ctypes.ConfigValueStr:
printFields(w, false, 0, k, t.Value, t.Type())
}
}
}
开发者ID:jeffweiss,项目名称:snap,代码行数:58,代码来源:config.go
示例9: uploadDocument
func uploadDocument(c *cli.Context) {
filename := c.String("filename")
doctype := c.String("doctype")
userid := getUserIdentifier(c)
if len(c.Args()) < 1 {
cli.ShowCommandHelp(c, c.Command.FullName())
return
}
if _, err := os.Stat(c.Args().First()); os.IsNotExist(err) {
color.Red("\nError: cannot find %s\n\n", c.Args().First())
cli.ShowCommandHelp(c, c.Command.FullName())
return
}
bodyBuf, err := os.Open(c.Args().First())
if err != nil {
color.Red("\nError: failed to read %s\n\n", c.Args().First())
cli.ShowCommandHelp(c, c.Command.FullName())
return
}
api := getApiClient(c)
doc, err := api.Upload(bodyBuf, giniapi.UploadOptions{
FileName: filename,
DocType: doctype,
UserIdentifier: userid,
})
if err != nil {
color.Red("\nError: %s\n\n", err)
return
}
done <- true
wg.Wait()
renderResults(doc)
if c.GlobalBool("curl") {
curl := curlData{
Headers: map[string]string{
"Accept": "application/vnd.gini.v1+json",
"X-User-Identifier": userid,
},
Body: fmt.Sprintf("--data-binary '@%s'", c.Args().First()),
URL: fmt.Sprintf("%s/documents", api.Endpoints.API),
Method: "POST",
}
curl.render(c)
}
}
开发者ID:gini,项目名称:gapicmd,代码行数:55,代码来源:gini.go
示例10: doUpdate
func doUpdate(c *cli.Context) {
conffile := c.GlobalString("conf")
argHostIDs := c.Args()
optName := c.String("name")
optStatus := c.String("status")
optRoleFullnames := c.StringSlice("roleFullname")
if len(argHostIDs) < 1 {
argHostIDs = make([]string, 1)
if argHostIDs[0] = LoadHostIDFromConfig(conffile); argHostIDs[0] == "" {
cli.ShowCommandHelp(c, "update")
os.Exit(1)
}
}
needUpdateHostStatus := optStatus != ""
needUpdateHost := (optName != "" || len(optRoleFullnames) > 0)
if !needUpdateHostStatus && !needUpdateHost {
cli.ShowCommandHelp(c, "update")
os.Exit(1)
}
client := newMackerel(conffile)
var wg sync.WaitGroup
for _, hostID := range argHostIDs {
wg.Add(1)
go func(hostID string) {
defer wg.Done()
if needUpdateHostStatus {
err := client.UpdateHostStatus(hostID, optStatus)
logger.DieIf(err)
}
if needUpdateHost {
_, err := client.UpdateHost(hostID, &mkr.UpdateHostParam{
Name: optName,
RoleFullnames: optRoleFullnames,
})
logger.DieIf(err)
}
logger.Log("updated", hostID)
}(hostID)
}
wg.Wait()
}
开发者ID:syohex,项目名称:mkr,代码行数:50,代码来源:commands.go
示例11: unloadPlugin
func unloadPlugin(ctx *cli.Context) error {
pDetails := filepath.SplitList(ctx.Args().First())
var pType, pName string
var pVer int
var err error
if len(pDetails) == 3 {
pType = pDetails[0]
pName = pDetails[1]
pVer, err = strconv.Atoi(pDetails[2])
if err != nil {
fmt.Println("Can't convert version string to integer")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
return errCritical
}
} else {
pType = ctx.String("plugin-type")
pName = ctx.String("plugin-name")
pVer = ctx.Int("plugin-version")
}
if pType == "" {
fmt.Println("Must provide plugin type")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
return errCritical
}
if pName == "" {
fmt.Println("Must provide plugin name")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
return errCritical
}
if pVer < 1 {
fmt.Println("Must provide plugin version")
cli.ShowCommandHelp(ctx, ctx.Command.Name)
return errCritical
}
r := pClient.UnloadPlugin(pType, pName, pVer)
if r.Err != nil {
fmt.Printf("Error unloading plugin:\n%v\n", r.Err.Error())
return errCritical
}
fmt.Println("Plugin unloaded")
fmt.Printf("Name: %s\n", r.Name)
fmt.Printf("Version: %d\n", r.Version)
fmt.Printf("Type: %s\n", r.Type)
return nil
}
开发者ID:Collinux,项目名称:snap,代码行数:49,代码来源:plugin.go
示例12: main
func main() {
app := cli.NewApp()
app.Name = "spiff"
app.Usage = "BOSH deployment manifest toolkit"
app.Version = "1.0.8dev"
app.Commands = []cli.Command{
{
Name: "merge",
ShortName: "m",
Usage: "merge stub files into a manifest template",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "print state info",
},
},
Action: func(c *cli.Context) {
if len(c.Args()) < 1 {
cli.ShowCommandHelp(c, "merge")
os.Exit(1)
}
debug.DebugFlag = c.Bool("debug")
merge(c.Args()[0], c.Args()[1:])
},
},
{
Name: "diff",
ShortName: "d",
Usage: "structurally compare two YAML files",
Flags: []cli.Flag{
cli.StringFlag{
Name: "separator",
Usage: "separator to print between diffs",
},
},
Action: func(c *cli.Context) {
if len(c.Args()) < 2 {
cli.ShowCommandHelp(c, "diff")
os.Exit(1)
}
diff(c.Args()[0], c.Args()[1], c.String("separator"))
},
},
}
app.Run(os.Args)
}
开发者ID:gstackio,项目名称:spiff,代码行数:49,代码来源:spiff.go
示例13: FailWithUsage
func (c *terminalUI) FailWithUsage(context *cli.Context) {
c.Say(FailureColor(T("FAILED")))
c.Say(T("Incorrect Usage.\n"))
cli.ShowCommandHelp(context, context.Command.Name)
c.Say("")
os.Exit(1)
}
开发者ID:raghulsid,项目名称:cli,代码行数:7,代码来源:ui.go
示例14: doGet
func doGet(c *cli.Context) {
argURL := c.Args().Get(0)
doUpdate := c.Bool("update")
if argURL == "" {
cli.ShowCommandHelp(c, "get")
os.Exit(1)
}
url, err := url.Parse(argURL)
utils.DieIf(err)
if !url.IsAbs() {
url.Scheme = "https"
url.Host = "github.com"
if url.Path[0] != '/' {
url.Path = "/" + url.Path
}
}
remote, err := NewRemoteRepository(url)
utils.DieIf(err)
if remote.IsValid() == false {
utils.Log("error", fmt.Sprintf("Not a valid repository: %s", url))
os.Exit(1)
}
getRemoteRepository(remote, doUpdate)
}
开发者ID:kentaro,项目名称:ghq,代码行数:30,代码来源:commands.go
示例15: cmdSquash
func (c *ServicedCli) cmdSquash(ctx *cli.Context) {
imageName := ""
baseLayer := ""
newName := ""
args := ctx.Args()
switch len(ctx.Args()) {
case 3:
newName = args[2]
fallthrough
case 2:
baseLayer = args[1]
fallthrough
case 1:
imageName = args[0]
break
default:
cli.ShowCommandHelp(ctx, "squash")
return
}
imageID, err := c.driver.Squash(imageName, baseLayer, newName, ctx.String("tempdir"))
if err != nil {
glog.Fatalf("error squashing: %s", err)
}
fmt.Println(imageID)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:27,代码来源:docker.go
示例16: cmdScp
func cmdScp(c *cli.Context) {
args := c.Args()
if len(args) != 2 {
cli.ShowCommandHelp(c, "scp")
log.Fatal("Improper number of arguments.")
}
// TODO: Check that "-3" flag is available in user's version of scp.
// It is on every system I've checked, but the manual mentioned it's "newer"
sshArgs := append(baseSSHArgs, "-3")
if c.Bool("recursive") {
sshArgs = append(sshArgs, "-r")
}
src := args[0]
dest := args[1]
store := getStore(c)
cmd, err := getScpCmd(src, dest, sshArgs, store)
if err != nil {
log.Fatal(err)
}
if err := runCmdWithStdIo(*cmd); err != nil {
log.Fatal(err)
}
}
开发者ID:rominirani,项目名称:machine,代码行数:28,代码来源:scp.go
示例17: doGet
func doGet(c *cli.Context) {
argURL := c.Args().Get(0)
branch := c.String("branch")
doUpdate := c.Bool("update")
isShallow := c.Bool("shallow")
isRecursive := c.Bool("recursive")
if argURL == "" {
cli.ShowCommandHelp(c, "get")
os.Exit(1)
}
if isShallow && isRecursive {
utils.Log("error", "Cannot specify both --shallow and --recursive options")
os.Exit(1)
}
// If argURL is a "./foo" or "../bar" form,
// find repository name trailing after github.com/USER/.
parts := strings.Split(argURL, string(filepath.Separator))
if parts[0] == "." || parts[0] == ".." {
if wd, err := os.Getwd(); err == nil {
path := filepath.Clean(filepath.Join(wd, filepath.Join(parts...)))
var repoPath string
for _, r := range localRepositoryRoots() {
p := strings.TrimPrefix(path, r+string(filepath.Separator))
if p != path && (repoPath == "" || len(p) < len(repoPath)) {
repoPath = p
}
}
if repoPath != "" {
// Guess it
utils.Log("resolved", fmt.Sprintf("relative %q to %q", argURL, "https://"+repoPath))
argURL = "https://" + repoPath
}
}
}
url, err := NewURL(argURL)
utils.DieIf(err)
isSSH := c.Bool("p")
if isSSH {
// Assume Git repository if `-p` is given.
url, err = ConvertGitURLHTTPToSSH(url)
utils.DieIf(err)
}
remote, err := NewRemoteRepository(url)
utils.DieIf(err)
if remote.IsValid() == false {
utils.Log("error", fmt.Sprintf("Not a valid repository: %s", url))
os.Exit(1)
}
getRemoteRepository(remote, branch, doUpdate, isShallow, isRecursive)
}
开发者ID:mkanai,项目名称:ghq,代码行数:60,代码来源:commands.go
示例18: cmdInit
func cmdInit(c *cli.Context) error {
username := c.Args().First()
if username == "" {
cli.ShowCommandHelp(c, "init")
return cli.NewExitError("", 0)
}
password := c.Args().Get(1)
if password == "" {
pwd, err := askPass()
if err != nil {
if err != gopass.ErrInterrupted {
return cli.NewExitError(err.Error(), 2)
}
return cli.NewExitError("", 2)
}
password = pwd
}
s, err := NewStore(c.GlobalString("store"), c.GlobalString("do-upgrades"),
c.GlobalString("policy-type"), c.GlobalString("policy-condition"), c.GlobalString("hooks-dir"))
if err != nil {
return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
}
if err := s.GetInterface().Init(username, password); err != nil {
return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
}
return cli.NewExitError(fmt.Sprintf("whawty store successfully initialized!"), 0)
}
开发者ID:whawty,项目名称:auth,代码行数:29,代码来源:main.go
示例19: removeImages
// remove untagged images
func removeImages(c *cli.Context) {
dry := c.Bool("dry")
untagged := c.Bool("untagged")
if !untagged {
cli.ShowCommandHelp(c, "rmi")
fmt.Println("EXAMPLE:")
fmt.Println(" command rmi --untagged")
return
}
ctx := getUtilContext()
if ctx == nil {
return
}
ctx = getUtilContext()
if ctx == nil {
return
}
if untagged == true {
ctx.RemoveUntaggedDockerImages(dry)
}
return
}
开发者ID:phoenix-io,项目名称:docker-utils,代码行数:27,代码来源:main.go
示例20: showError
func showError(ctx *cli.Context, err error) {
fmt.Fprintf(ctx.App.Writer, "ERROR: %s\n\n", err.Error())
fmt.Println(errors.Wrap(err, 0).ErrorStack())
cli.ShowCommandHelp(ctx, ctx.Command.Name)
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:7,代码来源:common.go
注:本文中的github.com/codegangsta/cli.ShowCommandHelp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论