package main import ( "fmt" "os" "git.cheetah.cat/archivinator-ng/workerclient/commands" "git.cheetah.cat/archivinator-ng/workerclient/common" "git.cheetah.cat/archivinator-ng/workerclient/settings" "github.com/jessevdk/go-flags" ) func main() { var err error common.WorkerSettings, err = settings.LoadSettings() if err != nil { panic("config corrupt") } parser := flags.NewParser(&commands.ArchivinatorNG, flags.HelpFlag|flags.PassDoubleDash) parser.NamespaceDelimiter = "-" helpParser := flags.NewParser(&commands.ArchivinatorNG, flags.HelpFlag) helpParser.NamespaceDelimiter = "-" _, err = parser.Parse() handleError(helpParser, err) } func handleError(helpParser *flags.Parser, err error) { if err != nil { if err == commands.ErrShowHelpMessage { showHelp(helpParser) } else if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrCommandRequired { showHelp(helpParser) } else if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { fmt.Println(err) os.Exit(0) } else { fmt.Printf("error: %s\n", err) } os.Exit(1) } } func showHelp(helpParser *flags.Parser) { helpParser.ParseArgs([]string{"-h"}) helpParser.WriteHelp(os.Stdout) os.Exit(0) }