You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
2.5 KiB

  1. // Copyright 2018 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package driver
  15. import (
  16. "flag"
  17. "strings"
  18. )
  19. // GoFlags implements the plugin.FlagSet interface.
  20. type GoFlags struct {
  21. UsageMsgs []string
  22. }
  23. // Bool implements the plugin.FlagSet interface.
  24. func (*GoFlags) Bool(o string, d bool, c string) *bool {
  25. return flag.Bool(o, d, c)
  26. }
  27. // Int implements the plugin.FlagSet interface.
  28. func (*GoFlags) Int(o string, d int, c string) *int {
  29. return flag.Int(o, d, c)
  30. }
  31. // Float64 implements the plugin.FlagSet interface.
  32. func (*GoFlags) Float64(o string, d float64, c string) *float64 {
  33. return flag.Float64(o, d, c)
  34. }
  35. // String implements the plugin.FlagSet interface.
  36. func (*GoFlags) String(o, d, c string) *string {
  37. return flag.String(o, d, c)
  38. }
  39. // BoolVar implements the plugin.FlagSet interface.
  40. func (*GoFlags) BoolVar(b *bool, o string, d bool, c string) {
  41. flag.BoolVar(b, o, d, c)
  42. }
  43. // IntVar implements the plugin.FlagSet interface.
  44. func (*GoFlags) IntVar(i *int, o string, d int, c string) {
  45. flag.IntVar(i, o, d, c)
  46. }
  47. // Float64Var implements the plugin.FlagSet interface.
  48. // the value of the flag.
  49. func (*GoFlags) Float64Var(f *float64, o string, d float64, c string) {
  50. flag.Float64Var(f, o, d, c)
  51. }
  52. // StringVar implements the plugin.FlagSet interface.
  53. func (*GoFlags) StringVar(s *string, o, d, c string) {
  54. flag.StringVar(s, o, d, c)
  55. }
  56. // StringList implements the plugin.FlagSet interface.
  57. func (*GoFlags) StringList(o, d, c string) *[]*string {
  58. return &[]*string{flag.String(o, d, c)}
  59. }
  60. // ExtraUsage implements the plugin.FlagSet interface.
  61. func (f *GoFlags) ExtraUsage() string {
  62. return strings.Join(f.UsageMsgs, "\n")
  63. }
  64. // AddExtraUsage implements the plugin.FlagSet interface.
  65. func (f *GoFlags) AddExtraUsage(eu string) {
  66. f.UsageMsgs = append(f.UsageMsgs, eu)
  67. }
  68. // Parse implements the plugin.FlagSet interface.
  69. func (*GoFlags) Parse(usage func()) []string {
  70. flag.Usage = usage
  71. flag.Parse()
  72. args := flag.Args()
  73. if len(args) == 0 {
  74. usage()
  75. }
  76. return args
  77. }