本站源代码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

89 linhas
2.9KB

  1. package pflag
  2. import "strconv"
  3. // -- int16 Value
  4. type int16Value int16
  5. func newInt16Value(val int16, p *int16) *int16Value {
  6. *p = val
  7. return (*int16Value)(p)
  8. }
  9. func (i *int16Value) Set(s string) error {
  10. v, err := strconv.ParseInt(s, 0, 16)
  11. *i = int16Value(v)
  12. return err
  13. }
  14. func (i *int16Value) Type() string {
  15. return "int16"
  16. }
  17. func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) }
  18. func int16Conv(sval string) (interface{}, error) {
  19. v, err := strconv.ParseInt(sval, 0, 16)
  20. if err != nil {
  21. return 0, err
  22. }
  23. return int16(v), nil
  24. }
  25. // GetInt16 returns the int16 value of a flag with the given name
  26. func (f *FlagSet) GetInt16(name string) (int16, error) {
  27. val, err := f.getFlagType(name, "int16", int16Conv)
  28. if err != nil {
  29. return 0, err
  30. }
  31. return val.(int16), nil
  32. }
  33. // Int16Var defines an int16 flag with specified name, default value, and usage string.
  34. // The argument p points to an int16 variable in which to store the value of the flag.
  35. func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) {
  36. f.VarP(newInt16Value(value, p), name, "", usage)
  37. }
  38. // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
  39. func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) {
  40. f.VarP(newInt16Value(value, p), name, shorthand, usage)
  41. }
  42. // Int16Var defines an int16 flag with specified name, default value, and usage string.
  43. // The argument p points to an int16 variable in which to store the value of the flag.
  44. func Int16Var(p *int16, name string, value int16, usage string) {
  45. CommandLine.VarP(newInt16Value(value, p), name, "", usage)
  46. }
  47. // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
  48. func Int16VarP(p *int16, name, shorthand string, value int16, usage string) {
  49. CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage)
  50. }
  51. // Int16 defines an int16 flag with specified name, default value, and usage string.
  52. // The return value is the address of an int16 variable that stores the value of the flag.
  53. func (f *FlagSet) Int16(name string, value int16, usage string) *int16 {
  54. p := new(int16)
  55. f.Int16VarP(p, name, "", value, usage)
  56. return p
  57. }
  58. // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
  59. func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 {
  60. p := new(int16)
  61. f.Int16VarP(p, name, shorthand, value, usage)
  62. return p
  63. }
  64. // Int16 defines an int16 flag with specified name, default value, and usage string.
  65. // The return value is the address of an int16 variable that stores the value of the flag.
  66. func Int16(name string, value int16, usage string) *int16 {
  67. return CommandLine.Int16P(name, "", value, usage)
  68. }
  69. // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
  70. func Int16P(name, shorthand string, value int16, usage string) *int16 {
  71. return CommandLine.Int16P(name, shorthand, value, usage)
  72. }
上海开阖软件有限公司 沪ICP备12045867号-1