本文整理汇总了Golang中flag.FlagSet.String方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.String方法的具体用法?Golang FlagSet.String怎么用?Golang FlagSet.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Flags
func (cmd *editDescriptionCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
cmd.ById = fs.Bool(drive.CLIOptionId, false, "open by id instead of path")
cmd.Description = fs.String(drive.CLIOptionDescription, "", drive.DescDescription)
cmd.Piped = fs.Bool(drive.CLIOptionPiped, false, drive.DescPiped)
return fs
}
示例2: commandVtGateSplitQuery
func commandVtGateSplitQuery(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
server := subFlags.String("server", "", "VtGate server to connect to")
bindVariables := newBindvars(subFlags)
connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client")
splitCount := subFlags.Int("split_count", 16, "number of splits to generate")
keyspace := subFlags.String("keyspace", "", "keyspace to send query to")
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() != 1 {
return fmt.Errorf("the <sql> argument is required for the VtGateSplitQuery command")
}
vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout)
if err != nil {
return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err)
}
defer vtgateConn.Close()
r, err := vtgateConn.SplitQuery(ctx, *keyspace, tproto.BoundQuery{
Sql: subFlags.Arg(0),
BindVariables: *bindVariables,
}, *splitCount)
if err != nil {
return fmt.Errorf("SplitQuery failed: %v", err)
}
wr.Logger().Printf("%v\n", jscfg.ToJSON(r))
return nil
}
示例3: commandLegacySplitClone
func commandLegacySplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude")
strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker LegacySplitClone --strategy=-help k/s' for more info")
sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert")
destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets before taking out one")
maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)")
if err := subFlags.Parse(args); err != nil {
return nil, err
}
if subFlags.NArg() != 1 {
subFlags.Usage()
return nil, fmt.Errorf("command LegacySplitClone requires <keyspace/shard>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
if err != nil {
return nil, err
}
var excludeTableArray []string
if *excludeTables != "" {
excludeTableArray = strings.Split(*excludeTables, ",")
}
worker, err := NewLegacySplitCloneWorker(wr, wi.cell, keyspace, shard, excludeTableArray, *strategy, *sourceReaderCount, *destinationPackCount, *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS)
if err != nil {
return nil, fmt.Errorf("cannot create split clone worker: %v", err)
}
return worker, nil
}
示例4: newCommandSub
// newCommandSub creates and returns a sub command.
func newCommandSub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
topicFilter := flg.String("t", "", "Topic Filter")
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
// Parse the flag.
if err := flg.Parse(args); err != nil {
return nil, errCmdArgsParse
}
// Create a sub command.
cmd := &commandSub{
cli: cli,
subscribeOpts: &client.SubscribeOptions{
SubReqs: []*client.SubReq{
&client.SubReq{
TopicFilter: []byte(*topicFilter),
QoS: byte(*qos),
Handler: messageHandler,
},
},
},
}
// Return the command.
return cmd, nil
}
示例5: commandVerticalSplitClone
func commandVerticalSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
tables := subFlags.String("tables", "", "comma separated list of tables to replicate (used for vertical split)")
strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'mysqlctl multirestore -strategy=-help' for more info")
sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert")
minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible")
destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
if err := subFlags.Parse(args); err != nil {
return nil, err
}
if subFlags.NArg() != 1 {
subFlags.Usage()
return nil, fmt.Errorf("command VerticalSplitClone requires <destination keyspace/shard>")
}
keyspace, shard, err := topo.ParseKeyspaceShardString(subFlags.Arg(0))
if err != nil {
return nil, err
}
var tableArray []string
if *tables != "" {
tableArray = strings.Split(*tables, ",")
}
worker, err := NewVerticalSplitCloneWorker(wr, wi.cell, keyspace, shard, tableArray, *strategy, *sourceReaderCount, *destinationPackCount, uint64(*minTableSizeForSplit), *destinationWriterCount)
if err != nil {
return nil, fmt.Errorf("cannot create worker: %v", err)
}
return worker, nil
}
示例6: doInitialize
func doInitialize(fs *flag.FlagSet, argv []string) error {
var (
conffile = fs.String("conf", config.DefaultConfig.Conffile, "Config file path")
apikey = fs.String("apikey", "", "API key from mackerel.io web site (Required)")
)
fs.Parse(argv)
if *apikey == "" {
// Setting apikey via environment variable should be supported or not?
return fmt.Errorf("-apikey option is required")
}
_, err := os.Stat(*conffile)
confExists := err == nil
if confExists {
conf, err := config.LoadConfig(*conffile)
if err != nil {
return fmt.Errorf("Failed to load the config file: %s", err)
}
if conf.Apikey != "" {
return apikeyAlreadySetError(*conffile)
}
}
contents := []byte(fmt.Sprintf("apikey = %q\n", *apikey))
if confExists {
cBytes, err := ioutil.ReadFile(*conffile)
if err != nil {
return err
}
contents = append(contents, cBytes...)
}
return ioutil.WriteFile(*conffile, contents, 0644)
}
示例7: Setup
// Setup the parameters with the command line flags in args.
func (job *Job) Setup(fs *flag.FlagSet, args []string) error {
taskfile := fs.String("task", "", "path to the task description (mandatory)")
inputfile := fs.String("input", "", "path to the input file (mandatory)")
fs.StringVar(&job.UmlPath, "uml", job.UmlPath, "path to the UML executable")
fs.StringVar(&job.EnvDir, "envdir", job.EnvDir, "environments directory")
fs.StringVar(&job.TasksDir, "tasksdir", job.TasksDir, "tasks directory")
if err := fs.Parse(args); err != nil {
return err
}
if len(*taskfile) == 0 || len(*inputfile) == 0 {
return errors.New("Missing task or input file")
}
taskcontent, err := ioutil.ReadFile(*taskfile)
if err != nil {
return err
}
if json.Unmarshal(taskcontent, &job.Task) != nil {
return err
}
inputcontent, err := ioutil.ReadFile(*inputfile)
if err != nil {
return err
}
job.Input = string(inputcontent)
return nil
}
示例8: Flags
func (gc *GetCommand) Flags(fs *flag.FlagSet) *flag.FlagSet {
gc.header = fs.Bool("H", false, "Display record header")
gc.test = fs.Bool("t", false, "Test that the record can be retrieved")
gc.separator = fs.String("s", "====", "Record separator")
return fs
}
示例9: mainReqs
func mainReqs(args []string, flags *flag.FlagSet) {
flags.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s %s <package-name>\n", os.Args[0], args[0])
flags.PrintDefaults()
}
file := flags.String("graphfile", "", fmt.Sprintf("Path to PyPI dependency graph file. Defaults to $GOPATH/src/github.com/beyang/cheerio/data/pypi_graph"))
flags.Parse(args[1:])
if flags.NArg() < 1 {
flags.Usage()
os.Exit(1)
}
pkg := cheerio.NormalizedPkgName(flags.Arg(0))
var pypiG *cheerio.PyPIGraph
if *file == "" {
pypiG = cheerio.DefaultPyPIGraph
} else {
var err error
pypiG, err = cheerio.NewPyPIGraph(*file)
if err != nil {
fmt.Printf("Error creating PyPI graph: %s\n", err)
os.Exit(1)
}
}
pkgReq := pypiG.Requires(pkg)
pkgReqBy := pypiG.RequiredBy(pkg)
fmt.Printf("pkg %s uses (%d):\n %s\nand is used by (%d):\n %s\n", pkg, len(pkgReq), strings.Join(pkgReq, " "), len(pkgReqBy), strings.Join(pkgReqBy, " "))
}
示例10: commandEmergencyReparentShard
func commandEmergencyReparentShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
waitSlaveTimeout := subFlags.Duration("wait_slave_timeout", 30*time.Second, "time to wait for slaves to catch up in reparenting")
keyspaceShard := subFlags.String("keyspace_shard", "", "keyspace/shard of the shard that needs to be reparented")
newMaster := subFlags.String("new_master", "", "alias of a tablet that should be the new master")
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() == 2 {
// Legacy syntax: "<keyspace/shard> <tablet alias>".
if *newMaster != "" {
return fmt.Errorf("cannot use legacy syntax and flag -new_master for action EmergencyReparentShard at the same time")
}
*keyspaceShard = subFlags.Arg(0)
*newMaster = subFlags.Arg(1)
} else if subFlags.NArg() != 0 {
return fmt.Errorf("action EmergencyReparentShard requires -keyspace_shard=<keyspace/shard> -new_master=<tablet alias>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(*keyspaceShard)
if err != nil {
return err
}
tabletAlias, err := topoproto.ParseTabletAlias(*newMaster)
if err != nil {
return err
}
return wr.EmergencyReparentShard(ctx, keyspace, shard, tabletAlias, *waitSlaveTimeout)
}
示例11: commandSplitClone
func commandSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
online := subFlags.Bool("online", defaultOnline, "do online copy (optional approximate copy, source and destination tablets will not be put out of serving, minimizes downtime during offline copy)")
offline := subFlags.Bool("offline", defaultOffline, "do offline copy (exact copy at a specific GTID, required before shard migration, source and destination tablets will be put out of serving during copy)")
excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude")
strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker SplitClone --strategy=-help k/s' for more info")
sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
writeQueryMaxRows := subFlags.Int("write_query_max_rows", defaultWriteQueryMaxRows, "maximum number of rows per write query")
writeQueryMaxSize := subFlags.Int("write_query_max_size", defaultWriteQueryMaxSize, "maximum size (in bytes) per write query")
writeQueryMaxRowsDelete := subFlags.Int("write_query_max_rows_delete", defaultWriteQueryMaxRows, "maximum number of rows per DELETE FROM write query")
minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible")
destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets in the source and destination shard at start")
maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)")
if err := subFlags.Parse(args); err != nil {
return nil, err
}
if subFlags.NArg() != 1 {
subFlags.Usage()
return nil, fmt.Errorf("command SplitClone requires <keyspace/shard>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
if err != nil {
return nil, err
}
var excludeTableArray []string
if *excludeTables != "" {
excludeTableArray = strings.Split(*excludeTables, ",")
}
worker, err := NewSplitCloneWorker(wr, wi.cell, keyspace, shard, *online, *offline, excludeTableArray, *strategy, *sourceReaderCount, *writeQueryMaxRows, *writeQueryMaxSize, *writeQueryMaxRowsDelete, uint64(*minTableSizeForSplit), *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS)
if err != nil {
return nil, fmt.Errorf("cannot create split clone worker: %v", err)
}
return worker, nil
}
示例12: commandVtGateExecute
func commandVtGateExecute(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
server := subFlags.String("server", "", "VtGate server to connect to")
bindVariables := newBindvars(subFlags)
connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client")
tabletType := subFlags.String("tablet_type", "master", "tablet type to query")
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() != 1 {
return fmt.Errorf("the <sql> argument is required for the VtGateExecute command")
}
t, err := parseTabletType(*tabletType, []pb.TabletType{pb.TabletType_MASTER, pb.TabletType_REPLICA, pb.TabletType_RDONLY})
if err != nil {
return err
}
vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout)
if err != nil {
return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err)
}
defer vtgateConn.Close()
qr, err := vtgateConn.Execute(ctx, subFlags.Arg(0), *bindVariables, t)
if err != nil {
return fmt.Errorf("Execute failed: %v", err)
}
return printJSON(wr, qr)
}
示例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: newCommandPub
// newCommandPub creates and returns a pub command.
func newCommandPub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
retain := flg.Bool("r", false, "Retain")
topicName := flg.String("t", "", "Topic Name")
message := flg.String("m", "", "Application Message")
// Parse the flag.
if err := flg.Parse(args); err != nil {
return nil, errCmdArgsParse
}
// Create a pub command.
cmd := &commandPub{
cli: cli,
publishOpts: &client.PublishOptions{
QoS: byte(*qos),
Retain: *retain,
TopicName: []byte(*topicName),
Message: []byte(*message),
},
}
// Return the command.
return cmd, nil
}
示例15: AddFlags
func AddFlags(flags *flag.FlagSet) {
flags.String(
DebugFlag,
"",
"host:port for serving pprof debugging info",
)
}