From d1bd7508f48e6a0dbb668fa86aa25cff00fca3b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:00:04 -0600 Subject: [PATCH 1/3] Bump github.com/rs/zerolog from 1.30.0 to 1.31.0 (#1691) * Bump github.com/rs/zerolog from 1.30.0 to 1.31.0 Bumps [github.com/rs/zerolog](https://github.com/rs/zerolog) from 1.30.0 to 1.31.0. - [Release notes](https://github.com/rs/zerolog/releases) - [Commits](https://github.com/rs/zerolog/compare/v1.30.0...v1.31.0) --- updated-dependencies: - dependency-name: github.com/rs/zerolog dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Updated Changelog --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] --- CHANGELOG.md | 2 +- go.mod | 6 +++--- go.sum | 14 ++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be724b0a83..1c99b0d748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,7 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - Bump `bufbuild/buf-setup-action` from 1.25.1 to 1.26.0 ([#1645](https://github.com/provenance-io/provenance/pull/1645)) - Bump `bufbuild/buf-setup-action` from 1.25.0 to 1.25.1 ([#1642](https://github.com/provenance-io/provenance/pull/1642)) - Bump `google.golang.org/grpc` from 1.56.2 to 1.57.0 ([#1635](https://github.com/provenance-io/provenance/pull/1635)) -- Bump `github.com/rs/zerolog` from 1.29.1 to 1.30.0 ([#1639](https://github.com/provenance-io/provenance/pull/1639)) +- Bump `github.com/rs/zerolog` from 1.29.1 to 1.31.0 ([#1639](https://github.com/provenance-io/provenance/pull/1639), [#1691](https://github.com/provenance-io/provenance/pull/1691)) - Bump `bufbuild/buf-setup-action` from 1.24.0 to 1.25.0 ([#1632](https://github.com/provenance-io/provenance/pull/1632)) - Bump `bufbuild/buf-setup-action` from 1.23.1 to 1.24.0 ([#1631](https://github.com/provenance-io/provenance/pull/1631)) - Bump `github.com/cosmos/ibc-go/v6` from 6.1.1 to 6.2.0 ([#1629](https://github.com/provenance-io/provenance/pull/1629)) diff --git a/go.mod b/go.mod index f767d38067..33a38e633c 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/otiai10/copy v1.12.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 - github.com/rs/zerolog v1.30.0 + github.com/rs/zerolog v1.31.0 github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 @@ -124,7 +124,7 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/manifoldco/promptui v0.9.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect github.com/minio/highwayhash v1.0.2 // indirect @@ -161,7 +161,7 @@ require ( golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.10.0 // indirect + golang.org/x/sys v0.12.0 // indirect golang.org/x/term v0.10.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect diff --git a/go.sum b/go.sum index 0e0347725c..39c3b678a3 100644 --- a/go.sum +++ b/go.sum @@ -834,7 +834,6 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -845,8 +844,8 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= -github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -1028,8 +1027,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= -github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1445,7 +1444,6 @@ golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1467,8 +1465,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= From 7eb06e56b47563db469001429e95fe655e1fe6b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:43:36 -0600 Subject: [PATCH 2/3] Bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#1689) * Bump google.golang.org/grpc from 1.58.1 to 1.58.2 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.58.1 to 1.58.2. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.1...v1.58.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Updated Changelog --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] Co-authored-by: Ira Miller <72319+iramiller@users.noreply.github.com> --- CHANGELOG.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c99b0d748..187649dc59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,7 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Dependencies -- Bump `google.golang.org/grpc` from 1.57.0 to 1.58.1 ([#1672](https://github.com/provenance-io/provenance/pull/1672), [#1685](https://github.com/provenance-io/provenance/pull/1685)) +- Bump `google.golang.org/grpc` from 1.57.0 to 1.58.2 ([#1672](https://github.com/provenance-io/provenance/pull/1672), [#1685](https://github.com/provenance-io/provenance/pull/1685), [#1689](https://github.com/provenance-io/provenance/pull/1689)) - Bump `crazy-max/ghaction-import-gpg` from 5 to 6 ([#1677](https://github.com/provenance-io/provenance/pull/1677)) - Bump `golang.org/x/text` from 0.12.0 to 0.13.0 ([#1667](https://github.com/provenance-io/provenance/pull/1667)) - Bump `actions/checkout` from 3 to 4 ([#1668](https://github.com/provenance-io/provenance/pull/1668)) diff --git a/go.mod b/go.mod index 33a38e633c..bf0128d8dc 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 golang.org/x/text v0.13.0 google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 - google.golang.org/grpc v1.58.1 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 39c3b678a3..245f3211be 100644 --- a/go.sum +++ b/go.sum @@ -1790,8 +1790,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58= -google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= From 28948e8800788b000de7efa4d0a8b9042d63eef3 Mon Sep 17 00:00:00 2001 From: Matt Witkowski Date: Wed, 27 Sep 2023 15:08:36 -0400 Subject: [PATCH 3/3] Add DocGen command (#1688) * Added all needed pieces to build feature. * Added additional logic. * Update usage and long help for command. * Add tests for docgen, but still need to verify generated contents. * Finish tests for docgen command. * Lint code. * Changelog entry. * Fix typo in test. * Add test for invalid target directory. * Add tests for invalid flag values. * Rename rest to rst to improve clarity. --------- Co-authored-by: Ira Miller <72319+iramiller@users.noreply.github.com> --- CHANGELOG.md | 1 + cmd/provenanced/cmd/docgen.go | 103 ++++++++++++++++ cmd/provenanced/cmd/docgen_test.go | 186 +++++++++++++++++++++++++++++ cmd/provenanced/cmd/root.go | 1 + go.mod | 2 + go.sum | 2 + 6 files changed, 295 insertions(+) create mode 100644 cmd/provenanced/cmd/docgen.go create mode 100644 cmd/provenanced/cmd/docgen_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 187649dc59..c76ef19324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ Management of holds is internal, but there are queries for looking up holds on accounts. Holds are also reflected in the `x/bank` module's `SpendableBalances` query. * Add new MaxSupply param to marker module and deprecate MaxTotalSupply. [#1292](https://github.com/provenance-io/provenance/issues/1292). +* Add hidden docgen command to output documentation in different formats. [#1468](https://github.com/provenance-io/provenance/issues/1468). ### Improvements diff --git a/cmd/provenanced/cmd/docgen.go b/cmd/provenanced/cmd/docgen.go new file mode 100644 index 0000000000..f59b6e1ea1 --- /dev/null +++ b/cmd/provenanced/cmd/docgen.go @@ -0,0 +1,103 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" + + "github.com/cosmos/cosmos-sdk/version" +) + +var docGenCmdStart = fmt.Sprintf("%s docgen", version.AppName) + +const ( + FlagMarkdown = "markdown" + FlagYaml = "yaml" + FlagRst = "rst" + FlagManpage = "manpage" +) + +func GetDocGenCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "docgen (--markdown) (--yaml) (--rst) (--manpages) [flags]", + Short: "Generates cli documentation for the Provenance Blockchain.", + Long: `Generates cli documentation for the Provenance Blockchain. +Various documentation formats can be generated, including markdown, YAML, RST, and man pages. +To ensure the command's success, you must specify at least one format. +A successful command will not only generate files in the selected formats but also create the target directory if it doesn't already exist.`, + Example: fmt.Sprintf("%s '/tmp' --yaml --markdown", docGenCmdStart), + Hidden: true, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + markdown, err := cmd.Flags().GetBool(FlagMarkdown) + if err != nil { + return err + } + yaml, err := cmd.Flags().GetBool(FlagYaml) + if err != nil { + return err + } + rst, err := cmd.Flags().GetBool(FlagRst) + if err != nil { + return err + } + manpage, err := cmd.Flags().GetBool(FlagManpage) + if err != nil { + return err + } + + if !markdown && !yaml && !rst && !manpage { + return fmt.Errorf("at least one doc type must be specified") + } + + dir := args[0] + if !exists(dir) { + err = os.Mkdir(dir, 0755) + if err != nil { + return err + } + } + + if markdown { + err = doc.GenMarkdownTree(cmd.Root(), dir) + if err != nil { + return err + } + } + if yaml { + err = doc.GenYamlTree(cmd.Root(), dir) + if err != nil { + return err + } + } + if rst { + err = doc.GenReSTTree(cmd.Root(), dir) + if err != nil { + return err + } + } + if manpage { + err = doc.GenManTree(cmd.Root(), nil, dir) + if err != nil { + return err + } + } + + return nil + }, + } + + cmd.Flags().Bool(FlagMarkdown, false, "Generate documentation in the format of markdown pages.") + cmd.Flags().Bool(FlagYaml, false, "Generate documentation in the format of yaml.") + cmd.Flags().Bool(FlagRst, false, "Generate documentation in the format of rst.") + cmd.Flags().Bool(FlagManpage, false, "Generate documentation in the format of manpages.") + + return cmd +} + +func exists(dir string) bool { + _, err := os.Stat(dir) + return err == nil +} diff --git a/cmd/provenanced/cmd/docgen_test.go b/cmd/provenanced/cmd/docgen_test.go new file mode 100644 index 0000000000..9b92feda7e --- /dev/null +++ b/cmd/provenanced/cmd/docgen_test.go @@ -0,0 +1,186 @@ +package cmd_test + +import ( + "context" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/server" + sdksim "github.com/cosmos/cosmos-sdk/simapp" + genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil" + provenancecmd "github.com/provenance-io/provenance/cmd/provenanced/cmd" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" +) + +func TestDocGen(t *testing.T) { + tests := []struct { + name string + target string + createTarget bool + flags []string + err string + extensions []string + }{ + { + name: "failure - no flags specified", + target: "tmp", + createTarget: true, + err: "at least one doc type must be specified", + }, + { + name: "failure - unsupported flag format", + target: "tmp", + flags: []string{"--bad"}, + createTarget: true, + err: "unknown flag: --bad", + }, + { + name: "failure - invalid target directory", + target: "/tmp/tmp2/tmp3", + flags: []string{"--yaml"}, + createTarget: false, + err: "mkdir %s: no such file or directory", + }, + { + name: "failure - bad yaml value", + target: "tmp", + createTarget: true, + flags: []string{"--yaml=xyz"}, + err: "invalid argument \"xyz\" for \"--yaml\" flag: strconv.ParseBool: parsing \"xyz\": invalid syntax", + }, + { + name: "failure - bad rst value", + target: "tmp", + createTarget: true, + flags: []string{"--rst=xyz"}, + err: "invalid argument \"xyz\" for \"--rst\" flag: strconv.ParseBool: parsing \"xyz\": invalid syntax", + }, + { + name: "failure - bad markdown value", + target: "tmp", + createTarget: true, + flags: []string{"--markdown=xyz"}, + err: "invalid argument \"xyz\" for \"--markdown\" flag: strconv.ParseBool: parsing \"xyz\": invalid syntax", + }, + { + name: "failure - bad manpage value", + target: "tmp", + createTarget: true, + flags: []string{"--manpage=xyz"}, + err: "invalid argument \"xyz\" for \"--manpage\" flag: strconv.ParseBool: parsing \"xyz\": invalid syntax", + }, + { + name: "success - yaml is generated", + target: "tmp", + createTarget: true, + flags: []string{"--yaml"}, + extensions: []string{".yaml"}, + }, + { + name: "success - rst is generated", + target: "tmp", + createTarget: true, + flags: []string{"--rst"}, + extensions: []string{".rst"}, + }, + { + name: "success - manpage is generated", + target: "tmp", + createTarget: true, + flags: []string{"--manpage"}, + extensions: []string{".1"}, + }, + { + name: "success - markdown is generated", + target: "tmp", + createTarget: true, + flags: []string{"--markdown"}, + extensions: []string{".md"}, + }, + { + name: "success - multiple types supported", + target: "tmp", + createTarget: true, + flags: []string{"--markdown", "--yaml"}, + extensions: []string{".md", ".yaml"}, + }, + { + name: "success - generates a new directory", + target: "tmp2", + createTarget: false, + flags: []string{"--yaml"}, + extensions: []string{".md", ".yaml"}, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + home := t.TempDir() + + targetPath := filepath.Join(home, tc.target) + if tc.createTarget { + require.NoError(t, os.Mkdir(targetPath, 0755), "Mkdir successfully created directory") + } + + logger := log.NewNopLogger() + cfg, err := genutiltest.CreateDefaultTendermintConfig(home) + require.NoError(t, err, "Created default tendermint config") + + appCodec := sdksim.MakeTestEncodingConfig().Codec + err = genutiltest.ExecInitCmd(testMbm, home, appCodec) + require.NoError(t, err, "Executed init command") + + serverCtx := server.NewContext(viper.New(), cfg, logger) + clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home) + + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) + ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx) + + cmd := provenancecmd.GetDocGenCmd() + args := append([]string{targetPath}, tc.flags...) + cmd.SetArgs(args) + + if len(tc.err) > 0 { + err := cmd.ExecuteContext(ctx) + require.Error(t, err, "should throw an error") + expected := tc.err + if strings.Contains(expected, "%s") { + expected = fmt.Sprintf(expected, targetPath) + } + require.Equal(t, expected, err.Error(), "should return the correct error") + files, err := os.ReadDir(targetPath) + if err != nil { + require.Equal(t, 0, len(files), "should not generate files when failed") + } + } else { + err := cmd.ExecuteContext(ctx) + require.NoError(t, err, "should not return an error") + + files, err := os.ReadDir(targetPath) + require.NoError(t, err, "ReadDir should not return an error") + require.NotZero(t, len(files), "should generate files when successful") + + for _, file := range files { + ext := filepath.Ext(file.Name()) + + contains := false + for _, extension := range tc.extensions { + contains = contains || ext == extension + } + require.True(t, contains, "should generate files with correct extension") + } + } + + if _, err := os.Stat(targetPath); err != nil { + require.NoError(t, os.RemoveAll(targetPath), "RemoveAll should be able to remove the temporary target directory") + } + }) + } +} diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index d85cf9ad07..da030bcbdb 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -154,6 +154,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { AddMetaAddressCmd(), snapshot.Cmd(newApp), GetPreUpgradeCmd(), + GetDocGenCmd(), ) fixDebugPubkeyRawTypeFlag(rootCmd) diff --git a/go.mod b/go.mod index bf0128d8dc..e01334a0e7 100644 --- a/go.mod +++ b/go.mod @@ -68,6 +68,7 @@ require ( github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.6 // indirect github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -144,6 +145,7 @@ require ( github.com/prometheus/procfs v0.9.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rs/cors v1.8.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/go.sum b/go.sum index 245f3211be..8316dfb04a 100644 --- a/go.sum +++ b/go.sum @@ -383,6 +383,7 @@ github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKy github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM= github.com/creachadair/taskgroup v0.3.2/go.mod h1:wieWwecHVzsidg2CsUnFinW1faVN4+kq+TDlRJQ0Wbk= @@ -1031,6 +1032,7 @@ github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=