Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/verda-cli/cmd/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func NewCmdS3(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command {
Show current S3 credential status:
verda s3 show
`),
Run: cmdutil.DefaultSubCommandRun(ioStreams.Out),
Annotations: map[string]string{cmdutil.TagAnnotation: "beta"},
Run: cmdutil.DefaultSubCommandRun(ioStreams.Out),
}

cmd.AddCommand(
Expand Down
10 changes: 9 additions & 1 deletion internal/verda-cli/cmd/util/command_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"github.com/spf13/cobra"
)

// TagAnnotation marks a command with a short status label (e.g. "beta") shown
// next to its name in the grouped root help. Set via cmd.Annotations.
const TagAnnotation = "verda.tag"

// CommandGroup represents a logical group of subcommands with a heading message.
type CommandGroup struct {
Message string
Expand Down Expand Up @@ -84,7 +88,11 @@ func SetUsageTemplate(cmd *cobra.Command, groups CommandGroups) {
if c.Hidden {
continue
}
fmt.Fprintf(&b, " %-18s %s\n", c.Name(), c.Short)
name := c.Name()
if tag := c.Annotations[TagAnnotation]; tag != "" {
name += " (" + tag + ")"
}
fmt.Fprintf(&b, " %-18s %s\n", name, c.Short)
}
b.WriteString("\n")
}
Expand Down
43 changes: 43 additions & 0 deletions internal/verda-cli/cmd/util/command_groups_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2026 Verda Cloud Oy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
"strings"
"testing"

"github.com/spf13/cobra"
)

// TestSetUsageTemplate_TagAnnotation verifies a command's TagAnnotation renders
// as "name (tag)" in the grouped help, while untagged commands stay plain.
func TestSetUsageTemplate_TagAnnotation(t *testing.T) {
t.Parallel()
tagged := &cobra.Command{Use: "s3", Short: "Manage S3 object storage",
Annotations: map[string]string{TagAnnotation: "beta"}}
plain := &cobra.Command{Use: "volume", Short: "Manage volumes"}
root := &cobra.Command{Use: "verda"}
groups := CommandGroups{{Message: "Resource Commands:", Commands: []*cobra.Command{tagged, plain}}}
groups.Add(root)
SetUsageTemplate(root, groups)

tmpl := root.UsageTemplate()
if !strings.Contains(tmpl, "s3 (beta)") {
t.Errorf("tagged command should render as \"s3 (beta)\"; got:\n%s", tmpl)
}
if strings.Contains(tmpl, "volume (") {
t.Errorf("untagged command must not get a tag; got:\n%s", tmpl)
}
}