설명 없음

flags.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // StringList implements the plugin.FlagSet interface.
  40. func (*GoFlags) StringList(o, d, c string) *[]*string {
  41. return &[]*string{flag.String(o, d, c)}
  42. }
  43. // ExtraUsage implements the plugin.FlagSet interface.
  44. func (f *GoFlags) ExtraUsage() string {
  45. return strings.Join(f.UsageMsgs, "\n")
  46. }
  47. // AddExtraUsage implements the plugin.FlagSet interface.
  48. func (f *GoFlags) AddExtraUsage(eu string) {
  49. f.UsageMsgs = append(f.UsageMsgs, eu)
  50. }
  51. // Parse implements the plugin.FlagSet interface.
  52. func (*GoFlags) Parse(usage func()) []string {
  53. flag.Usage = usage
  54. flag.Parse()
  55. args := flag.Args()
  56. if len(args) == 0 {
  57. usage()
  58. }
  59. return args
  60. }