本文整理匯總了Golang中flag.FlagSet.Bool方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagSet.Bool方法的具體用法?Golang FlagSet.Bool怎麽用?Golang FlagSet.Bool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.Bool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: multisnapshotCmd
func multisnapshotCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) {
concurrency := subFlags.Int("concurrency", 8, "how many compression jobs to run simultaneously")
spec := subFlags.String("spec", "-", "shard specification")
tablesString := subFlags.String("tables", "", "dump only this comma separated list of tables")
skipSlaveRestart := subFlags.Bool("skip-slave-restart", false, "after the snapshot is done, do not restart slave replication")
maximumFilesize := subFlags.Uint64("maximum-file-size", 128*1024*1024, "the maximum size for an uncompressed data file")
subFlags.Parse(args)
if subFlags.NArg() != 2 {
relog.Fatal("action multisnapshot requires <db name> <key name>")
}
shards, err := key.ParseShardingSpec(*spec)
if err != nil {
relog.Fatal("multisnapshot failed: %v", err)
}
var tables []string
if *tablesString != "" {
tables = strings.Split(*tablesString, ",")
}
filenames, err := mysqld.CreateMultiSnapshot(shards, subFlags.Arg(0), subFlags.Arg(1), tabletAddr, false, *concurrency, tables, *skipSlaveRestart, *maximumFilesize, nil)
if err != nil {
relog.Fatal("multisnapshot failed: %v", err)
} else {
relog.Info("manifest locations: %v", filenames)
}
}
示例2: ApplyWithError
// ApplyWithError populates the flag given the flag set and environment
func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
val := true
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
envVar = strings.TrimSpace(envVar)
if envVal, ok := syscall.Getenv(envVar); ok {
if envVal == "" {
val = false
break
}
envValBool, err := strconv.ParseBool(envVal)
if err != nil {
return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
}
val = envValBool
break
}
}
}
eachName(f.Name, func(name string) {
if f.Destination != nil {
set.BoolVar(f.Destination, name, val, f.Usage)
return
}
set.Bool(name, val, f.Usage)
})
return nil
}
示例3: 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
}
示例4: TestLoadConfig
func TestLoadConfig(t *testing.T) {
var flagSet flag.FlagSet
a := flagSet.Int("a", -1, "for test")
b := flagSet.Bool("b", true, "for test")
c := flagSet.String("c", "-1", "for test")
da := flagSet.Int("d.a", -1, "for test")
dd := flagSet.Bool("d.d", false, "for test")
dc := flagSet.String("d.c", "-1", "for test")
e := loadConfig("config_test.txt", &flagSet, false)
if nil != e {
t.Error(e)
return
}
if *a != 1 {
t.Error("a != 1")
}
if !*b {
t.Error("b != true")
}
if "abc" != *c {
t.Error("c != \"abc\"")
}
if *da != 1323 {
t.Error("d.a != 1323")
}
if !*dd {
t.Error("db != true")
}
if "67" != *dc {
t.Errorf("dc != \"67\", actual is %s", *dc)
}
}
示例5: 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
}
示例6: commandWorkflowCreate
func commandWorkflowCreate(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
if WorkflowManager == nil {
return fmt.Errorf("no workflow.Manager registered")
}
skipStart := subFlags.Bool("skip_start", false, "If set, the workflow will not be started.")
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() < 1 {
return fmt.Errorf("the <factoryName> argument is required for the WorkflowCreate command")
}
factoryName := subFlags.Arg(0)
uuid, err := WorkflowManager.Create(ctx, factoryName, subFlags.Args()[1:])
if err != nil {
return err
}
wr.Logger().Printf("uuid: %v\n", uuid)
if !*skipStart {
return WorkflowManager.Start(ctx, uuid)
}
return nil
}
示例7: 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")
json := subFlags.Bool("json", false, "Output JSON instead of human-readable table")
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, []topodatapb.TabletType{topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.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)
}
if *json {
return printJSON(wr.Logger(), qr)
}
printQueryResult(loggerWriter{wr.Logger()}, qr)
return nil
}
示例8: 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
}
示例9: 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
}
示例10: Flags
func (c *DaemonCmd) Flags(fs *flag.FlagSet) {
c.dbfile = fs.String("o", "ci.db", "override the default local file name")
c.port = fs.Int("p", 2020, "override the default local port")
c.hookport = fs.Int("hp", 2121, "override the default hook port ")
c.hook = fs.Bool("hook", false, "also start an http Hook server (Get returns a status, Post fire a build)")
}
示例11: NewGoCmdWithFlags
// NewGoCmdWithFlags like NewGoCmd, but wl also parse flags configured i flagset
func NewGoCmdWithFlags(flagset *flag.FlagSet, workdir string, args ...string) (*GoCmd, error) {
if len(args) < 2 {
return nil, errors.New("GoCmd must have at least two arguments (e.g. go build)")
}
if sort.SearchStrings([]string{"build", "run", "test"}, args[1]) > -1 {
flagset.Int("p", runtime.NumCPU(), "number or parallel builds")
for _, f := range []string{"x", "v", "n", "a", "work"} {
flagset.Bool(f, false, "")
}
for _, f := range []string{"compiler", "gccgoflags", "gcflags", "ldflags", "tags"} {
flagset.String(f, "", "")
}
}
switch args[1] {
case "run":
case "build":
flagset.String("o", "", "output: output file")
case "test":
for _, f := range []string{"i", "c"} {
flagset.Bool(f, false, "")
}
for _, testflag := range TestFlags {
flagset.String(testflag, "", "")
flagset.String("test."+testflag, "", "")
}
flagset.Bool("short", false, "")
flagset.Bool("test.short", false, "")
flagset.Bool("test.v", false, "")
default:
return nil, errors.New("Currently only build run and test commands supported. Sorry.")
}
if err := flagset.Parse(args[2:]); err != nil {
return nil, err
}
var params, extra []string
switch args[1] {
case "build":
params = flagset.Args()
case "run":
for i, param := range flagset.Args() {
if !strings.HasSuffix(param, ".go") {
extra = flagset.Args()[i:]
break
}
params = append(params, param)
}
case "test":
for i, param := range flagset.Args() {
if strings.HasPrefix(param, "-") {
extra = flagset.Args()[i:]
break
}
params = append(params, param)
}
default:
return nil, errors.New("Currently only build run and test commands supported")
}
return &GoCmd{make(map[string]string), workdir, args[0], args[1], FromFlagSet(flagset), params, extra}, nil
}
示例12: Flags
func (cmd *touchCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
cmd.hidden = fs.Bool(drive.HiddenKey, false, "allows pushing of hidden paths")
cmd.recursive = fs.Bool("r", false, "toggles recursive touching")
cmd.matches = fs.Bool(drive.MatchesKey, false, "search by prefix and touch")
cmd.quiet = fs.Bool(drive.QuietKey, false, "if set, do not log anything but errors")
cmd.byId = fs.Bool(drive.CLIOptionId, false, "share by id instead of path")
return fs
}
示例13: teardownCmd
func teardownCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) {
force := subFlags.Bool("force", false, "will remove the root directory even if mysqld shutdown fails")
subFlags.Parse(args)
if err := mysqlctl.Teardown(mysqld, *force); err != nil {
relog.Fatal("failed teardown mysql (forced? %v): %v", *force, err)
}
}
示例14: init
func init() {
var fs flag.FlagSet
goimport := fs.Bool("goimport", false, "use goimport instead of gofmt")
commands["fmt"] = &Command{
fs: &fs,
do: func(ctx *Context) { doFormat(ctx, *goimport) },
}
}
示例15: init
func init() {
var fs flag.FlagSet
all := fs.Bool("all", false, "show unexported identifiers")
commands["doc"] = &Command{
fs: &fs,
do: func(ctx *Context) { os.Exit(doDoc(ctx, *all)) },
}
}