diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ca7558d..7456d004f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changelog for NeoFS Node ### Added - Config examples for Inner ring application (#1358) +- Command for documentation generation for `neofs-cli`, `neofs-adm` and `neofs-lens` (#1396) ### Fixed - Do not ask for contract wallet password twice (#1346) diff --git a/cmd/neofs-adm/internal/modules/root.go b/cmd/neofs-adm/internal/modules/root.go index 4322e6c70..2234fc3d6 100644 --- a/cmd/neofs-adm/internal/modules/root.go +++ b/cmd/neofs-adm/internal/modules/root.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/storagecfg" "github.com/nspcc-dev/neofs-node/misc" "github.com/nspcc-dev/neofs-node/pkg/util/autocomplete" + "github.com/nspcc-dev/neofs-node/pkg/util/gendoc" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -42,6 +43,7 @@ func init() { rootCmd.AddCommand(storagecfg.RootCmd) rootCmd.AddCommand(autocomplete.Command("neofs-adm")) + rootCmd.AddCommand(gendoc.Command(rootCmd)) } func Execute() error { diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 11a7d5851..49b798e1c 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -18,6 +18,7 @@ import ( bearerCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/bearer" sessionCli "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/modules/session" "github.com/nspcc-dev/neofs-node/misc" + "github.com/nspcc-dev/neofs-node/pkg/util/gendoc" "github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/owner" @@ -93,6 +94,7 @@ func init() { rootCmd.AddCommand(bearerCli.Cmd) rootCmd.AddCommand(sessionCli.Cmd) rootCmd.AddCommand(accountingCli.Cmd) + rootCmd.AddCommand(gendoc.Command(rootCmd)) } func entryPoint(cmd *cobra.Command, _ []string) { diff --git a/cmd/neofs-lens/root.go b/cmd/neofs-lens/root.go index f27ae7744..8cfdd9c39 100644 --- a/cmd/neofs-lens/root.go +++ b/cmd/neofs-lens/root.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/commands/inspect" cmdlist "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/commands/list" "github.com/nspcc-dev/neofs-node/misc" + "github.com/nspcc-dev/neofs-node/pkg/util/gendoc" "github.com/spf13/cobra" ) @@ -36,6 +37,7 @@ func init() { command.AddCommand( cmdlist.Command, inspect.Command, + gendoc.Command(command), ) } diff --git a/go.mod b/go.mod index b7044cf26..55b3304ef 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/prometheus/client_golang v1.11.0 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.3 + github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.8.1 github.com/stretchr/testify v1.7.0 go.etcd.io/bbolt v1.3.6 @@ -80,7 +81,6 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/afero v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect github.com/twmb/murmur3 v1.1.5 // indirect diff --git a/pkg/util/gendoc/gendoc.go b/pkg/util/gendoc/gendoc.go new file mode 100644 index 000000000..59c36fd34 --- /dev/null +++ b/pkg/util/gendoc/gendoc.go @@ -0,0 +1,144 @@ +package gendoc + +import ( + "errors" + "fmt" + "io/ioutil" + "os" + "path/filepath" + "strings" + "text/template" + + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" + "github.com/spf13/pflag" +) + +const ( + gendocTypeFlag = "type" + + gendocMarkdown = "md" + gendocMan = "man" + + depthFlag = "depth" + extensionFlag = "extension" +) + +// Command returns command which generates user documentation for the argument. +func Command(rootCmd *cobra.Command) *cobra.Command { + gendocCmd := &cobra.Command{ + Use: "gendoc