~samwhited/cli

ref: e61e7fcaa94afc5f08431923c74acc39a79fecbc cli/example_article_test.go -rw-r--r-- 1.4 KiB
e61e7fcaSam Whited cli: fix typo in docs 1 year, 20 days ago
                                                                                
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2017 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package cli_test

import (
	"fmt"

	"mellium.im/cli"
)

// Returns a help article about the config file format.
func articleHelp() *cli.Command {
	return &cli.Command{
		Usage: `article`,
		Description: `Help article about help articles.

Help articles are "commands" that do not provide any functionality. They
only exist so that their description can be shown using the help command
(or your own help system):

    $ ./yourcmd help articlename`,
	}
}

func Example_articles() {
	cmds := &cli.Command{
		Usage: "git <command>",
		Commands: []*cli.Command{
			commitCmd(nil),
			articleHelp(),
		},
	}
	cmds.Commands = append(cmds.Commands, cli.Help(cmds))
	fmt.Println("$ git help")
	cmds.Exec("help")

	fmt.Print("$ git help article\n\n")
	cmds.Exec("help", "article")

	// Output:
	// $ git help
	// Usage: git <command>
	//
	// Commands:
	//
	//	commit	Records changes to the repository.
	//	help	Print articles and detailed information about subcommands.
	//
	// Articles:
	//
	//	article	Help article about help articles.
	// $ git help article
	//
	// Help article about help articles.
	//
	// Help articles are "commands" that do not provide any functionality. They
	// only exist so that their description can be shown using the help command
	// (or your own help system):
	//
	//     $ ./yourcmd help articlename
}