From 6407ba64f9c432ea25d2f0d02516bf89fb8aeeea Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Fri, 30 Apr 2021 22:51:30 -0500 Subject: [PATCH] feat(options): add support for Hidden help message for install-manpage command Signed-off-by: Derek Smith --- cdocs.go | 13 ++++++++----- cdocs_test.go | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cdocs.go b/cdocs.go index 4dbbf36..8f8ccde 100644 --- a/cdocs.go +++ b/cdocs.go @@ -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 } @@ -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" { @@ -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 == "" { @@ -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 { diff --git a/cdocs_test.go b/cdocs_test.go index 090726b..86458b9 100644 --- a/cdocs_test.go +++ b/cdocs_test.go @@ -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: "", @@ -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: "", @@ -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) }) }