blob: 780b8dd95d7071ae5ebbe4192c491eca050b9448 [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 Zalegadb75e212022-08-04 17:31:34 +020028 // format refers to how the output data, except logs, is formatted.
29 format string
30 // filter specifies a CEL filter used to narrow down the set of output
31 // objects.
32 filter string
33 // output is an optional output file path the resulting data will be saved
34 // at. If unspecified, the data will be written to stdout.
35 output string
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020036}
37
38var flags metroctlFlags
39
40func init() {
41 rootCmd.PersistentFlags().StringArrayVar(&flags.clusterEndpoints, "endpoints", nil, "A list of the target cluster's endpoints.")
Mateusz Zalegaf7774962022-07-08 12:26:55 +020042 rootCmd.PersistentFlags().StringVar(&flags.proxyAddr, "proxy", "", "SOCKS5 proxy address")
Mateusz Zalega8234c162022-07-08 17:05:50 +020043 rootCmd.PersistentFlags().StringVar(&flags.configPath, "config", filepath.Join(xdg.ConfigHome, "metroctl"), "An alternative cluster config path")
Mateusz Zalegab2cac082022-07-14 14:55:43 +020044 rootCmd.PersistentFlags().BoolVar(&flags.verbose, "verbose", false, "Log additional runtime information")
Mateusz Zalegadb75e212022-08-04 17:31:34 +020045 rootCmd.PersistentFlags().StringVarP(&flags.format, "format", "f", "plaintext", "Data output format")
46 rootCmd.PersistentFlags().StringVar(&flags.filter, "filter", "", "The object filter applied to the output data")
47 rootCmd.PersistentFlags().StringVarP(&flags.output, "output", "o", "", "Redirects output to the specified file")
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020048}
49
Mateusz Zalega18a67b02022-08-02 13:37:50 +020050// rpcLogger passes through the cluster resolver logs, if "--verbose" flag was
51// used.
52func rpcLogger(f string, args ...interface{}) {
53 if flags.verbose {
54 log.Printf("resolver: " + f, args...)
55 }
56}
57
Lorenz Brun6adf8842021-10-05 13:39:11 +020058func main() {
59 cobra.CheckErr(rootCmd.Execute())
60}