From 9a3e48fa37914fd78da46b53a303d40d277771e1 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Mon, 24 Mar 2025 21:06:07 -0600 Subject: [PATCH] Explicitly enforce the number or arguments accepted by some `wwctl` subcommands. #1717 Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + internal/app/wwclient/root.go | 1 + internal/app/wwctl/configure/root.go | 1 + internal/app/wwctl/image/delete/root.go | 1 + internal/app/wwctl/image/list/root.go | 1 + internal/app/wwctl/image/root.go | 1 + internal/app/wwctl/node/edit/root.go | 1 + internal/app/wwctl/node/export/root.go | 1 + internal/app/wwctl/node/list/root.go | 1 + internal/app/wwctl/node/root.go | 1 + internal/app/wwctl/node/status/root.go | 1 + internal/app/wwctl/overlay/build/root.go | 1 + internal/app/wwctl/overlay/list/root.go | 1 + internal/app/wwctl/overlay/root.go | 1 + internal/app/wwctl/power/root.go | 1 + internal/app/wwctl/profile/add/root.go | 1 + internal/app/wwctl/profile/edit/root.go | 1 + internal/app/wwctl/profile/list/root.go | 1 + internal/app/wwctl/profile/root.go | 1 + internal/app/wwctl/profile/set/root.go | 1 + internal/app/wwctl/root.go | 1 + 21 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4fc3acf..9e473c02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Update GitHub actions to build aarch64 artifacts. +- Explicitly enforce the number or arguments accepted by some `wwctl` subcommands. #1717 ### Removed diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index 24cf04ff..a8c5afd5 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -31,6 +31,7 @@ var ( Long: "wwclient fetches the runtime overlay and puts it on the disk", RunE: CobraRunE, SilenceUsage: true, + Args: cobra.NoArgs, } DebugFlag bool PIDFile string diff --git a/internal/app/wwctl/configure/root.go b/internal/app/wwctl/configure/root.go index 40a84e02..3abd0776 100644 --- a/internal/app/wwctl/configure/root.go +++ b/internal/app/wwctl/configure/root.go @@ -17,6 +17,7 @@ var ( Long: "This application allows you to manage and initialize Warewulf dependent system\n" + "services based on the configuration in the warewulf.conf file.", RunE: CobraRunE, + Args: cobra.NoArgs, } allFunctions bool ) diff --git a/internal/app/wwctl/image/delete/root.go b/internal/app/wwctl/image/delete/root.go index 7fd1efb3..20ad8dcd 100644 --- a/internal/app/wwctl/image/delete/root.go +++ b/internal/app/wwctl/image/delete/root.go @@ -13,6 +13,7 @@ var ( Short: "Delete an imported image", Long: "This command will delete IMAGEs that have been imported into Warewulf.", RunE: CobraRunE, + Args: cobra.ArbitraryArgs, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp diff --git a/internal/app/wwctl/image/list/root.go b/internal/app/wwctl/image/list/root.go index 6e5c5aea..57504b30 100644 --- a/internal/app/wwctl/image/list/root.go +++ b/internal/app/wwctl/image/list/root.go @@ -23,6 +23,7 @@ func GetCommand() *cobra.Command { Long: "This command will show you the images that are imported into Warewulf.", RunE: CobraRunE(&vars), Aliases: []string{"ls"}, + Args: cobra.ArbitraryArgs, ValidArgsFunction: completions.Images, } baseCmd.PersistentFlags().BoolVarP(&vars.full, "long", "l", false, "show all") diff --git a/internal/app/wwctl/image/root.go b/internal/app/wwctl/image/root.go index f8eefe33..f26fecf9 100644 --- a/internal/app/wwctl/image/root.go +++ b/internal/app/wwctl/image/root.go @@ -23,6 +23,7 @@ var baseCmd = &cobra.Command{ "node images. These commands will help you import, manage, and transform\n" + "images into bootable Warewulf images.", Aliases: []string{"vnfs", "container"}, + Args: cobra.NoArgs, } func init() { diff --git a/internal/app/wwctl/node/edit/root.go b/internal/app/wwctl/node/edit/root.go index c095b6b7..f80cae69 100644 --- a/internal/app/wwctl/node/edit/root.go +++ b/internal/app/wwctl/node/edit/root.go @@ -13,6 +13,7 @@ var ( Long: "This command opens an editor for the given nodes.", RunE: CobraRunE, ValidArgsFunction: completions.Nodes, + Args: cobra.ArbitraryArgs, } NoHeader bool ) diff --git a/internal/app/wwctl/node/export/root.go b/internal/app/wwctl/node/export/root.go index c3cccd35..bc62d306 100644 --- a/internal/app/wwctl/node/export/root.go +++ b/internal/app/wwctl/node/export/root.go @@ -13,6 +13,7 @@ var ( Long: "This command exports the given nodes as yaml to stdout.", RunE: CobraRunE, ValidArgsFunction: completions.Nodes, + Args: cobra.ArbitraryArgs, } NoHeader bool ) diff --git a/internal/app/wwctl/node/list/root.go b/internal/app/wwctl/node/list/root.go index bf8805c4..3d8e35c8 100644 --- a/internal/app/wwctl/node/list/root.go +++ b/internal/app/wwctl/node/list/root.go @@ -25,6 +25,7 @@ func GetCommand() *cobra.Command { RunE: CobraRunE(&vars), Aliases: []string{"ls"}, ValidArgsFunction: completions.Nodes, + Args: cobra.ArbitraryArgs, } baseCmd.PersistentFlags().BoolVarP(&vars.showNet, "net", "n", false, "Show node network configurations") baseCmd.PersistentFlags().BoolVarP(&vars.showIpmi, "ipmi", "i", false, "Show node IPMI configurations") diff --git a/internal/app/wwctl/node/root.go b/internal/app/wwctl/node/root.go index 062f630b..c71e1451 100644 --- a/internal/app/wwctl/node/root.go +++ b/internal/app/wwctl/node/root.go @@ -23,6 +23,7 @@ var ( "node ranges. For example: n00[00-4].cluster[0-1] will identify the first 5 nodes\n" + "in cluster0 and cluster1.", Aliases: []string{"nodes"}, + Args: cobra.NoArgs, } ) diff --git a/internal/app/wwctl/node/status/root.go b/internal/app/wwctl/node/status/root.go index d6cfd4d1..0ccb3dc7 100644 --- a/internal/app/wwctl/node/status/root.go +++ b/internal/app/wwctl/node/status/root.go @@ -13,6 +13,7 @@ var ( Long: "View and monitor the status of nodes as they are provisioned and check in.", RunE: CobraRunE, ValidArgsFunction: completions.Nodes, + Args: cobra.ArbitraryArgs, } SetWatch bool SetUpdate int diff --git a/internal/app/wwctl/overlay/build/root.go b/internal/app/wwctl/overlay/build/root.go index 2c4fac86..041da655 100644 --- a/internal/app/wwctl/overlay/build/root.go +++ b/internal/app/wwctl/overlay/build/root.go @@ -13,6 +13,7 @@ var ( Long: "This command builds overlays for given nodes.", RunE: CobraRunE, ValidArgsFunction: completions.Nodes, + Args: cobra.ArbitraryArgs, } OverlayNames []string OverlayDir string diff --git a/internal/app/wwctl/overlay/list/root.go b/internal/app/wwctl/overlay/list/root.go index ff8fb903..d5031e1d 100644 --- a/internal/app/wwctl/overlay/list/root.go +++ b/internal/app/wwctl/overlay/list/root.go @@ -14,6 +14,7 @@ var ( RunE: CobraRunE, Aliases: []string{"ls"}, ValidArgsFunction: completions.Overlays, + Args: cobra.ArbitraryArgs, } ListContents bool ListLong bool diff --git a/internal/app/wwctl/overlay/root.go b/internal/app/wwctl/overlay/root.go index cbf6ca67..529da93c 100644 --- a/internal/app/wwctl/overlay/root.go +++ b/internal/app/wwctl/overlay/root.go @@ -20,6 +20,7 @@ var ( Use: "overlay COMMAND [OPTIONS]", Short: "Warewulf Overlay Management", Long: "Management interface for Warewulf overlays", + Args: cobra.NoArgs, } ) diff --git a/internal/app/wwctl/power/root.go b/internal/app/wwctl/power/root.go index 180ab219..58347b70 100644 --- a/internal/app/wwctl/power/root.go +++ b/internal/app/wwctl/power/root.go @@ -16,6 +16,7 @@ var ( Use: "power COMMAND [OPTIONS]", Short: "Warewulf node power management", Long: "This command controls the power state of nodes.", + Args: cobra.NoArgs, } ) diff --git a/internal/app/wwctl/profile/add/root.go b/internal/app/wwctl/profile/add/root.go index 255bcef8..ad415aa7 100644 --- a/internal/app/wwctl/profile/add/root.go +++ b/internal/app/wwctl/profile/add/root.go @@ -24,6 +24,7 @@ func GetCommand() *cobra.Command { Aliases: []string{"new", "create"}, RunE: CobraRunE(&vars), ValidArgsFunction: completions.None, + Args: cobra.MinimumNArgs(1), } vars.profileConf.CreateFlags(baseCmd) vars.profileAdd.CreateAddFlags(baseCmd) diff --git a/internal/app/wwctl/profile/edit/root.go b/internal/app/wwctl/profile/edit/root.go index 078c9cc1..4b4c323b 100644 --- a/internal/app/wwctl/profile/edit/root.go +++ b/internal/app/wwctl/profile/edit/root.go @@ -13,6 +13,7 @@ var ( Long: "This command opens an editor for the given profiles.", RunE: CobraRunE, ValidArgsFunction: completions.Profiles, + Args: cobra.ArbitraryArgs, } NoHeader bool ) diff --git a/internal/app/wwctl/profile/list/root.go b/internal/app/wwctl/profile/list/root.go index 86468943..91cc7492 100644 --- a/internal/app/wwctl/profile/list/root.go +++ b/internal/app/wwctl/profile/list/root.go @@ -22,6 +22,7 @@ func GetCommand() *cobra.Command { RunE: CobraRunE(&vars), Aliases: []string{"ls"}, ValidArgsFunction: completions.Profiles, + Args: cobra.ArbitraryArgs, } baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all profile configurations") baseCmd.PersistentFlags().BoolVarP(&vars.showYaml, "yaml", "y", false, "Show profile configurations via yaml format") diff --git a/internal/app/wwctl/profile/root.go b/internal/app/wwctl/profile/root.go index 4cd354ca..19092929 100644 --- a/internal/app/wwctl/profile/root.go +++ b/internal/app/wwctl/profile/root.go @@ -15,6 +15,7 @@ var ( Use: "profile COMMAND [OPTIONS]", Short: "Node configuration profile management", Long: "Management of node profile settings", + Args: cobra.NoArgs, } ) diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index df76aab6..6627ff21 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -35,6 +35,7 @@ func GetCommand() *cobra.Command { Aliases: []string{"modify"}, RunE: CobraRunE(&vars), ValidArgsFunction: completions.Profiles, + Args: cobra.ArbitraryArgs, } vars.profileConf.CreateFlags(baseCmd) vars.profileDel.CreateDelFlags(baseCmd) diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 7e464333..a0e18b2a 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -30,6 +30,7 @@ var ( PersistentPreRunE: rootPersistentPreRunE, SilenceUsage: true, SilenceErrors: true, + Args: cobra.NoArgs, } verboseArg bool DebugFlag bool