Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move list inside stacks command #127

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/terramate/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ type cliSpec struct {
GitChangeBase string `short:"B" optional:"true" help:"git base ref for computing changes."`
Changed bool `short:"c" optional:"true" help:"filter by changed infrastructure"`

List struct {
Why bool `help:"Shows the reason why the stack has changed."`
} `cmd:"" help:"List stacks."`

Run struct {
Quiet bool `short:"q" help:"Don't print any information other than the command output."`
DryRun bool `default:"false" help:"plan the execution but do not execute it"`
Expand All @@ -85,6 +81,10 @@ type cliSpec struct {
Force bool `help:"force initialization."`
} `cmd:"" help:"Initialize a stack."`

List struct {
Why bool `help:"Shows the reason why the stack has changed."`
} `cmd:"" help:"List stacks."`

Globals struct {
} `cmd:"" help:"list globals for all stacks."`
} `cmd:"" help:"stack related commands."`
Expand Down Expand Up @@ -266,14 +266,14 @@ func (c *cli) run() error {
switch c.ctx.Command() {
case "version":
c.log(terramate.Version())
case "list":
return c.printStacks()
case "plan graph":
return c.generateGraph()
case "plan run-order":
return c.printRunOrder()
case "stacks init":
return c.initStack([]string{c.wd()})
case "stacks list":
return c.printStacks()
case "stacks init <paths>":
return c.initStack(c.parsedArgs.Stacks.Init.StackDirs)
case "stacks globals":
Expand Down Expand Up @@ -341,7 +341,7 @@ func (c *cli) printStacks() error {
continue
}

if c.parsedArgs.List.Why {
if c.parsedArgs.Stacks.List.Why {
c.log("%s - %s", stackRepr, entry.Reason)
} else {
c.log(stackRepr)
Expand Down
4 changes: 2 additions & 2 deletions cmd/terramate/cli/cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestRunOrderNotChangedStackIgnored(t *testing.T) {
cli := newCLI(t, s.RootDir())

wantList := stack.RelPath() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: wantList})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: wantList})

cat := test.LookPath(t, "cat")
wantRun := fmt.Sprintf(
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestRunOrderAllChangedStacksExecuted(t *testing.T) {
cli := newCLI(t, s.RootDir())

wantList := stack.RelPath() + "\n" + stack2.RelPath() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: wantList})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: wantList})

cat := test.LookPath(t, "cat")
wantRun := fmt.Sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ z/a
s.BuildTree(tc.layout)

cli := newCLI(t, s.RootDir())
assertRunResult(t, cli.run("list"), tc.want)
assertRunResult(t, cli.run("stacks", "list"), tc.want)
})
}
}
Expand All @@ -115,15 +115,15 @@ func TestListStackWithNoTerramateBlock(t *testing.T) {
Stack: &hcl.Stack{},
})
cli := newCLI(t, s.RootDir())
assertRunResult(t, cli.run("list"), runResult{Stdout: "stack\n"})
assertRunResult(t, cli.run("stacks", "list"), runResult{Stdout: "stack\n"})
}

func TestListNoSuchFile(t *testing.T) {
notExists := test.NonExistingDir(t)
cli := newCLI(t, notExists)

// errors from the manager are not logged in stderr
assertRunResult(t, cli.run("list"), runResult{
assertRunResult(t, cli.run("stacks", "list"), runResult{
Error: os.ErrNotExist,
})
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestListDetectChangesInSubDirOfStack(t *testing.T) {
want := runResult{
Stdout: stack.RelPath() + "\n",
}
assertRunResult(t, cli.run("list", "--changed"), want)
assertRunResult(t, cli.run("stacks", "list", "--changed"), want)
}

func TestListDetectChangesInSubDirOfStackWithOtherConfigs(t *testing.T) {
Expand Down Expand Up @@ -184,5 +184,5 @@ terramate {
want := runResult{
Stdout: stack.RelPath() + "\n",
}
assertRunResult(t, cli.run("list", "--changed"), want)
assertRunResult(t, cli.run("stacks", "list", "--changed"), want)
}
18 changes: 9 additions & 9 deletions cmd/terramate/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ source = "%s"

cli := newCLI(t, s.RootDir())
want := stack1.RelPath() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: want})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: want})
}

func TestBugModuleMultipleFilesSameDir(t *testing.T) {
Expand Down Expand Up @@ -128,7 +128,7 @@ module "mod1" {

cli := newCLI(t, s.RootDir())
want := stack.RelPath() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: want})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: want})
}

func TestListAndRunChangedStack(t *testing.T) {
Expand All @@ -154,7 +154,7 @@ func TestListAndRunChangedStack(t *testing.T) {
git.CommitAll("stack changed")

wantList := stack.RelPath() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: wantList})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: wantList})

cat := test.LookPath(t, "cat")
wantRun := fmt.Sprintf(
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestListAndRunChangedStackInAbsolutePath(t *testing.T) {
git.CommitAll("stack changed")

wantList := stack.Path() + "\n"
assertRunResult(t, cli.run("list", "--changed"), runResult{Stdout: wantList})
assertRunResult(t, cli.run("stacks", "list", "--changed"), runResult{Stdout: wantList})

cat := test.LookPath(t, "cat")
wantRun := fmt.Sprintf(
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestDefaultBaseRefInOtherThanMain(t *testing.T) {
want := runResult{
Stdout: stack.RelPath() + "\n",
}
assertRunResult(t, cli.run("list", "--changed"), want)
assertRunResult(t, cli.run("stacks", "list", "--changed"), want)
}

func TestDefaultBaseRefInMain(t *testing.T) {
Expand All @@ -260,7 +260,7 @@ func TestDefaultBaseRefInMain(t *testing.T) {
Stdout: stack.RelPath() + "\n",
IgnoreStderr: true,
}
assertRunResult(t, cli.run("list", "--changed"), want)
assertRunResult(t, cli.run("stacks", "list", "--changed"), want)
}

func TestBaseRefFlagPrecedenceOverDefault(t *testing.T) {
Expand All @@ -277,7 +277,7 @@ func TestBaseRefFlagPrecedenceOverDefault(t *testing.T) {
git.Commit("all")
git.Push("main")

assertRunResult(t, cli.run("list", "--changed",
assertRunResult(t, cli.run("stacks", "list", "--changed",
"--git-change-base", "origin/main"),
runResult{
IgnoreStderr: true,
Expand All @@ -303,7 +303,7 @@ func TestFailsOnChangeDetectionIfCurrentBranchIsMainAndItIsOutdated(t *testing.T
IgnoreStderr: true,
}

assertRunResult(t, ts.run("list", "--changed"), wantRes)
assertRunResult(t, ts.run("stacks", "list", "--changed"), wantRes)

cat := test.LookPath(t, "cat")
assertRunResult(t, ts.run(
Expand All @@ -325,7 +325,7 @@ func TestFailsOnChangeDetectionIfRepoDoesntHaveOriginMain(t *testing.T) {
IgnoreStderr: true,
}

assertRunResult(t, ts.run("list", "--changed"), wantRes)
assertRunResult(t, ts.run("stacks", "list", "--changed"), wantRes)

cat := test.LookPath(t, "cat")
assertRunResult(t, ts.run(
Expand Down