diff options
| author | nytpu <alex@nytpu.com> | 2021-03-16 10:20:31 -0600 |
|---|---|---|
| committer | nytpu <alex@nytpu.com> | 2021-03-16 10:24:36 -0600 |
| commit | 91e663c0f0ec4e1e61a2493f6ab08850cd2e5a2e (patch) | |
| tree | cfc8f3e4db20d48085be41485ffcf411b9441920 /flags.go | |
| parent | f82e0905779c9d88140403778f7b3b35a1d03420 (diff) | |
add command parsing
Diffstat (limited to 'flags.go')
| -rw-r--r-- | flags.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..7f28bed --- /dev/null +++ b/flags.go @@ -0,0 +1,49 @@ +// Copyright (C) 2021 nytpu +// SPDX-License-Identifier: AGPL-3.0-or-later +// For more license details, see LICENSE or <https://www.gnu.org/licenses/agpl-3.0.html>. + +package main + +import flag "github.com/spf13/pflag" + +// globalFs contains the flags that are used in every command. +var ( + globalFs = flag.NewFlagSet("global", flag.ContinueOnError) + + dataFlag = globalFs.StringP("data", "d", "", "The data directory where comitium will store its files") +) + +// command holds fields used for printing information about a command. +type command struct { + Name string + Usage string +} + +// info about all the accepted commands +var commandInfo = []command{ + {"refresh", "Check for new updates to subscriptions"}, + {"list", "List all subscriptions"}, + {"add", "Add a new subscription"}, + {"remove", "Remove a subscription"}, + {"help", "Print usage information"}, + {"version", "Print version information"}, +} + +var commands = map[string]*flag.FlagSet{ + "refresh": flag.NewFlagSet("refresh", flag.ExitOnError), + "list": flag.NewFlagSet("list", flag.ExitOnError), + "add": flag.NewFlagSet("add", flag.ExitOnError), + "remove": flag.NewFlagSet("remove", flag.ExitOnError), +} + +// set up various flags for each individual command +var ( + // add + addTypeFlag = commands["add"].StringP( + "type", "t", // long and shorthand flag + "g", // default + `Select which type a subscription is. Can be "g" for a +Gemini feed; "a" for Atom, RSS, & JSON; or "c" to watch +the page for changes.`, + ) +) |
