package rags_test import ( "flag" "os" "edge-infra.dev/pkg/lib/cli/rags" ) func ExampleRagSet_Usage() { // Using a RagSet as a drop-in replacement for FlagSet while leveraging // rich-flag specific functionality. var ( rs = rags.New("example-flag-usage", flag.ContinueOnError) _ = rs.String("foo", "", "special flag foo boy", rags.WithCategory("special")) _ = rs.String("bar", "foo", "super special copy flag", rags.WithCategory("special"), rags.WithShort("b")) _ = rs.Bool("reqfoo", true, "required foo", rags.WithRequired()) _ = rs.Bool("required2", false, "you'll need me too", rags.WithRequired()) _ = rs.String("shortie", "tallboi", "peep my short flag", rags.WithShort("s")) _ = rs.Bool("reg", true, "just a regular ol flag type beat") _ = rs.Bool("reg2", false, "another reggie") ) rs.SetOutput(os.Stdout) rs.Usage() } func ExampleNew_addOnCreate() { var ( enabled bool target string ) // Add flags declaratively when creating the RagSet rs := rags.New("example-add-flags", flag.ContinueOnError, &rags.Rag{Name: "enable", Short: "e", Value: &rags.Bool{Var: &enabled}}, &rags.Rag{Name: "target", Required: true, Value: &rags.String{Var: &target}}, ) // Add flags imperatively _ = rs.Bool("imperative-enable", false, "added with FlagSet drop-in replacement") } func ExampleNew_addAfterCreate() { var ( enabled bool target string ) // Add flags declaratively after creating the RagSet rs := rags.New("example-add-flags", flag.ContinueOnError) rs.Add( &rags.Rag{Name: "enable", Short: "e", Value: &rags.Bool{Var: &enabled}}, &rags.Rag{Name: "target", Required: true, Value: &rags.String{Var: &target}}, ) // Add flags imperatively _ = rs.Bool("imperative-enable", false, "added FlagSet-style") }