2020-01-19 06:06:00 +00:00
|
|
|
package arguments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var FlagName = "command"
|
|
|
|
|
|
|
|
type FlagSet struct {
|
|
|
|
*flag.FlagSet
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFlagSet() *FlagSet {
|
|
|
|
fs := flag.NewFlagSet(FlagName, flag.ContinueOnError)
|
|
|
|
fs.SetOutput(ioutil.Discard)
|
|
|
|
|
|
|
|
return &FlagSet{fs}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fs *FlagSet) Usage() string {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
fs.FlagSet.SetOutput(&buf)
|
|
|
|
fs.FlagSet.Usage()
|
|
|
|
fs.FlagSet.SetOutput(ioutil.Discard)
|
|
|
|
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:01:48 +00:00
|
|
|
type Flag []string
|
2020-01-19 06:06:00 +00:00
|
|
|
|
|
|
|
func (f *Flag) ParseContent(arguments []string) error {
|
2020-05-15 01:01:48 +00:00
|
|
|
*f = arguments
|
2020-01-19 06:06:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:01:48 +00:00
|
|
|
func (f Flag) Usage() string {
|
|
|
|
return "[flags] arguments"
|
2020-01-19 06:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:01:48 +00:00
|
|
|
func (f Flag) Args() []string {
|
|
|
|
return f
|
2020-01-19 06:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:01:48 +00:00
|
|
|
func (f Flag) With(fs *flag.FlagSet) error {
|
|
|
|
return fs.Parse(f)
|
2020-01-19 06:06:00 +00:00
|
|
|
}
|