m/c/metroctl: implement the "list" command
list prints node IDs of existing nodes.
If no positional arguments are passed, or the only positional argument
equals "all", all existing nodes will be processed.
Otherwise, if any positional arguments are used, the output set will
be limited to node IDs matching the positional arguments. Nonexistent
nodes will not be listed.
The node set can be further narrowed with an optional CEL node filter
expression, set with the new --filter flag.
The output format can be adjusted using the --format (-f) flag.
Currently, only plaintext output is available.
The output will be saved to a file, if a path is specified with the
--output (-o) flag.
Change-Id: I44d57ad52805924673354c70e54cd299a88ad75f
Reviewed-on: https://review.monogon.dev/c/monogon/+/848
Tested-by: Jenkins CI
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/metropolis/cli/metroctl/main.go b/metropolis/cli/metroctl/main.go
index 949eb63..780b8dd 100644
--- a/metropolis/cli/metroctl/main.go
+++ b/metropolis/cli/metroctl/main.go
@@ -25,6 +25,14 @@
// verbose, if set, will make this utility log additional runtime
// information.
verbose bool
+ // format refers to how the output data, except logs, is formatted.
+ format string
+ // filter specifies a CEL filter used to narrow down the set of output
+ // objects.
+ filter string
+ // output is an optional output file path the resulting data will be saved
+ // at. If unspecified, the data will be written to stdout.
+ output string
}
var flags metroctlFlags
@@ -34,6 +42,9 @@
rootCmd.PersistentFlags().StringVar(&flags.proxyAddr, "proxy", "", "SOCKS5 proxy address")
rootCmd.PersistentFlags().StringVar(&flags.configPath, "config", filepath.Join(xdg.ConfigHome, "metroctl"), "An alternative cluster config path")
rootCmd.PersistentFlags().BoolVar(&flags.verbose, "verbose", false, "Log additional runtime information")
+ rootCmd.PersistentFlags().StringVarP(&flags.format, "format", "f", "plaintext", "Data output format")
+ rootCmd.PersistentFlags().StringVar(&flags.filter, "filter", "", "The object filter applied to the output data")
+ rootCmd.PersistentFlags().StringVarP(&flags.output, "output", "o", "", "Redirects output to the specified file")
}
// rpcLogger passes through the cluster resolver logs, if "--verbose" flag was