Skip to content

Commit

Permalink
Added package envs command for printing tree of environments
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
motns committed May 15, 2020
1 parent c118636 commit e33f8d4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
15 changes: 15 additions & 0 deletions PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ username
/staging: admin
```

You can also just show the hierarchy of environments and sub-environments by running:
```bash
configstore package envs
```
This returns an output very similar to that of `configstore package tree`:
```bash
/dev
/aws
/server1
/server2
/local
/live
/staging
```

To process templates in the context of a given environment, you can run:
```bash
configstore package process_templates dev/local /path/to/output
Expand Down
13 changes: 13 additions & 0 deletions cmd/configstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@ func main() {
},
BashComplete: PackageCmdAutocomplete(nil),
},
{
Name: "envs",
Usage: "Print out a hierarchical structure of all environments and sub-environments",
Action: cmdPackageEnvs,
Flags: []cli.Flag{
cli.StringFlag{
Name: "basedir",
Usage: "The base directory for the configuration package structure",
Value: "./config",
},
},
BashComplete: PackageCmdAutocomplete(nil),
},
{
Name: "diff",
Usage: "Prints out the differences between two environments",
Expand Down
38 changes: 38 additions & 0 deletions cmd/configstore/package-envs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"gopkg.in/urfave/cli.v1"
"strings"
)

func cmdPackageEnvs(c *cli.Context) error {
basedir := c.String("basedir")
return printDirs(basedir + "/env", 0)
}

func printDirs(basedir string, indent int) error {
dirs, err := ListDirs(basedir)
if err != nil {
return fmt.Errorf("%w; Failed to list top-level directories at: %s", err, basedir)
}

for _, dir := range dirs {
out := ""
if indent == 0 {
out = formatGreen(dir)
} else if indent == 1 {
out = formatCyan(dir)
} else {
out = dir
}

fmt.Println(strings.Repeat(" ", indent * 2) + "/" + out)

if err := printDirs(basedir + "/" + dir, indent + 1); err != nil {
return err
}
}

return nil
}
5 changes: 4 additions & 1 deletion configstore.bats
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
rm -rf test_data/out_test
}

@test "configstore package ls, tree, diff" {
@test "configstore package ls, envs, tree, diff" {
rm -rf test_data/package_test
rm -rf test_data/out_test
mkdir test_data/out_test
Expand All @@ -219,6 +219,9 @@
run bin/darwin/amd64/configstore package ls --basedir test_data/package_test dev/local
[ "$status" -eq 0 ]

run bin/darwin/amd64/configstore package envs --basedir test_data/package_test
[ "$status" -eq 0 ]

run bin/darwin/amd64/configstore package tree --basedir test_data/package_test
[ "$status" -eq 0 ]

Expand Down

0 comments on commit e33f8d4

Please sign in to comment.