Skip to content

Commit

Permalink
group commands (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
passichenko authored May 21, 2024
1 parent bd8f15f commit fdedea2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 55 deletions.
5 changes: 3 additions & 2 deletions cmd/lekko/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (

func confCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "conf",
Short: "parse a .lekko-like configuration file in the working directory",
Use: "conf",
Short: "parse a .lekko-like configuration file in the working directory",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
// By default, read dotlekko and output as JSON
wd, err := os.Getwd()
Expand Down
118 changes: 72 additions & 46 deletions cmd/lekko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,84 @@ import (
// Updated at build time using ldflags
var version = "development"

var coreCommands = &cobra.Group{
ID: "core",
Title: "CORE COMMANDS",
}
var extraCommands = &cobra.Group{
ID: "extra",
Title: "EXTRA COMMANDS",
}
var managementCommands = &cobra.Group{
ID: "management",
Title: "MANAGEMENT COMMANDS",
}
var internalCommands = &cobra.Group{
ID: "internal",
Title: "INTERNAL COMMANDS",
}

func addGroup(parent *cobra.Command, group *cobra.Group, cmds ...*cobra.Command) {
parent.AddGroup(group)
for _, cmd := range cmds {
cmd.GroupID = group.ID
parent.AddCommand(cmd)
}
}

func main() {
err2.SetErrorTracer(os.Stderr)
// to support standard go flags defined by 3rd party libraries
// for example err2
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)

rootCmd := rootCmd()
rootCmd.AddCommand(compileCmd())
rootCmd.AddCommand(verifyCmd())
rootCmd.AddCommand(commitCmd())
rootCmd.AddCommand(reviewCmd())
rootCmd.AddCommand(mergeCmd)
rootCmd.AddCommand(restoreCmd())
rootCmd.AddCommand(teamCmd())
rootCmd.AddCommand(repoCmd())
rootCmd.AddCommand(featureCmd())
rootCmd.AddCommand(namespaceCmd())
rootCmd.AddCommand(apikeyCmd())
rootCmd.AddCommand(upgradeCmd())
rootCmd.AddCommand(confCmd())
// auth
rootCmd.AddCommand(authCmd())
// exp
experimentalCmd.AddCommand(parseCmd())
experimentalCmd.AddCommand(cleanupCmd)
experimentalCmd.AddCommand(formatCmd())
// code generation
rootCmd.AddCommand(genCmd())
rootCmd.AddCommand(syncCmd())
rootCmd.AddCommand(bisyncCmd())
// also leaving these in experimental for backwards compatibility just in case
experimentalCmd.AddCommand(genCmd())
experimentalCmd.AddCommand(syncCmd())
experimentalCmd.AddCommand(bisyncCmd())
rootCmd.AddCommand(experimentalCmd)

// setup
rootCmd.AddCommand(setupCmd())

// short for `lekko repo push`
rootCmd.AddCommand(pushCmd())
// short for `lekko repo pull`
rootCmd.AddCommand(pullCmd())
// short for `lekko repo merge-file`
rootCmd.AddCommand(mergeFileCmd())

rootCmd.AddCommand(diffCmd())

addGroup(
rootCmd,
coreCommands,
genCmd(),
syncCmd(),
bisyncCmd(),
pushCmd(),
pullCmd(),
)

addGroup(
rootCmd,
managementCommands,
authCmd(),
setupCmd(),
teamCmd(),
repoCmd(),
featureCmd(),
namespaceCmd(),
apikeyCmd(),
upgradeCmd(),
)

addGroup(
rootCmd,
extraCommands,
// config repo commands
compileCmd(),
verifyCmd(),
commitCmd(),
reviewCmd(),
mergeCmd,
restoreCmd(),
parseCmd(),
cleanupCmd,
formatCmd(),
)

addGroup(
rootCmd,
internalCommands,
mergeFileCmd(),
diffCmd(),
confCmd(),
)

logging.InitColors()

Expand All @@ -106,7 +137,7 @@ func main() {
func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "lekko",
Short: "lekko - dynamic configuration helper",
Short: "Lekko is a dynamic configuration management tool",
Version: version,
SilenceUsage: true,
SilenceErrors: true,
Expand Down Expand Up @@ -419,11 +450,6 @@ func (p *provider) Type() string {
return "provider"
}

var experimentalCmd = &cobra.Command{
Use: "exp",
Short: "experimental commands",
}

func commitCmd() *cobra.Command {
var message, wd string
cmd := &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/migueleliasweb/go-github-mock v0.0.16
github.com/olekukonko/tablewriter v0.0.5
github.com/shurcooL/githubv4 v0.0.0-20231126234147-1cffa1f02456
github.com/spf13/cobra v1.5.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
github.com/whilp/git-urls v1.0.0
github.com/zalando/go-keyring v0.2.4
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/cli/oauth v0.9.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
Expand Down Expand Up @@ -124,8 +124,8 @@ github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
Expand Down Expand Up @@ -181,8 +181,8 @@ github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgI
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit fdedea2

Please sign in to comment.