summaryrefslogtreecommitdiff
path: root/flags.go
blob: 3967da8989ee753abda7826648a2f770696aa370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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"},
	{"regenerate", "Regenerate all files generated by comitium without checking for new updates."},
	{"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),
	"regenerate": flag.NewFlagSet("regenerate", flag.ExitOnError),
	"add":        flag.NewFlagSet("add", flag.ExitOnError),
	"remove":     flag.NewFlagSet("remove", flag.ExitOnError),
}

// set up various flags for each individual command
var (
	// add
	addPageFlag = commands["add"].BoolP(
		"watch", "w",
		false,
		`Watch a page instead of adding it as a feed.`,
	)

	// refresh
	refreshWorkersFlag = commands["refresh"].IntP(
		"num-workers", "n",
		5, // 5 workers is a safe default
		`Number of worker threads to use when refreshing feeds. More is faster,
but there are more concurrent outgoing requests then.`,
	)
	refreshTimeoutFlag = commands["refresh"].IntP(
		"timeout", "t",
		10,
		`Set a timeout for requests, in seconds.`,
	)

	// remove
	removeFeedsFlag = commands["remove"].BoolP(
		"feeds", "f",
		false,
		`Remove URL from subscribed feeds.`,
	)
	removePagesFlag = commands["remove"].BoolP(
		"pages", "p",
		false,
		`remove URL from subscribed pages.`,
	)
)