blob: 949eb637581b7d7c96ca839af2b17b3fe021f82b [file] [log] [blame]
Lorenz Brun6adf8842021-10-05 13:39:11 +02001package main
2
3import (
Mateusz Zalega18a67b02022-08-02 13:37:50 +02004 "log"
Mateusz Zalega8234c162022-07-08 17:05:50 +02005 "path/filepath"
6
7 "github.com/adrg/xdg"
Lorenz Brun6adf8842021-10-05 13:39:11 +02008 "github.com/spf13/cobra"
9)
10
11// rootCmd represents the base command when called without any subcommands
12var rootCmd = &cobra.Command{
13 Use: "metroctl",
14 Short: "metroctl controls Metropolis nodes and clusters.",
15}
16
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020017type metroctlFlags struct {
18 // clusterEndpoints is a list of the targeted cluster's endpoints, used by
19 // commands that perform RPC on it.
20 clusterEndpoints []string
Mateusz Zalegaf7774962022-07-08 12:26:55 +020021 // proxyAddr is a SOCKS5 proxy address the cluster will be accessed through.
22 proxyAddr string
Mateusz Zalega8234c162022-07-08 17:05:50 +020023 // configPath overrides the default XDG config path
24 configPath string
Mateusz Zalegab2cac082022-07-14 14:55:43 +020025 // verbose, if set, will make this utility log additional runtime
26 // information.
27 verbose bool
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020028}
29
30var flags metroctlFlags
31
32func init() {
33 rootCmd.PersistentFlags().StringArrayVar(&flags.clusterEndpoints, "endpoints", nil, "A list of the target cluster's endpoints.")
Mateusz Zalegaf7774962022-07-08 12:26:55 +020034 rootCmd.PersistentFlags().StringVar(&flags.proxyAddr, "proxy", "", "SOCKS5 proxy address")
Mateusz Zalega8234c162022-07-08 17:05:50 +020035 rootCmd.PersistentFlags().StringVar(&flags.configPath, "config", filepath.Join(xdg.ConfigHome, "metroctl"), "An alternative cluster config path")
Mateusz Zalegab2cac082022-07-14 14:55:43 +020036 rootCmd.PersistentFlags().BoolVar(&flags.verbose, "verbose", false, "Log additional runtime information")
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020037}
38
Mateusz Zalega18a67b02022-08-02 13:37:50 +020039// rpcLogger passes through the cluster resolver logs, if "--verbose" flag was
40// used.
41func rpcLogger(f string, args ...interface{}) {
42 if flags.verbose {
43 log.Printf("resolver: " + f, args...)
44 }
45}
46
Lorenz Brun6adf8842021-10-05 13:39:11 +020047func main() {
48 cobra.CheckErr(rootCmd.Execute())
49}