doc.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Package tagflag uses reflection to derive flags and positional arguments to a
  2. // program, and parses and sets them from a slice of arguments.
  3. //
  4. // For example:
  5. // var opts struct {
  6. // Mmap bool `help:"memory-map torrent data"`
  7. // TestPeer []*net.TCPAddr `help:"addresses of some starting peers"`
  8. // tagflag.StartPos // Marks beginning of positional arguments.
  9. // Torrent []string `arity:"+" help:"torrent file path or magnet uri"`
  10. // }
  11. // tagflag.Parse(&opts)
  12. //
  13. // Supported tags include:
  14. // help: a line of text to show after the option
  15. // arity: defaults to 1. the number of arguments a field requires, or ? for one
  16. // optional argument, + for one or more, or * for zero or more.
  17. //
  18. // MarshalArgs is called on fields that implement ArgsMarshaler. A number of
  19. // arguments matching the arity of the field are passed if possible.
  20. //
  21. // Slices will collect successive values, within the provided arity constraints.
  22. //
  23. // A few helpful types have builtin marshallers, for example Bytes,
  24. // *net.TCPAddr, *url.URL, time.Duration, and net.IP.
  25. //
  26. // Flags are strictly passed with the form -K or -K=V. No space between -K and
  27. // the value is allowed. This allows positional arguments to be mixed in with
  28. // flags, and prevents any confusion due to some flags occasionally not taking
  29. // values. A `--` will terminate flag parsing, and treat all further arguments
  30. // as positional.
  31. //
  32. // A builtin help and usage printer are provided, and activated when passing
  33. // -h or -help.
  34. //
  35. // Flag and positional argument names are automatically munged to fit the
  36. // standard scheme within tagflag.
  37. package tagflag