@@ -105,7 +105,7 @@ func TestExecute(t *testing.T) {
105105
106106 return nil
107107 }),
108- cli .Flag (& force , "force" , 'f' , false , "Force something" ),
108+ cli .Flag (& force , "force" , 'f' , "Force something" ),
109109 }
110110
111111 cmd , err := cli .New ("test" , slices .Concat (options , tt .options )... )
@@ -270,8 +270,8 @@ func TestSubCommandExecute(t *testing.T) {
270270
271271 sub1 := func () (* cli.Command , error ) {
272272 defaultOpts := []cli.Option {
273- cli .Flag (& force , "force" , 'f' , false , "Force for sub1" ),
274- cli .Flag (& something , "something" , 's' , "" , " Something for sub1" ),
273+ cli .Flag (& force , "force" , 'f' , "Force for sub1" ),
274+ cli .Flag (& something , "something" , 's' , "Something for sub1" ),
275275 cli .Run (func (ctx context.Context , cmd * cli.Command ) error {
276276 if something == "" {
277277 something = "<empty>"
@@ -315,8 +315,8 @@ func TestSubCommandExecute(t *testing.T) {
315315
316316 return nil
317317 }),
318- cli .Flag (& deleteMe , "delete" , 'd' , false , "Delete for sub2" ),
319- cli .Flag (& number , "number" , 'n' , - 1 , "Number for sub2" ),
318+ cli .Flag (& deleteMe , "delete" , 'd' , "Delete for sub2" ),
319+ cli .Flag (& number , "number" , 'n' , "Number for sub2" , cli . FlagDefault ( - 1 ) ),
320320 }
321321
322322 opts := slices .Concat (defaultOpts , tt .sub2Options )
@@ -433,7 +433,7 @@ func TestHelp(t *testing.T) {
433433 cli .OverrideArgs ([]string {"--help" }),
434434 cli .Arg (new (string ), "src" , "The file to copy" ), // This one is required
435435 cli .Arg (new (string ), "dest" , "Destination to copy to" , cli .ArgDefault ("destination.txt" )), // This one is optional
436- cli .Flag (new (flag.Count ), "verbosity" , 'v' , 0 , "Increase the verbosity level" ),
436+ cli .Flag (new (flag.Count ), "verbosity" , 'v' , "Increase the verbosity level" ),
437437 cli .Run (func (ctx context.Context , cmd * cli.Command ) error { return nil }),
438438 },
439439 wantErr : false ,
@@ -493,10 +493,16 @@ func TestHelp(t *testing.T) {
493493 cli .Short ("A cool CLI to do things" ),
494494 cli .Long ("A longer, probably multiline description" ),
495495 cli .SubCommands (sub1 , sub2 ),
496- cli .Flag (new (bool ), "delete" , 'd' , false , "Delete something" ),
497- cli .Flag (new (int ), "count" , flag .NoShortHand , - 1 , "Count something" ),
498- cli .Flag (new ([]string ), "things" , flag .NoShortHand , nil , "Names of things" ),
499- cli .Flag (new ([]string ), "more" , flag .NoShortHand , []string {"one" , "two" }, "Names of things with a default" ),
496+ cli .Flag (new (bool ), "delete" , 'd' , "Delete something" ),
497+ cli .Flag (new (int ), "count" , flag .NoShortHand , "Count something" , cli .FlagDefault (- 1 )),
498+ cli .Flag (new ([]string ), "things" , flag .NoShortHand , "Names of things" ),
499+ cli .Flag (
500+ new ([]string ),
501+ "more" ,
502+ flag .NoShortHand ,
503+ "Names of things with a default" ,
504+ cli .FlagDefault ([]string {"one" , "two" }),
505+ ),
500506 },
501507 wantErr : false ,
502508 },
@@ -735,16 +741,16 @@ func TestOptionValidation(t *testing.T) {
735741 {
736742 name : "flag already exists" ,
737743 options : []cli.Option {
738- cli .Flag (new (int ), "count" , 'c' , 0 , "Count something" ),
739- cli .Flag (new (int ), "count" , 'c' , 0 , "Count something (again)" ),
744+ cli .Flag (new (int ), "count" , 'c' , "Count something" ),
745+ cli .Flag (new (int ), "count" , 'c' , "Count something (again)" ),
740746 },
741747 errMsg : `flag "count" already defined` ,
742748 },
743749 {
744750 name : "flag short already exists" ,
745751 options : []cli.Option {
746- cli .Flag (new (int ), "count" , 'c' , 0 , "Count something" ),
747- cli .Flag (new (string ), "config" , 'c' , "" , " Path to config file" ),
752+ cli .Flag (new (int ), "count" , 'c' , "Count something" ),
753+ cli .Flag (new (string ), "config" , 'c' , "Path to config file" ),
748754 },
749755 errMsg : `could not add flag "config" to command "test": shorthand "c" already in use for flag "count"` ,
750756 },
@@ -884,8 +890,8 @@ func TestCommandOptionOrder(t *testing.T) {
884890 cli .Arg (new (string ), "third" , "Third arg" ),
885891 cli .Version ("v1.2.3" ),
886892 cli .SubCommands (sub ),
887- cli .Flag (& f , "flag" , 'f' , false , "Set a bool flag" ),
888- cli .Flag (& count , "count" , 'c' , 0 , "Count a thing" ),
893+ cli .Flag (& f , "flag" , 'f' , "Set a bool flag" ),
894+ cli .Flag (& count , "count" , 'c' , "Count a thing" ),
889895 }
890896
891897 baseLineOptions := slices .Concat (
@@ -1001,9 +1007,9 @@ func BenchmarkNew(b *testing.B) {
10011007 cli .Version ("dev" ),
10021008 cli .Commit ("dfdddaf" ),
10031009 cli .Example ("An example" , "bench --help" ),
1004- cli .Flag (new (bool ), "force" , 'f' , false , "Force something" ),
1005- cli .Flag (new (string ), "name" , 'n' , "" , " The name of something" ),
1006- cli .Flag (new (int ), "count" , 'c' , 1 , "Count something" ),
1010+ cli .Flag (new (bool ), "force" , 'f' , "Force something" ),
1011+ cli .Flag (new (string ), "name" , 'n' , "The name of something" ),
1012+ cli .Flag (new (int ), "count" , 'c' , "Count something" , cli . FlagDefault ( 1 ) ),
10071013 cli .Run (func (ctx context.Context , cmd * cli.Command ) error { return nil }),
10081014 )
10091015 if err != nil {
0 commit comments