From 301082cdd7d9338592014dd05acece7f4f838e0b Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Sun, 6 Jul 2025 16:34:49 +0200 Subject: [PATCH] add docstring for node patterns Signed-off-by: Tobias Ribizel --- internal/app/wwctl/node/list/root.go | 3 ++- internal/app/wwctl/node/sensors/root.go | 3 ++- internal/app/wwctl/node/set/root.go | 3 ++- internal/app/wwctl/power/cycle/root.go | 3 ++- internal/app/wwctl/power/off/root.go | 3 ++- internal/app/wwctl/power/on/root.go | 3 ++- internal/app/wwctl/power/reset/root.go | 3 ++- internal/app/wwctl/power/soft/root.go | 5 +++-- internal/app/wwctl/power/status/root.go | 3 ++- internal/app/wwctl/ssh/root.go | 3 ++- internal/pkg/hostlist/hostlist.go | 2 ++ 11 files changed, 23 insertions(+), 11 deletions(-) diff --git a/internal/app/wwctl/node/list/root.go b/internal/app/wwctl/node/list/root.go index 3d8e35c8..80e2666e 100644 --- a/internal/app/wwctl/node/list/root.go +++ b/internal/app/wwctl/node/list/root.go @@ -3,6 +3,7 @@ package list import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -21,7 +22,7 @@ func GetCommand() *cobra.Command { Use: "list [OPTIONS] [PATTERN]", Short: "List nodes", Long: "This command lists all configured nodes. Optionally, it will list only\n" + - "nodes matching a PATTERN.", + "nodes matching a PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Aliases: []string{"ls"}, ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/node/sensors/root.go b/internal/app/wwctl/node/sensors/root.go index a75a5aa1..572bc2a5 100644 --- a/internal/app/wwctl/node/sensors/root.go +++ b/internal/app/wwctl/node/sensors/root.go @@ -3,6 +3,7 @@ package sensors import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -18,7 +19,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "sensors [OPTIONS] PATTERN", Short: "Show node IPMI sensor information", - Long: "Show IPMI sensor information for nodes matching PATTERN.", + Long: "Show IPMI sensor information for nodes matching PATTERN.\n" + hostlist.Docstring, Args: cobra.MinimumNArgs(1), RunE: CobraRunE(&vars), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 7da68e93..f6af5cf7 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -5,6 +5,7 @@ import ( "github.com/warewulf/warewulf/internal/app/wwctl/completions" "github.com/warewulf/warewulf/internal/app/wwctl/flags" "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -23,7 +24,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "set [OPTIONS] PATTERN", Short: "Configure node properties", - Long: "This command sets configuration properties for nodes matching PATTERN.\n\nNote: use the string 'UNSET' to remove a configuration", + Long: "This command sets configuration properties for nodes matching PATTERN.\n\nNote: use the string 'UNSET' to remove a configuration\n" + hostlist.Docstring, Aliases: []string{"modify"}, Args: cobra.MinimumNArgs(1), // require pattern as a mandatory arg RunE: CobraRunE(&vars), diff --git a/internal/app/wwctl/power/cycle/root.go b/internal/app/wwctl/power/cycle/root.go index 77fa0461..2bc35e01 100644 --- a/internal/app/wwctl/power/cycle/root.go +++ b/internal/app/wwctl/power/cycle/root.go @@ -3,6 +3,7 @@ package cycle import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -17,7 +18,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "cycle [OPTIONS] [PATTERN ...]", Short: "Power cycle the given node(s)", - Long: "This command cycles power for a set of nodes specified by PATTERN.", + Long: "This command cycles power for a set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/power/off/root.go b/internal/app/wwctl/power/off/root.go index ee647342..1f0e73f1 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -3,6 +3,7 @@ package off import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -17,7 +18,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "off [OPTIONS] [PATTERN ...]", Short: "Power off the given node(s)", - Long: "This command will shutdown power to a set of nodes specified by PATTERN.", + Long: "This command will shutdown power to a set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/power/on/root.go b/internal/app/wwctl/power/on/root.go index 1111f160..737e7ae0 100644 --- a/internal/app/wwctl/power/on/root.go +++ b/internal/app/wwctl/power/on/root.go @@ -3,6 +3,7 @@ package on import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -16,7 +17,7 @@ func GetCommand() *cobra.Command { powerCmd := &cobra.Command{ Use: "on [OPTIONS] [PATTERN ...]", Short: "Power on the given node(s)", - Long: "This command will power on a set of nodes specified by PATTERN.", + Long: "This command will power on a set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/power/reset/root.go b/internal/app/wwctl/power/reset/root.go index d7dd5506..49ab1a00 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -3,6 +3,7 @@ package reset import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -17,7 +18,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "reset [OPTIONS] [PATTERN ...]", Short: "Issue a reset to node(s)", - Long: "This command will issue a reset to a set of nodes specified by PATTERN.", + Long: "This command will issue a reset to a set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/power/soft/root.go b/internal/app/wwctl/power/soft/root.go index faea9c02..02837a62 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -3,6 +3,7 @@ package soft import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -15,9 +16,9 @@ func GetCommand() *cobra.Command { vars := variables{} powerCmd := &cobra.Command{ DisableFlagsInUseLine: true, - Use: "soft", + Use: "soft [OPTIONS] [PATTERN ...]", Short: "Gracefully shuts down the given node(s)", - Long: "This command uses the operating system to shut down the set of nodes specified by PATTERN.", + Long: "This command uses the operating system to shut down the set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/power/status/root.go b/internal/app/wwctl/power/status/root.go index 6b0c6a37..23667355 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -3,6 +3,7 @@ package status import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) type variables struct { @@ -17,7 +18,7 @@ func GetCommand() *cobra.Command { DisableFlagsInUseLine: true, Use: "status [OPTIONS] [PATTERN ...]", Short: "Show power status for the given node(s)", - Long: "This command displays the power status of a set of nodes specified by PATTERN.", + Long: "This command displays the power status of a set of nodes specified by PATTERN.\n" + hostlist.Docstring, RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), ValidArgsFunction: completions.Nodes, diff --git a/internal/app/wwctl/ssh/root.go b/internal/app/wwctl/ssh/root.go index b7c5bc5b..7244839e 100644 --- a/internal/app/wwctl/ssh/root.go +++ b/internal/app/wwctl/ssh/root.go @@ -3,6 +3,7 @@ package ssh import ( "github.com/spf13/cobra" "github.com/warewulf/warewulf/internal/app/wwctl/completions" + "github.com/warewulf/warewulf/internal/pkg/hostlist" ) var ( @@ -10,7 +11,7 @@ var ( DisableFlagsInUseLine: true, Use: "ssh [OPTIONS] NODE_PATTERN COMMAND", Short: "SSH into configured nodes in parallel", - Long: "Easily ssh into nodes in parallel to run non-interactive commands\n", + Long: "Easily ssh into nodes in parallel to run non-interactive commands\n" + hostlist.Docstring, RunE: CobraRunE, Args: cobra.MinimumNArgs(2), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/internal/pkg/hostlist/hostlist.go b/internal/pkg/hostlist/hostlist.go index 11ce93c1..e3e1897d 100644 --- a/internal/pkg/hostlist/hostlist.go +++ b/internal/pkg/hostlist/hostlist.go @@ -6,6 +6,8 @@ import ( "strings" ) +const Docstring = "Node patterns are a comma-separated list of individual pattern. Each pattern can either be a full node name or a node range like node[01-03,05]." + // Expand takes a slice of host strings, possibly containing comma-separated // values and bracketed ranges (e.g. "node[01-03]") and returns a fully expanded // slice of host names.