Skip to content

Commit df5c7ac

Browse files
committed
enforce --label in namespace update
1 parent f3b142a commit df5c7ac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cmd/nerdctl/namespace/namespace_update.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package namespace
1818

1919
import (
20+
"errors"
21+
2022
"github.com/spf13/cobra"
2123

2224
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
@@ -34,7 +36,7 @@ func newNamespacelabelUpdateCommand() *cobra.Command {
3436
SilenceUsage: true,
3537
SilenceErrors: true,
3638
}
37-
namespaceLabelCommand.Flags().StringArrayP("label", "l", nil, "Set labels for a namespace")
39+
namespaceLabelCommand.Flags().StringArrayP("label", "l", nil, "Set labels for a namespace (required)")
3840
return namespaceLabelCommand
3941
}
4042

@@ -47,6 +49,11 @@ func processNamespaceUpdateCommandOption(cmd *cobra.Command) (types.NamespaceUpd
4749
if err != nil {
4850
return types.NamespaceUpdateOptions{}, err
4951
}
52+
53+
if (len(labels) == 0) {
54+
return types.NamespaceUpdateOptions{}, errors.New("use \"--label\" or \"-l\" to specify labels for namespace");
55+
}
56+
5057
return types.NamespaceUpdateOptions{
5158
GOptions: globalOptions,
5259
Labels: labels,

0 commit comments

Comments
 (0)