1 Star 0 Fork 0

bolo-tourism/go

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
help.go 1.50 KB
Copy Edit Raw Blame History
kevin authored 2023-05-08 14:34 +08:00 . 初始化
// Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package app
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
const (
flagHelp = "help"
flagHelpShorthand = "H"
)
func helpCommand(name string) *cobra.Command {
return &cobra.Command{
Use: "help [command]",
Short: "Help about any command.",
Long: `Help provides help for any command in the application.
Simply type ` + name + ` help [path to command] for full details.`,
Run: func(c *cobra.Command, args []string) {
cmd, _, e := c.Root().Find(args)
if cmd == nil || e != nil {
c.Printf("Unknown help topic %#q\n", args)
_ = c.Root().Usage()
} else {
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
_ = cmd.Help()
}
},
}
}
// addHelpFlag adds flags for a specific application to the specified FlagSet
// object.
func addHelpFlag(name string, fs *pflag.FlagSet) {
fs.BoolP(flagHelp, flagHelpShorthand, false, fmt.Sprintf("Help for %s.", name))
}
// addHelpCommandFlag adds flags for a specific command of application to the
// specified FlagSet object.
func addHelpCommandFlag(usage string, fs *pflag.FlagSet) {
fs.BoolP(
flagHelp,
flagHelpShorthand,
false,
fmt.Sprintf("Help for the %s command.", color.GreenString(strings.Split(usage, " ")[0])),
)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bolo-tourism/go.git
git@gitee.com:bolo-tourism/go.git
bolo-tourism
go
go
772bc38bfa1d

Search