12
"github.com/lxc/lxd/shared/gnuflag"
13
"github.com/lxc/lxd/shared/i18n"
20
func (c *helpCmd) showByDefault() bool {
24
func (c *helpCmd) usage() string {
26
`Presents details on how to use LXD.
31
func (c *helpCmd) flags() {
32
gnuflag.BoolVar(&c.showAll, "all", false, i18n.G("Show all commands (not just interesting ones)"))
35
func (c *helpCmd) run(_ *lxd.Config, args []string) error {
37
for _, name := range args {
38
cmd, ok := commands[name]
40
fmt.Fprintf(os.Stderr, i18n.G("error: unknown command: %s")+"\n", name)
42
fmt.Fprintf(os.Stderr, cmd.usage()+"\n")
48
fmt.Println(i18n.G("Usage: lxc [subcommand] [options]"))
49
fmt.Println(i18n.G("Available commands:"))
51
for name := range commands {
52
names = append(names, name)
55
for _, name := range names {
57
if c.showAll || cmd.showByDefault() {
58
fmt.Printf("\t%-10s - %s\n", name, c.summaryLine(cmd.usage()))
63
fmt.Println(i18n.G("Options:"))
64
fmt.Println(" --all " + i18n.G("Print less common commands."))
65
fmt.Println(" --debug " + i18n.G("Print debug information."))
66
fmt.Println(" --verbose " + i18n.G("Print verbose information."))
68
fmt.Println(i18n.G("Environment:"))
69
fmt.Println(" LXD_CONF " + i18n.G("Path to an alternate client configuration directory."))
70
fmt.Println(" LXD_DIR " + i18n.G("Path to an alternate server directory."))
75
// summaryLine returns the first line of the help text. Conventionally, this
76
// should be a one-line command summary, potentially followed by a longer
78
func (c *helpCmd) summaryLine(usage string) string {
79
usage = strings.TrimSpace(usage)
80
s := bufio.NewScanner(bytes.NewBufferString(usage))
82
if len(s.Text()) > 1 {
86
return i18n.G("Missing summary.")