本文整理汇总了Golang中flag.FlagSet类的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet类的具体用法?Golang FlagSet怎么用?Golang FlagSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlagSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Register
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
f.StringVar(&cmd.spec.VswitchName, "vswitch", "", "vSwitch Name")
f.IntVar(&cmd.spec.VlanId, "vlan", 0, "VLAN ID")
}
示例2: Register
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
f.BoolVar(&cmd.Long, "l", false, "Long listing format")
f.StringVar(&cmd.Type, "t", "", "Object type")
}
示例3: Run
func (cmd *esxcli) Run(f *flag.FlagSet) error {
c, err := cmd.Client()
if err != nil {
return nil
}
host, err := cmd.HostSystem()
if err != nil {
return err
}
e, err := NewExecutor(c, host)
if err != nil {
return err
}
res, err := e.Run(f.Args())
if err != nil {
return err
}
if len(res.Values) == 0 {
return nil
}
// TODO: OutputFlag / format options
switch res.Info.Hints.Formatter() {
case "table":
cmd.formatTable(res)
default:
cmd.formatSimple(res)
}
return nil
}
示例4: createComponentUsage
// CreateComponentUsage creates a usage function for a component.
func createComponentUsage(info pythia.ComponentInfo, fs *flag.FlagSet) func() {
return func() {
fmt.Fprintf(os.Stderr, componentUsageHeader, os.Args[0], info.Name,
info.Description)
fs.PrintDefaults()
}
}
示例5: copyFlag
func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
switch ff.Value.(type) {
case *StringSlice:
default:
set.Set(name, ff.Value.String())
}
}
示例6: addFetchFlags
func addFetchFlags(fs *flag.FlagSet) {
fs.StringVar(&branch, "branch", "", "branch of the package")
fs.StringVar(&revision, "revision", "", "revision of the package")
fs.StringVar(&tag, "tag", "", "tag of the package")
fs.BoolVar(&noRecurse, "no-recurse", false, "do not fetch recursively")
fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols")
}
示例7: commandHelp
func commandHelp(name string, cmd Command, f *flag.FlagSet) {
type HasUsage interface {
Usage() string
}
fmt.Fprintf(os.Stderr, "Usage: %s %s [OPTIONS]", os.Args[0], name)
if u, ok := cmd.(HasUsage); ok {
fmt.Fprintf(os.Stderr, " %s", u.Usage())
}
fmt.Fprintf(os.Stderr, "\n")
type HasDescription interface {
Description() string
}
if u, ok := cmd.(HasDescription); ok {
fmt.Fprintf(os.Stderr, "%s\n", u.Description())
}
n := 0
f.VisitAll(func(_ *flag.Flag) {
n += 1
})
if n > 0 {
fmt.Fprintf(os.Stderr, "\nOptions:\n")
tw := tabwriter.NewWriter(os.Stderr, 2, 0, 2, ' ', 0)
f.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(tw, "\t-%s=%s\t%s\n", f.Name, f.DefValue, f.Usage)
})
tw.Flush()
}
}
示例8: Run
func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error {
c, err := cmd.Client()
if err != nil {
return err
}
refs, err := cmd.ManagedObjects(ctx, f.Args())
if err != nil {
return err
}
m := object.NewAuthorizationManager(c)
rl, err := m.RoleList(ctx)
if err != nil {
return err
}
role := rl.ByName(cmd.role)
if role == nil {
return fmt.Errorf("role '%s' not found", cmd.role)
}
cmd.Permission.RoleId = role.RoleId
perms := []types.Permission{cmd.Permission}
for _, ref := range refs {
err = m.SetEntityPermissions(ctx, ref, perms)
if err != nil {
return err
}
}
return nil
}
示例9: usageFor
func usageFor(fs *flag.FlagSet, usage string) func() {
return func() {
var b bytes.Buffer
b.WriteString(ansi.Bold("Usage:") + "\n " + usage + "\n")
var options [][]string
fs.VisitAll(func(f *flag.Flag) {
var opt = " -" + f.Name
if f.DefValue != "false" {
opt += "=" + f.DefValue
}
options = append(options, []string{opt, f.Usage})
})
if len(options) > 0 {
b.WriteString("\n" + ansi.Bold("Options:") + "\n")
optionTable(&b, options)
}
fmt.Println(b.String())
}
}
示例10: Register
func (cmd *connect) Register(ctx context.Context, f *flag.FlagSet) {
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
cmd.VirtualMachineFlag.Register(ctx, f)
f.StringVar(&cmd.device, "device", "", "serial port device name")
f.BoolVar(&cmd.client, "client", false, "Use client direction")
}
示例11: Register
func (cmd *service) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
f.BoolVar(&cmd.Enable, "enable", false, "Enable service")
f.BoolVar(&cmd.Disable, "disable", false, "Disable service")
}
示例12: Run
func (cmd *install) Run(ctx context.Context, f *flag.FlagSet) error {
host, err := cmd.HostSystem()
if err != nil {
return err
}
m, err := host.ConfigManager().CertificateManager(ctx)
if err != nil {
return err
}
var cert string
name := f.Arg(0)
if name == "-" || name == "" {
var buf bytes.Buffer
if _, err := io.Copy(&buf, os.Stdin); err != nil {
return err
}
cert = buf.String()
} else {
b, err := ioutil.ReadFile(name)
if err != nil {
return err
}
cert = string(b)
}
return m.InstallServerCertificate(ctx, cert)
}
示例13: newCommandUnsub
// newCommandUnsub creates and returns an unsub command.
func newCommandUnsub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
topicFilter := flg.String("t", "", "Topic Filter")
// Parse the flag.
if err := flg.Parse(args); err != nil {
return nil, errCmdArgsParse
}
// Create an unsub command.
cmd := &commandUnsub{
cli: cli,
unsubscribeOpts: &client.UnsubscribeOptions{
TopicFilters: [][]byte{
[]byte(*topicFilter),
},
},
}
// Return the command.
return cmd, nil
}
示例14: Run
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
finder, err := cmd.Finder()
if err != nil {
return err
}
lr := listResult{
Elements: nil,
Long: cmd.Long,
}
args := f.Args()
if len(args) == 0 {
args = []string{"."}
}
for _, arg := range args {
es, err := finder.ManagedObjectListChildren(context.TODO(), arg)
if err != nil {
return err
}
for _, e := range es {
if cmd.typeMatch(e.Object.Reference()) {
lr.Elements = append(lr.Elements, e)
}
}
}
return cmd.WriteResult(lr)
}
示例15: Run
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
vm, err := cmd.VirtualMachine()
if err != nil {
return err
}
if vm == nil {
return flag.ErrHelp
}
devices, err := vm.Device(ctx)
if err != nil {
return err
}
for _, name := range f.Args() {
device := devices.Find(name)
if device == nil {
return fmt.Errorf("device '%s' not found", name)
}
if err = vm.RemoveDevice(ctx, cmd.keepFiles, device); err != nil {
return err
}
}
return nil
}