34 lines
656 B
Go
34 lines
656 B
Go
package flags
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/jessevdk/go-flags"
|
|
)
|
|
|
|
type Options struct {
|
|
Config string `short:"c" long:"config" description:"Configuration file location" value-name:"FILE"`
|
|
PidFile string `short:"p" long:"pid" description:"PID file location"`
|
|
|
|
InterfaceName string
|
|
}
|
|
|
|
func ParseFlags() (*Options, error) {
|
|
o := new(Options)
|
|
args, err := flags.Parse(o)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
o.InterfaceName = args[0]
|
|
if o.Config == "" {
|
|
o.Config = fmt.Sprintf(DefaultConfigFile, o.InterfaceName)
|
|
}
|
|
if o.PidFile == "" {
|
|
o.PidFile = fmt.Sprintf(DefaultPidFile, o.InterfaceName)
|
|
}
|
|
}
|
|
|
|
return o, err
|
|
}
|