From a7ef585e12eb7d96ff27126127c237bec64d64a3 Mon Sep 17 00:00:00 2001 From: iwilltry42 Date: Mon, 6 Apr 2020 16:34:32 +0200 Subject: [PATCH] createCluster: allow 0 or 1 arg Allow 0 or 1 argument for k3d create cluster. If 0, then we'll use the default cluster name. --- cmd/create/createCluster.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/create/createCluster.go b/cmd/create/createCluster.go index 30f1b283..bd7c539c 100644 --- a/cmd/create/createCluster.go +++ b/cmd/create/createCluster.go @@ -48,7 +48,7 @@ func NewCmdCreateCluster() *cobra.Command { Use: "cluster NAME", Short: "Create a new k3s cluster in docker", Long: `Create a new k3s cluster with containerized nodes (k3s in docker).`, - Args: cobra.ExactArgs(1), // exactly one cluster name can be set // TODO: if not specified, use k3d.DefaultClusterName + Args: cobra.RangeArgs(0, 1), // exactly one cluster name can be set (default: k3d.DefaultClusterName) Run: func(cmd *cobra.Command, args []string) { cluster := parseCreateClusterCmd(cmd, args, createClusterOpts) if err := k3dCluster.CreateCluster(cluster, runtimes.SelectedRuntime); err != nil { @@ -116,7 +116,10 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string, createClusterOpts * Parse and validate arguments * ********************************/ - clustername := args[0] + clustername := k3d.DefaultClusterName + if len(args) != 0 { + clustername = args[0] + } if err := cluster.CheckName(clustername); err != nil { log.Fatal(err) }