mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-20 04:14:32 +09:00
cli: print only the required keys with generate config --minimal
With every other key defaulted, server_url alone is a configuration. Updates #1926
This commit is contained in:
1 parent
73127e4baa
commit
cac78c856b
4 files changed
+104
-3
No files matched your search
@@ -20,6 +20,8 @@ func init() {
|
||||
|
||||
generateConfigCmd.Flags().Bool("no-docs", false, "Leave out the documentation comments")
|
||||
generateConfigCmd.Flags().Bool("running", false, "Print the running server's configuration, secrets redacted, instead of the defaults")
|
||||
generateConfigCmd.Flags().Bool("minimal", false, "Print only the keys every server must set")
|
||||
generateConfigCmd.MarkFlagsMutuallyExclusive("minimal", "running")
|
||||
generateCmd.AddCommand(generateConfigCmd)
|
||||
|
||||
generateNixOSOptionsCmd.Flags().Bool("release", false, "Stamp the version and commit of this binary, which must be a clean build of a known commit")
|
||||
@@ -57,7 +59,8 @@ var generateConfigCmd = &cobra.Command{
|
||||
Short: "Print a configuration file with every key",
|
||||
Long: `Print a YAML configuration with every key, its default and its
|
||||
documentation as comments, e.g. for "> /etc/headscale/config.yaml". Set the
|
||||
keys marked "Required" before starting headscale.
|
||||
keys marked "Required" before starting headscale. With --minimal, print only
|
||||
those keys.
|
||||
|
||||
With --running, print instead the configuration of the running server,
|
||||
without the client-only cli section: literal secrets, DNS provider settings
|
||||
@@ -67,6 +70,7 @@ kept as written.`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
noDocs, _ := cmd.Flags().GetBool("no-docs")
|
||||
running, _ := cmd.Flags().GetBool("running")
|
||||
minimal, _ := cmd.Flags().GetBool("minimal")
|
||||
|
||||
if running {
|
||||
return printRunningConfig(cmd, !noDocs)
|
||||
@@ -74,7 +78,7 @@ kept as written.`,
|
||||
|
||||
d := config.Default()
|
||||
|
||||
out, err := config.GenerateExample(&d, config.ExampleOptions{Docs: !noDocs})
|
||||
out, err := config.GenerateExample(&d, config.ExampleOptions{Docs: !noDocs, Minimal: minimal})
|
||||
if err != nil {
|
||||
return fmt.Errorf("generating config: %w", err)
|
||||
}
|
||||
|
||||
@@ -303,6 +303,10 @@ func TestGenerateConfigCommand(t *testing.T) {
|
||||
{name: "example", args: []string{"generate", "config"}, wantStdout: []string{"# Every key"}, wantLoaded: true},
|
||||
{name: "alias", args: []string{"gen", "config"}, wantLoaded: true},
|
||||
{name: "no docs", args: []string{"generate", "config", "--no-docs"}, hideStdout: []string{"#"}, wantLoaded: true},
|
||||
{name: "minimal", args: []string{"generate", "config", "--minimal"}, wantStdout: []string{`server_url: ""`}, hideStdout: []string{"listen_addr"}, wantLoaded: true},
|
||||
{name: "minimal no docs", args: []string{"generate", "config", "--minimal", "--no-docs"}, wantExact: "server_url: \"\"\n"},
|
||||
// Cobra's flag-group error.
|
||||
{name: "minimal running", args: []string{"-c", ok, "generate", "config", "--minimal", "--running"}, wantErr: true, wantStderr: []string{"none of the others can be"}},
|
||||
{name: "running", args: []string{"-c", ok, "generate", "config", "--running"}, wantExact: running, wantStderr: []string{warning}},
|
||||
{name: "running no docs", args: []string{"-c", ok, "generate", "config", "--running", "--no-docs"}, wantExact: runningNoDocs, wantStderr: []string{warning}},
|
||||
{name: "running log level error", args: []string{"-c", logging("error", "level: error"), "generate", "config", "--running"}, wantExact: running, wantStderr: []string{warning}},
|
||||
|
||||
Reference in new issue
Block a user