12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package main
- import (
- "errors"
- "fmt"
- "os"
- "path/filepath"
- "github.com/pborman/getopt/v2"
- )
- type Options struct {
- Help bool
- Version bool
- Servers []string
- Split bool
- KeepOld bool
- OutputDir string
- }
- func Help() {
- getopt.PrintUsage(os.Stdout)
- os.Exit(0)
- }
- func Version() {
- fmt.Printf("masto-emoji-pack v%s\n", VERSION)
- os.Exit(0)
- }
- func Usage(err error) {
- fmt.Fprintln(os.Stderr, err)
- getopt.Usage()
- os.Exit(2)
- }
- func Parse() {
- if err := getopt.Getopt(nil); err != nil {
- Usage(err)
- }
- }
- func parseOptions() (options Options) {
- getopt.SetParameters("DOMAIN...")
- help := getopt.BoolLong("help", 'h', "show help message")
- version := getopt.BoolLong("version", 'v', "show version info")
- split := getopt.BoolLong("split", 's', "split emoji pack via category")
- keepOld := getopt.BoolLong("keep-old", 'k', "keep old files")
- dir := getopt.StringLong("path", 'p', os.TempDir(), "generate emoji pack directory", "PATH")
- Parse()
- options = Options{
- Help: *help,
- Version: *version,
- Servers: getopt.Args(),
- Split: *split,
- KeepOld: *keepOld,
- OutputDir: filepath.Clean(*dir),
- }
- if options.Help {
- Help()
- }
- if options.Version {
- Version()
- }
- if len(options.Servers) == 0 {
- Usage(errors.New("must be specified: DOMAIN..."))
- }
- return
- }
|