-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
91 lines (81 loc) · 3.18 KB
/
Copy pathroot.go
File metadata and controls
91 lines (81 loc) · 3.18 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package cmd
import (
"os"
"github.com/spf13/cobra"
"beancount.io/beancount-cli/internal/updater"
cmdaccount "beancount.io/beancount-cli/cmd/account"
cmdauth "beancount.io/beancount-cli/cmd/auth"
cmdbalance "beancount.io/beancount-cli/cmd/balance"
cmdbudget "beancount.io/beancount-cli/cmd/budget"
cmdcheck "beancount.io/beancount-cli/cmd/check"
cmdcollaborator "beancount.io/beancount-cli/cmd/collaborator"
cmdcommodity "beancount.io/beancount-cli/cmd/commodity"
cmddocument "beancount.io/beancount-cli/cmd/document"
cmderror "beancount.io/beancount-cli/cmd/error"
cmdevent "beancount.io/beancount-cli/cmd/event"
cmdledger "beancount.io/beancount-cli/cmd/ledger"
cmdnote "beancount.io/beancount-cli/cmd/note"
cmdprice "beancount.io/beancount-cli/cmd/price"
cmdquery "beancount.io/beancount-cli/cmd/query"
cmdtransaction "beancount.io/beancount-cli/cmd/transaction"
cmdupgrade "beancount.io/beancount-cli/cmd/upgrade"
)
var updateCheckCh <-chan updater.UpdateResult
var rootCmd = &cobra.Command{
Use: "beancount-cli",
Short: "Official CLI for Beancount",
// Dev-only environment variables (not shown in help output):
// BEANCOUNT_API_URL Override the GraphQL endpoint (default: https://beancount.io/api-gateway/)
// BEANCOUNT_DASHBOARD_URL Override the dashboard URL (default: https://beancount.io)
// BEANCOUNT_NO_UPDATE_NOTIFIER Set to any value to disable update notifications
Long: `beancount-cli is the official command-line interface for Beancount.
Use it to authenticate and interact with your beancount.io account.`,
// Don't print usage on every RunE error — the error message is sufficient.
SilenceUsage: true,
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
if cmd.Name() != "upgrade" {
updateCheckCh = updater.StartUpdateCheck(cmd.Root().Version)
}
},
PersistentPostRun: func(cmd *cobra.Command, _ []string) {
if cmd.Name() == "upgrade" || updateCheckCh == nil {
return
}
select {
case result := <-updateCheckCh:
updater.PrintUpdateTip(os.Stderr, result)
default:
}
},
}
// SetVersion sets the version string shown by --version.
func SetVersion(v string) {
rootCmd.Version = v
}
// Execute runs the root command and exits on error.
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.AddCommand(cmdaccount.NewCmdAccount())
rootCmd.AddCommand(cmdcollaborator.NewCmdCollaborator())
rootCmd.AddCommand(cmdauth.NewCmdLogin())
rootCmd.AddCommand(cmdauth.NewCmdLogout())
rootCmd.AddCommand(cmdauth.NewCmdWhoami())
rootCmd.AddCommand(cmdbalance.NewCmdBalance())
rootCmd.AddCommand(cmdbudget.NewCmdBudget())
rootCmd.AddCommand(cmdcheck.NewCmdCheck())
rootCmd.AddCommand(cmdcommodity.NewCmdCommodity())
rootCmd.AddCommand(cmddocument.NewCmdDocument())
rootCmd.AddCommand(cmdevent.NewCmdEvent())
rootCmd.AddCommand(cmderror.NewCmdError())
rootCmd.AddCommand(cmdledger.NewCmdLedger())
rootCmd.AddCommand(cmdnote.NewCmdNote())
rootCmd.AddCommand(cmdprice.NewCmdPrice())
rootCmd.AddCommand(cmdquery.NewCmdBeanQuery())
rootCmd.AddCommand(cmdquery.NewCmdQuery())
rootCmd.AddCommand(cmdtransaction.NewCmdTransaction())
rootCmd.AddCommand(cmdupgrade.NewCmdUpgrade(&rootCmd.Version))
}