Skip to content

Commit 2487574

Browse files
swalkinshawclaude
andcommitted
Mark droplet commands as deprecated in help output
Add deprecatedCommandHelpFunc to display deprecated commands in a separate section at the bottom of the help output. The droplet commands are now listed under "Deprecated commands" instead of in the main command list. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5c01dcc commit 2487574

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

help.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"sort"
7+
"strings"
8+
9+
"github.com/hashicorp/cli"
10+
)
11+
12+
func deprecatedCommandHelpFunc(commandNames []string, f cli.HelpFunc) cli.HelpFunc {
13+
return func(commands map[string]cli.CommandFactory) string {
14+
var buf bytes.Buffer
15+
if len(commandNames) > 0 {
16+
buf.WriteString("\n\nDeprecated commands:\n")
17+
}
18+
19+
maxKeyLen := 0
20+
keys := make([]string, 0, len(commandNames))
21+
filteredCommands := make(map[string]cli.CommandFactory)
22+
23+
for key, command := range commands {
24+
for _, deprecatedKey := range commandNames {
25+
if key != deprecatedKey {
26+
filteredCommands[key] = command
27+
}
28+
}
29+
}
30+
31+
for _, key := range commandNames {
32+
if len(key) > maxKeyLen {
33+
maxKeyLen = len(key)
34+
}
35+
36+
keys = append(keys, key)
37+
}
38+
39+
sort.Strings(keys)
40+
41+
for _, key := range keys {
42+
commandFunc, _ := commands[key]
43+
command, _ := commandFunc()
44+
key = fmt.Sprintf("%s%s", key, strings.Repeat(" ", maxKeyLen-len(key)))
45+
buf.WriteString(fmt.Sprintf(" %s %s\n", key, command.Synopsis()))
46+
}
47+
48+
return f(filteredCommands) + buf.String()
49+
}
50+
}

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
// To be replaced by goreleaser build flags.
2020
var version = "canary"
2121
var updaterRepo = ""
22+
var deprecatedCommands = []string{
23+
"droplet",
24+
}
2225

2326
func main() {
2427
c := cli.NewCLI("trellis", version)
@@ -215,7 +218,7 @@ func main() {
215218
}
216219

217220
c.HiddenCommands = []string{"venv", "venv hook"}
218-
c.HelpFunc = cli.BasicHelpFunc("trellis")
221+
c.HelpFunc = deprecatedCommandHelpFunc(deprecatedCommands, cli.BasicHelpFunc("trellis"))
219222

220223
if trellis.CliConfig.LoadPlugins {
221224
pluginPaths := filepath.SplitList(os.Getenv("PATH"))

0 commit comments

Comments
 (0)