| 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 |
|
| 15 |
package driver |
| 16 |
|
| 17 |
import ( |
| 18 |
"flag" |
| 19 |
"strings" |
| 20 |
) |
| 21 |
|
| 22 |
// GoFlags implements the plugin.FlagSet interface. |
| 23 |
type GoFlags struct { |
| 24 |
UsageMsgs []string |
| 25 |
} |
| 26 |
|
| 27 |
// Bool implements the plugin.FlagSet interface. |
| 28 |
func (*GoFlags) Bool(o string, d bool, c string) *bool { |
| 29 |
return flag.Bool(o, d, c) |
| 30 |
} |
| 31 |
|
| 32 |
// Int implements the plugin.FlagSet interface. |
| 33 |
func (*GoFlags) Int(o string, d int, c string) *int { |
| 34 |
return flag.Int(o, d, c) |
| 35 |
} |
| 36 |
|
| 37 |
// Float64 implements the plugin.FlagSet interface. |
| 38 |
func (*GoFlags) Float64(o string, d float64, c string) *float64 { |
| 39 |
return flag.Float64(o, d, c) |
| 40 |
} |
| 41 |
|
| 42 |
// String implements the plugin.FlagSet interface. |
| 43 |
func (*GoFlags) String(o, d, c string) *string { |
| 44 |
return flag.String(o, d, c) |
| 45 |
} |
| 46 |
|
| 47 |
// StringList implements the plugin.FlagSet interface. |
| 48 |
func (*GoFlags) StringList(o, d, c string) *[]*string { |
| 49 |
return &[]*string{flag.String(o, d, c)} |
| 50 |
} |
| 51 |
|
| 52 |
// ExtraUsage implements the plugin.FlagSet interface. |
| 53 |
func (f *GoFlags) ExtraUsage() string { |
| 54 |
return strings.Join(f.UsageMsgs, "\n") |
| 55 |
} |
| 56 |
|
| 57 |
// AddExtraUsage implements the plugin.FlagSet interface. |
| 58 |
func (f *GoFlags) AddExtraUsage(eu string) { |
| 59 |
f.UsageMsgs = append(f.UsageMsgs, eu) |
| 60 |
} |
| 61 |
|
| 62 |
// Parse implements the plugin.FlagSet interface. |
| 63 |
func (*GoFlags) Parse(usage func()) []string { |
| 64 |
flag.Usage = usage |
| 65 |
flag.Parse() |
| 66 |
args := flag.Args() |
| 67 |
if len(args) == 0 { |
| 68 |
usage() |
| 69 |
} |
| 70 |
return args |
| 71 |
} |