You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
9 months ago
|
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)
|
||
|
}
|