(t *testing.T)
| 1309 | func (cv *customValue) Type() string { return "custom" } |
| 1310 | |
| 1311 | func TestPrintDefaults(t *testing.T) { |
| 1312 | fs := NewFlagSet("print defaults test", ContinueOnError) |
| 1313 | var buf bytes.Buffer |
| 1314 | fs.SetOutput(&buf) |
| 1315 | fs.Bool("A", false, "for bootstrapping, allow 'any' type") |
| 1316 | fs.Bool("Alongflagname", false, "disable bounds checking") |
| 1317 | fs.BoolP("CCC", "C", true, "a boolean defaulting to true") |
| 1318 | fs.String("D", "", "set relative `path` for local imports") |
| 1319 | fs.Float64("F", 2.7, "a non-zero `number`") |
| 1320 | fs.Float64("G", 0, "a float that defaults to zero") |
| 1321 | fs.Int("N", 27, "a non-zero int") |
| 1322 | fs.IntSlice("Ints", []int{}, "int slice with zero default") |
| 1323 | fs.IP("IP", nil, "IP address with no default") |
| 1324 | fs.IPMask("IPMask", nil, "Netmask address with no default") |
| 1325 | fs.IPNet("IPNet", net.IPNet{}, "IP network with no default") |
| 1326 | fs.Int("Z", 0, "an int that defaults to zero") |
| 1327 | fs.Duration("maxT", 0, "set `timeout` for dial") |
| 1328 | fs.String("ND1", "foo", "a string with NoOptDefVal") |
| 1329 | fs.Lookup("ND1").NoOptDefVal = "bar" |
| 1330 | fs.Int("ND2", 1234, "a `num` with NoOptDefVal") |
| 1331 | fs.Lookup("ND2").NoOptDefVal = "4321" |
| 1332 | fs.IntP("EEE", "E", 4321, "a `num` with NoOptDefVal") |
| 1333 | fs.ShorthandLookup("E").NoOptDefVal = "1234" |
| 1334 | fs.StringSlice("StringSlice", []string{}, "string slice with zero default") |
| 1335 | fs.StringArray("StringArray", []string{}, "string array with zero default") |
| 1336 | fs.CountP("verbose", "v", "verbosity") |
| 1337 | |
| 1338 | var cv customValue |
| 1339 | fs.Var(&cv, "custom", "custom Value implementation") |
| 1340 | |
| 1341 | cv2 := customValue(10) |
| 1342 | fs.VarP(&cv2, "customP", "", "a VarP with default") |
| 1343 | |
| 1344 | // Simulate case where a value has been provided and the help screen is shown |
| 1345 | var cv3 customValue |
| 1346 | fs.Var(&cv3, "custom-with-val", "custom value which has been set from command line while help is shown") |
| 1347 | err := fs.Parse([]string{"--custom-with-val", "3"}) |
| 1348 | if err != nil { |
| 1349 | t.Error("Parsing flags failed:", err) |
| 1350 | } |
| 1351 | |
| 1352 | fs.PrintDefaults() |
| 1353 | got := buf.String() |
| 1354 | if got != defaultOutput { |
| 1355 | t.Errorf("\n--- Got:\n%s--- Wanted:\n%s\n", got, defaultOutput) |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | func TestVisitAllFlagOrder(t *testing.T) { |
| 1360 | fs := NewFlagSet("TestVisitAllFlagOrder", ContinueOnError) |
nothing calls this directly
no test coverage detected