Skip to content

Commit

Permalink
feat(options): add support for Hidden help message for install-manpag…
Browse files Browse the repository at this point in the history
…e command

Signed-off-by: Derek Smith <drsmith.phys@gmail.com>
  • Loading branch information
clok committed May 1, 2021
1 parent 1893d76 commit 6407ba6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions cdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ type InstallManpageCommandInput struct {
AppName string `required:"true"`
CmdName string `default:"install-command"`
Path string `default:"/usr/local/share/man/man8"`
Hidden bool `default:"false"`
}

// InstallManpageCommand will generate a *cli.Command to be used with a cli.App.
// This will install a manual page (8) to the man-db.
func InstallManpageCommand(opts *InstallManpageCommandInput) (*cli.Command, error) {
name, cmdname, path, err := extractManpageSettings(opts)
name, cmdname, path, hidden, err := extractManpageSettings(opts)
if err != nil {
return nil, err
}
Expand All @@ -98,6 +99,7 @@ func InstallManpageCommand(opts *InstallManpageCommandInput) (*cli.Command, erro
Name: cmdname,
Usage: "Generate and install man page",
UsageText: "NOTE: Windows is not supported",
Hidden: hidden,
Action: func(c *cli.Context) error {
kman.Printf("OS detected: %s", runtime.GOOS)
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -125,14 +127,15 @@ func InstallManpageCommand(opts *InstallManpageCommandInput) (*cli.Command, erro
}

// extractManpageSettings processes the *InstallManpageCommandInput and validates
func extractManpageSettings(opts *InstallManpageCommandInput) (string, string, string, error) {
func extractManpageSettings(opts *InstallManpageCommandInput) (string, string, string, bool, error) {
kim.Printf("passed opts: %# v", opts)
name := opts.AppName
cmdname := opts.CmdName
path := opts.Path
hidden := opts.Hidden

if name == "" {
return "", "", "", fmt.Errorf("AppName is required. Options passed in: %# v", opts)
return "", "", "", hidden, fmt.Errorf("AppName is required. Options passed in: %# v", opts)
}

if path == "" {
Expand All @@ -142,8 +145,8 @@ func extractManpageSettings(opts *InstallManpageCommandInput) (string, string, s
if cmdname == "" {
cmdname = "install-manpage"
}
kim.Printf("name: %s cmdname: %s path: %s", name, cmdname, path)
return name, cmdname, path, nil
kim.Printf("name: %s cmdname: %s path: %s hidden: %t", name, cmdname, path, hidden)
return name, cmdname, path, hidden, nil
}

type cliTemplate struct {
Expand Down
11 changes: 7 additions & 4 deletions cdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func Test_extractManpageSettings(t *testing.T) {
is := assert.New(t)

t.Run("AppName is required", func(t *testing.T) {
_, _, _, err := extractManpageSettings(&InstallManpageCommandInput{
_, _, _, _, err := extractManpageSettings(&InstallManpageCommandInput{
AppName: "",
CmdName: "",
Path: "",
Expand All @@ -349,8 +349,8 @@ func Test_extractManpageSettings(t *testing.T) {
is.Error(err, "AppName is required. Options passed in: &cdocs.InstallManpageCommandInput{AppName:\"\", CmdName:\"\", Path:\"\"}")
})

t.Run("path and command defaults", func(t *testing.T) {
name, cmdname, path, err := extractManpageSettings(&InstallManpageCommandInput{
t.Run("path, command and hidden defaults", func(t *testing.T) {
name, cmdname, path, hidden, err := extractManpageSettings(&InstallManpageCommandInput{
AppName: "test",
CmdName: "",
Path: "",
Expand All @@ -360,19 +360,22 @@ func Test_extractManpageSettings(t *testing.T) {
is.Equal(name, "test")
is.Equal(cmdname, "install-manpage")
is.Equal(path, "/usr/local/share/man/man8")
is.False(hidden)
})

t.Run("all can be set", func(t *testing.T) {
name, cmdname, path, err := extractManpageSettings(&InstallManpageCommandInput{
name, cmdname, path, hidden, err := extractManpageSettings(&InstallManpageCommandInput{
AppName: "test",
CmdName: "test-cmd",
Path: "/a/path",
Hidden: true,
})

is.Nil(err)
is.Equal(name, "test")
is.Equal(cmdname, "test-cmd")
is.Equal(path, "/a/path")
is.True(hidden)
})
}

Expand Down

0 comments on commit 6407ba6

Please sign in to comment.