File: cmd_help.go

package info (click to toggle)
direnv 2.37.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 872 kB
  • sloc: sh: 1,499; csh: 83; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd

import (
	"fmt"
	"strings"
)

// CmdHelp is `direnv help`
var CmdHelp = &Cmd{
	Name:    "help",
	Desc:    "Shows this help",
	Args:    []string{"[SHOW_PRIVATE]"},
	Aliases: []string{"--help"},
	Action: actionSimple(func(_ Env, args []string) (err error) {
		var showPrivate = len(args) > 1
		fmt.Printf(`direnv v%s
Usage: direnv COMMAND [...ARGS]

Available commands
------------------
`, version)
		for _, cmd := range CmdList {
			var opts string
			if len(cmd.Args) > 0 {
				opts = " " + strings.Join(cmd.Args, " ")
			}
			if cmd.Private {
				if showPrivate {
					fmt.Printf("*%s%s:\n  %s\n", cmd.Name, opts, cmd.Desc)
				}
			} else {
				fmt.Printf("%s%s:\n", cmd.Name, opts)
				for _, alias := range cmd.Aliases {
					if alias[0:1] != "-" {
						fmt.Printf("%s%s:\n", alias, opts)
					}
				}
				fmt.Printf("  %s\n", cmd.Desc)
			}
		}

		if showPrivate {
			fmt.Println("* = private commands")
		}
		return
	}),
}