Files
obitools4/pkg/obioptions/options.go

47 lines
862 B
Go
Raw Normal View History

2022-01-13 23:27:39 +01:00
package obioptions
import (
"fmt"
"os"
"github.com/DavidGamba/go-getoptions"
)
var __debug__ = false
type ArgumentParser func([]string) (*getoptions.GetOpt, []string, error)
func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser {
options := getoptions.New()
options.Bool("help", false, options.Alias("h", "?"))
options.BoolVar(&__debug__, "debug", false)
for _, o := range optionset {
o(options)
}
return func(args []string) (*getoptions.GetOpt, []string, error) {
remaining, err := options.Parse(args[1:])
if options.Called("help") {
2022-01-14 16:10:19 +01:00
fmt.Fprint(os.Stderr, options.Help())
2022-01-13 23:27:39 +01:00
os.Exit(1)
}
return options, remaining, err
}
}
// Predicate indicating if the debug mode is activated
func IsDebugMode() bool {
return __debug__
}
func DebugOn() {
__debug__ = true
}
func DebugOff() {
__debug__ = false
}