Skip to content

Commit

Permalink
refactor: Change Arguments and Flags.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Change in API.
  • Loading branch information
lukasz-lobocki committed Aug 10, 2024
1 parent 7bcfe05 commit 3c7bd20
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 16 deletions.
17 changes: 14 additions & 3 deletions cmd/command_dbtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ import (

// dbTableCmd represents the shell command.
var dbTableCmd = &cobra.Command{
Use: "dbTable <PATH> <TABLE>",
Short: "Export badger table.",
Long: `Export data table out of the badger database of step-ca. For list of tables see: https://raw.githubusercontent.com/smallstep/certificates/master/db/db.go`,
Long: `
Export data table out of the badger database of step-ca.`,

Short: "Export badger table.",
DisableFlagsInUseLine: true,
Use: `dbTable <PATH> <TABLE> [flags]
Arguments:
PATH location of the source database
TABLE name of Badger table to export
Note:
For list of tables see: https://raw.githubusercontent.com/smallstep/certificates/master/db/db.go`,

Aliases: []string{"dbtable"},
Example: " step-badger dbTable ./db ssh_host_principals",

Args: cobra.ExactArgs(2),
Expand Down
53 changes: 53 additions & 0 deletions cmd/command_markdownDocs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright © 2024 Lukasz Lobocki
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

// markdownDocsCmd represents the markdownDocs command
var markdownDocsCmd = &cobra.Command{
Long: `
Generate markdown docs for the entire command tree.`,
Short: "Generate markdown docs.",
DisableFlagsInUseLine: true,
Use: `markdownDocs <PATH> [flags]
Arguments:
PATH location for the result`,

Aliases: []string{"markdowndocs"},

Args: cobra.ExactArgs(1),

Example: ` step-badger markdownDocs ~/tmp`,

Hidden: true, // Hide command from the tree.

Run: func(cmd *cobra.Command, args []string) {
exportMarkdownMain(args)
},
}

func init() {
rootCmd.AddCommand(markdownDocsCmd)

// Hide help command.
markdownDocsCmd.SetHelpCommand(&cobra.Command{Hidden: true})

//Do not sort flags.
markdownDocsCmd.Flags().SortFlags = false
}

func exportMarkdownMain(args []string) {

checkLogginglevel(args)

err := doc.GenMarkdownTree(rootCmd, args[0])
if err != nil {
logError.Fatalln(err)
}
}
9 changes: 5 additions & 4 deletions cmd/command_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ var config tConfig // Holds configuration.

// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "step-badger",
Short: "Export step-ca data from badger.",
Long: `Export certificate or table data from the badger database of step-ca. Requires off-line database directory.`,
Version: semReleaseVersion,
Use: "step-badger",
Short: "Export step-ca data from badger.",
Long: `Export certificate or table data from the badger database of step-ca. Requires off-line database directory.`,
Version: semReleaseVersion,
DisableAutoGenTag: true, // Do not add footer to autogenerated help.

CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true},

Expand Down
15 changes: 11 additions & 4 deletions cmd/command_sshcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ import (

// sshCertsCmd represents the shell command.
var sshCertsCmd = &cobra.Command{
Long: `Export ssh certificates' data out of the badger database of step-ca.`,
Short: "Export ssh certificates.",
Use: "sshCerts <PATH>",
Long: `
Export ssh certificates' data out of the badger database of step-ca.`,

Short: "Export ssh certificates.",
DisableFlagsInUseLine: true,
Use: `sshCerts <PATH> [flags]
Arguments:
PATH location of the source database`,

Aliases: []string{"sshcerts"},
Example: " step-badger sshCerts ./db",

Args: cobra.ExactArgs(1),
Expand All @@ -42,7 +49,7 @@ func init() {

// Records selection criteria.
sshCertsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid certificates shown")
sshCertsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked certificates shown")
sshCertsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", false, "revoked certificates shown")
sshCertsCmd.Flags().BoolVarP(&config.showExpired, "expired", "e", false, "expired certificates shown")

// Format choice
Expand Down
18 changes: 13 additions & 5 deletions cmd/command_x509certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ import (

// x509certsCmd represents the shell command.
var x509certsCmd = &cobra.Command{
Long: `Export x509 certificates' data out of the badger database of step-ca.`,
Short: "Export x509 certificates.",
Use: "x509Certs <PATH>",
Long: `
Export x509 certificates' data out of the badger database of step-ca.`,

Example: " step-badger x509certs ./db",
Short: "Export x509 certificates.",
DisableFlagsInUseLine: true,
Use: `x509Certs <PATH> [flags]
Arguments:
PATH location of the source database`,

Aliases: []string{"x509certs"},
Example: ` step-badger x509certs ./db
step-badger x509Certs ./db --revoked --valid=false --emit=openssl`,

Args: cobra.ExactArgs(1),

Expand All @@ -44,7 +52,7 @@ func init() {

// Records selection criteria.
x509certsCmd.Flags().BoolVarP(&config.showValid, "valid", "v", true, "valid certificates shown")
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", true, "revoked certificates shown")
x509certsCmd.Flags().BoolVarP(&config.showRevoked, "revoked", "r", false, "revoked certificates shown")
x509certsCmd.Flags().BoolVarP(&config.showExpired, "expired", "e", false, "expired certificates shown")

// Format choice
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
Expand All @@ -27,12 +28,15 @@ require (
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
go.etcd.io/bbolt v1.3.10 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -66,7 +67,10 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lukasz-lobocki/tabby v1.0.6 h1:qWID8Gc7Ojpo2HrVYbDD5bRpi70anvT3+XCjQwouh5E=
github.com/lukasz-lobocki/tabby v1.0.6/go.mod h1:npL3zCVTzd1S4x0eSp1FD+SaxBTN6pQZSLWck04Wxyo=
Expand All @@ -84,7 +88,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
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/smallstep/assert v0.0.0-20180720014142-de77670473b5 h1:lX6ybsQW9Agn3qK/W1Z39Z4a6RyEMGem/gXUYW0axYk=
github.com/smallstep/assert v0.0.0-20180720014142-de77670473b5/go.mod h1:TC9A4+RjIOS+HyTH7wG17/gSqVv95uDw2J64dQZx7RE=
Expand Down Expand Up @@ -140,6 +147,8 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down

0 comments on commit 3c7bd20

Please sign in to comment.