3 Star 3 Fork 2

Gitee 极速下载/kingpin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/alecthomas/kingpin
克隆/下载
global.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Alec Thomas 提交于 2014-10-16 16:19 . A proper fix for EOL messages.
package kingpin
import (
"os"
"path/filepath"
)
var (
// CommandLine is the default Kingpin parser.
CommandLine = New(filepath.Base(os.Args[0]), "")
)
// Command adds a new command to the default parser.
func Command(name, help string) *CmdClause {
return CommandLine.Command(name, help)
}
// Flag adds a new flag to the default parser.
func Flag(name, help string) *FlagClause {
return CommandLine.Flag(name, help)
}
// Arg adds a new argument to the top-level of the default parser.
func Arg(name, help string) *ArgClause {
return CommandLine.Arg(name, help)
}
// Parse and return the selected command. Will exit with a non-zero status if
// an error was encountered.
func Parse() string {
selected := MustParse(CommandLine.Parse(os.Args[1:]))
if selected == "" && CommandLine.cmdGroup.have() {
Usage()
os.Exit(0)
}
return selected
}
// Fatalf prints an error message to stderr and exits.
func Fatalf(format string, args ...interface{}) {
CommandLine.Fatalf(os.Stderr, format, args...)
}
// FatalIfError prints an error and exits if err is not nil. The error is printed
// with the given prefix.
func FatalIfError(err error, prefix string) {
CommandLine.FatalIfError(os.Stderr, err, prefix)
}
// UsageErrorf prints an error message followed by usage information, then
// exits with a non-zero status.
func UsageErrorf(format string, args ...interface{}) {
CommandLine.UsageErrorf(os.Stderr, format, args...)
}
// Usage prints usage to stderr.
func Usage() {
CommandLine.Usage(os.Stderr)
}
// MustParse can be used with app.Parse(args) to exit with an error if parsing fails.
func MustParse(command string, err error) string {
if err != nil {
Fatalf("%s, try --help", err)
}
return command
}
// Version adds a flag for displaying the application version number.
func Version(version string) {
CommandLine.Version(version)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/kingpin.git
git@gitee.com:mirrors/kingpin.git
mirrors
kingpin
kingpin
v1.3.3

搜索帮助

0d507c66 1850385 C8b1a773 1850385