本文整理匯總了Golang中github.com/ogier/pflag.NewFlagSet函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFlagSet函數的具體用法?Golang NewFlagSet怎麽用?Golang NewFlagSet使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFlagSet函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
id_message := versionString() + "\n\nUsage: c4 [mode] [flags] [files]\n\n" +
"# `id` mode \n\n" +
" c4 generates c4ids for all files and folders spacified.\n" +
" If no file is given c4 will read piped data.\n" +
" Output is in YAML format.\n\n" +
" flags:\n"
cp_message := "\n\n" +
"# `cp` mode (not yet implemented)\n\n" +
" cp mode acts as a drop in replacement for the unix cp command.\n" +
" It acts the same as the normal cp command, but ids files on the fly\n" +
" It also adds the ability to specify multiple copy targets with the -T flag.\n\n" +
" flags:\n"
flag.Usage = func() {
fmt.Fprintf(os.Stderr, id_message)
id_flags.PrintDefaults()
fmt.Fprintf(os.Stderr, cp_message)
cp_flags.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n")
}
id_flags = flag.NewFlagSet("id", flag.ContinueOnError)
cp_flags = flag.NewFlagSet("cp", flag.ContinueOnError)
// id
// id_flags.BoolVarP(&version_flag, "version", "v", false, "Show version information.")
id_flags.BoolVarP(&recursive_flag, "recursive", "R", false, "Recursively identify all files for the given url.")
id_flags.BoolVarP(&absolute_flag, "absolute", "a", false, "Output absolute paths, instead of relative paths.")
// id_flags.BoolVarP(&arg_links, "arg_links", "H", false, "If the -R option is specified, symbolic links on the command line are followed.\n (Symbolic links encountered in the tree traversal are not followed by default.)")
id_flags.BoolVarP(&links_flag, "links", "L", false, "All symbolic links are followed.")
// id_flags.BoolVarP(&no_links, "no_links", "P", true, "If the -R option is specified, no symbolic links are followed. This is the default.")
id_flags.IntVarP(&depth, "depth", "d", 0, "Only output ids for files and folders 'depth' directories deep.")
id_flags.BoolVarP(&include_meta, "metadata", "m", false, "Include filesystem metadata.")
id_flags.StringVarP(&formatting_string, "formatting", "f", "id", "Output formatting options.\n \"id\": c4id oriented.\n \"path\": path oriented.")
// cp
cp_flags.BoolVarP(&archive_cp_flag, "archive", "a", false, "Same as -pPR options.")
cp_flags.BoolVarP(&force_cp_flag, "force", "f", false, "Force.")
cp_flags.BoolVarP(&follow_all_links_cp_flag, "follow_all_links", "H", false, "Follow all symbolic links.")
cp_flags.BoolVarP(&prompt_cp_flag, "prompt", "i", false, "Prompt before overwriting an existing file.")
cp_flags.BoolVarP(&follow_links_cp_flag, "follow_links", "L", false, "Follow links instead of copy with -R option.")
cp_flags.BoolVarP(&noclobber_cp_flag, "noclobber", "n", false, "Do not overwrite existing files.")
cp_flags.BoolVarP(©_links_cp_flag, "copy_links", "P", true, "Copy links with -R option (default).")
cp_flags.BoolVarP(&preserve_cp_flag, "preserve", "p", false, "Preserve attributes.")
cp_flags.BoolVarP(&recursive_cp_flag, "recursive", "R", false, "Copy recursively.")
cp_flags.BoolVarP(&verbose_cp_flag, "verbose", "v", false, "Verbose output.")
cp_flags.VarP(&target_cp_flag, "target", "T", "Specify additional target paths, can be used more than once.")
}
示例2: NewCmd
func NewCmd(l log15.Logger, server *Server, version string) *Cmd {
var (
flags = &flags{
FlagSet: pflag.NewFlagSet("", pflag.ExitOnError),
}
)
flags.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n")
flags.PrintDefaults()
}
flags.StringVar(&flags.location, "location", "", "unix socket for http")
flags.StringVar(&flags.statedir, "statedir", "", "statedir location")
flags.BoolVarP(&flags.help, "help", "h", false, "show help")
flags.BoolVarP(&flags.version, "version", "v", false, "show version")
flags.BoolVar(&flags.verbose, "verbose", false, "verbose output")
return &Cmd{
Logger: l,
flags: flags,
Server: server,
version: version,
}
}
示例3: parseFlags
func (cmd *Download) parseFlags() (exitCode int, err error) {
var showUsage bool
fs := flag.NewFlagSet("conoha-ojs-download", flag.ContinueOnError)
fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
err = fs.Parse(os.Args[2:])
if err != nil {
return ExitCodeParseFlagError, err
}
if showUsage {
return ExitCodeUsage, nil
}
if len(os.Args) < 3 {
return ExitCodeParseFlagError, errors.New("Not enough arguments.")
}
// 取得するオブジェクト名
cmd.objectName = os.Args[2]
// 保存先のパス
if len(os.Args) == 4 {
cmd.destPath = os.Args[3]
} else {
cmd.destPath = "."
}
return ExitCodeOK, nil
}
示例4: FlagParse
func FlagParse(args []string) (*CLI, error) {
fs := pflag.NewFlagSet(args[0], pflag.ContinueOnError)
cli := &CLI{}
fs.BoolVarP(&cli.Public, "private", "p", false, "make private")
err := fs.Parse(args[1:])
if err != nil {
return nil, err
}
cli.Public = !cli.Public
if len(fs.Args()) != 1 {
return nil, fmt.Errorf("file name is required")
}
cli.FileName = fs.Arg(0)
content, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return nil, err
}
cli.FileContent = string(content)
return cli, nil
}
示例5: parseFlags
// コマンドライン引數を処理して、一覧表示するコンテナ名を返す
// 引數が省略された場合はルートを決め打ちする
func (cmd *List) parseFlags() (exitCode int, err error) {
var showUsage bool
fs := flag.NewFlagSet("conoha-ojs-list", flag.ContinueOnError)
fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
err = fs.Parse(os.Args[2:])
if err != nil {
return ExitCodeParseFlagError, err
}
if showUsage {
return ExitCodeUsage, nil
}
if len(os.Args) == 2 {
// コンテナ名が指定されなかったときはルートを決め打ちする
cmd.containerName = "/"
} else if len(os.Args) < 2 {
return ExitCodeParseFlagError, errors.New("Not enough arguments.")
} else {
cmd.containerName = os.Args[2]
}
return ExitCodeOK, nil
}
示例6: parseFlags
func (cmd *Delete) parseFlags() (exitCode int, err error) {
var showUsage bool
fs := flag.NewFlagSet("conoha-ojs-delete", flag.ContinueOnError)
fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
err = fs.Parse(os.Args[2:])
if err != nil {
return ExitCodeParseFlagError, err
}
if showUsage {
return ExitCodeUsage, nil
}
if fs.NArg() < 1 {
return ExitCodeParseFlagError, errors.New("Not enough arguments.")
}
// 削除するオブジェクト名
cmd.objectName = os.Args[2]
return ExitCodeOK, nil
}
示例7: parseFlags
// 引數-mでメタデータを指定する
// メタデータはコロン區切りの key:value の形式で渡す。
func (cmd *Post) parseFlags() (exitCode int, err error) {
// 初期化
cmd.metadatas = strmap{}
var showUsage bool
fs := flag.NewFlagSet("conoha-ojs-post", flag.ContinueOnError)
fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
fs.VarP(&cmd.metadatas, "meta", "m", "Key and value of metadata.")
fs.StringVarP(&cmd.readAcl, "read-acl", "r", "_no_assign_", "Read ACL for containers.")
fs.StringVarP(&cmd.writeAcl, "write-acl", "w", "_no_assign_", "Write ACL for containers.")
err = fs.Parse(os.Args[2:])
if err != nil {
return ExitCodeParseFlagError, err
}
if showUsage {
return ExitCodeUsage, nil
}
// メタデータを操作するオブジェクト
cmd.objectName = fs.Arg(0)
if cmd.objectName == "" {
return ExitCodeParseFlagError, errors.New("Not enough arguments.")
}
return ExitCodeOK, nil
}
示例8: readConfigsFromReader
func readConfigsFromReader(r io.Reader, name string) ([]*Config, error) {
scanner := bufio.NewScanner(r)
lineNo := 0
var configs []*Config
for scanner.Scan() {
lineNo++
errorf := fmt.Sprintf("error on line %d of %s: %%s", lineNo, name)
c := &Config{}
flags := flag.NewFlagSet("", flag.ContinueOnError)
flags.SetOutput(ioutil.Discard)
c.registerFlags(flags)
parts, err := shellquote.Split(scanner.Text())
if err != nil {
return nil, fmt.Errorf(errorf, err)
}
// Skip empty lines and comments (lines starting with #).
if len(parts) == 0 || strings.HasPrefix(parts[0], "#") {
continue
}
if err := flags.Parse(parts); err != nil {
return nil, fmt.Errorf(errorf, err)
}
c.command = flags.Args()
c.source = fmt.Sprintf("%s, line %d", name, lineNo)
configs = append(configs, c)
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("error reading config from %s: %s", name, err)
}
return configs, nil
}
示例9: config
// Read configuration from both profile and flags. Flags override profile.
func config() (*flag.FlagSet, error) {
dir, err := getCfgDir(".boot2docker")
if err != nil {
return nil, fmt.Errorf("failed to get boot2docker directory: %s", err)
}
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flags.Usage = func() { usageLong(flags) }
flags.StringVar(&B2D.VM, "vm", "boot2docker-vm", "virtual machine name.")
flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2docker config directory.")
flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.")
flags.StringVar(&B2D.VMDK, "basevmdk", "", "Path to VMDK to use as base for persistent partition")
vbm := "VBoxManage"
if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" && runtime.GOOS == "windows" {
vbm = filepath.Join(p, "VBoxManage.exe")
}
flags.StringVar(&B2D.VBM, "vbm", vbm, "path to VirtualBox management utility.")
flags.BoolVarP(&B2D.Verbose, "verbose", "v", false, "display verbose command invocations.")
flags.StringVar(&B2D.SSH, "ssh", "ssh", "path to SSH client utility.")
flags.StringVar(&B2D.SSHGen, "ssh-keygen", "ssh-keygen", "path to ssh-keygen utility.")
sshdir, _ := getCfgDir(".ssh")
flags.StringVar(&B2D.SSHKey, "sshkey", filepath.Join(sshdir, "id_boot2docker"), "path to SSH key to use.")
flags.UintVarP(&B2D.DiskSize, "disksize", "s", 20000, "boot2docker disk image size (in MB).")
flags.UintVarP(&B2D.Memory, "memory", "m", 1024, "virtual machine memory size (in MB).")
flags.Uint16Var(&B2D.SSHPort, "sshport", 2022, "host SSH port (forward to port 22 in VM).")
flags.Uint16Var(&B2D.DockerPort, "dockerport", 4243, "host Docker port (forward to port 4243 in VM).")
flags.IPVar(&B2D.HostIP, "hostip", net.ParseIP("192.168.59.3"), "VirtualBox host-only network IP address.")
flags.IPMaskVar(&B2D.NetMask, "netmask", flag.ParseIPv4Mask("255.255.255.0"), "VirtualBox host-only network mask.")
flags.BoolVar(&B2D.DHCPEnabled, "dhcp", true, "enable VirtualBox host-only network DHCP.")
flags.IPVar(&B2D.DHCPIP, "dhcpip", net.ParseIP("192.168.59.99"), "VirtualBox host-only network DHCP server address.")
flags.IPVar(&B2D.LowerIP, "lowerip", net.ParseIP("192.168.59.103"), "VirtualBox host-only network DHCP lower bound.")
flags.IPVar(&B2D.UpperIP, "upperip", net.ParseIP("192.168.59.254"), "VirtualBox host-only network DHCP upper bound.")
// Set the defaults
if err := flags.Parse([]string{}); err != nil {
return nil, err
}
// Over-ride from the profile file
// TODO: should we really parse for and expand $ENVVARS before we process..?
filename := getCfgFilename(dir)
if _, err := toml.DecodeFile(filename, &B2D); err != nil {
return nil, err
}
// Command-line overrides profile config.
if err := flags.Parse(os.Args[1:]); err != nil {
return nil, err
}
// Name of VM is the second argument. Override the value set in flag.
if vm := flags.Arg(1); vm != "" {
B2D.VM = vm
}
vbx.Verbose = B2D.Verbose
vbx.VBM = B2D.VBM
return flags, nil
}
示例10: parseCommandLine
func parseCommandLine(cmdLine []string) (Args, error) {
var result Args
flags := pflag.NewFlagSet("Sarge", pflag.ContinueOnError)
flags.StringVarP(&result.ImageFile, "image", "i", "",
"The image file to load")
err := flags.Parse(cmdLine)
return result, err
}
示例11: parseFlags
func parseFlags(args []string) (*config.Config, error) {
var doHelp bool
var doVersion bool
var c = config.DefaultConfig()
flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError)
flags.Usage = func() {
fmt.Println(Help())
}
flags.BoolVar(&doHelp, "help", false, "")
flags.BoolVar(&doVersion, "version", false, "")
flags.StringVar(&c.LogLevel, "log-level", "WARN", "")
flags.DurationVar(&c.Refresh, "refresh", time.Minute, "")
flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "")
flags.StringVar(&c.MesosIpOrder, "mesos-ip-order", "netinfo,mesos,host", "")
flags.BoolVar(&c.Healthcheck, "healthcheck", false, "")
flags.StringVar(&c.HealthcheckIp, "healthcheck-ip", "127.0.0.1", "")
flags.StringVar(&c.HealthcheckPort, "healthcheck-port", "24476", "")
flags.Var((funcVar)(func(s string) error {
c.WhiteList = append(c.WhiteList, s)
return nil
}), "whitelist", "")
flags.StringVar(&c.ServiceName, "service-name", "mesos", "")
flags.StringVar(&c.ServiceTags, "service-tags", "", "")
consul.AddCmdFlags(flags)
if err := flags.Parse(args); err != nil {
return nil, err
}
args = flags.Args()
if len(args) > 0 {
return nil, fmt.Errorf("extra argument(s): %q", args)
}
if doVersion {
fmt.Printf("%s v%s\n", Name, Version)
os.Exit(0)
}
if doHelp {
flags.Usage()
os.Exit(0)
}
l, err := log.ParseLevel(strings.ToLower(c.LogLevel))
if err != nil {
log.SetLevel(log.WarnLevel)
log.Warnf("Invalid log level '%v'. Setting to WARN", c.LogLevel)
} else {
log.SetLevel(l)
}
return c, nil
}
示例12: ParseCommandLine
// ParseCommandLine parses the standard command line interface for a squaddie
// plugin
func ParseCommandLine(cmdLine []string) (Args, error) {
var result Args
flags := pflag.NewFlagSet("Plugin API", pflag.ContinueOnError)
flags.StringVarP(&result.Network, "network", "n", "unix",
"The network type")
flags.StringVarP(&result.Path, "path", "p", "/var/sarge.sock",
"The RPC endpoint")
err := flags.Parse(cmdLine)
return result, err
}
示例13: Parse
func (c *CLI) Parse(args []string) error {
cmds := make(Commands, 0)
c.Commands = cmds
fset := pflag.NewFlagSet(args[0], pflag.ContinueOnError)
fset.VarP(&c.Commands, "command", "c", "command")
err := fset.Parse(args[1:])
c.Files = fset.Args()
return err
}
示例14: RunServer
func RunServer(args []string) {
flags := flag.NewFlagSet("server", flag.ExitOnError)
addCommonOptions(flags)
flags.Parse(args)
// We start the transports in another goroutine, so our main routine can
// return (and wait for signals).
// Note: The startTransports function takes ownership (and closes) the
// tuntap device.
tt := getTuntap(false)
go startTransports(tt)
}
示例15: httpHandle
func httpHandle(args []string) {
set := pflag.NewFlagSet("http", pflag.ExitOnError)
addr := set.StringP("addr", "a", ":8080", "Listen address.")
set.Parse(args)
if addr == nil {
set.Usage()
os.Exit(1)
}
if err := ListenAndServe(*addr); err != nil {
log.Fatal(err)
}
}