Skip to content

Commit 4a782da

Browse files
committed
feat: show help text when invoked with no arguments
1 parent c6cd6d9 commit 4a782da

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func SetVersion(version, commit string) {
103103
rootCmd.Version = version + " (" + commit + ")"
104104
}
105105

106+
// PrintHelp prints the root command's help text.
107+
func PrintHelp() {
108+
rootCmd.Help()
109+
}
110+
106111
// Execute runs the root command. It is the single entry point called by main.
107112
func Execute() error {
108113
return rootCmd.Execute()

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ var (
1717
// main initialises the version string and delegates to the Cobra command tree.
1818
func main() {
1919
cmd.SetVersion(version, commit)
20+
if len(os.Args) == 1 {
21+
cmd.PrintHelp()
22+
return
23+
}
2024
if err := cmd.Execute(); err != nil {
2125
os.Exit(1)
2226
}

0 commit comments

Comments
 (0)