Skip to content

Commit

Permalink
feat: use checkmark to denote current workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Dec 23, 2024
1 parent 0e3e9fa commit 2e6cf4c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ The explorer pane a tree of [modules](#module) and [workspaces](#workspace) disc

You can select multiple modules or workspaces; you cannot select a combination of the two. Any terraform commands are then carried out on the selection.

The *current* workspace for a module is distinguished by a check mark. If you run any workspace-level commands on a module, such as a plan or apply, then those commands operate on the current workspace. See key bindings below for how to change the current workspace.

The number of resources in the state is shown alongside the workspace.

![Modules screenshot](./demo/modules.png)
Expand Down
6 changes: 3 additions & 3 deletions internal/integration/cost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func TestCost(t *testing.T) {
return strings.Contains(s, "cost") &&
strings.Contains(s, "exited $2621.90") &&
matchPattern(t, `OVERALL TOTAL.*\$2\,621\.90`, s) &&
strings.Contains(s, `default 0 $87.12`) &&
strings.Contains(s, `default 0 $87.12`) &&
strings.Contains(s, `dev 0 $2360.55`) &&
strings.Contains(s, `default 0 $87.12`) &&
strings.Contains(s, `default 0 $87.12`)
strings.Contains(s, `default 0 $87.12`) &&
strings.Contains(s, `default 0 $87.12`)
})
}

Expand Down
10 changes: 5 additions & 5 deletions internal/integration/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestExplorer_SingleDestroyPlan(t *testing.T) {
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└ 󰠱 a") &&
strings.Contains(s, "└  default 10")
strings.Contains(s, "└  default 10")
})

// Create destroy plan
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestExplorer_SingleDestroy(t *testing.T) {
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└ 󰠱 a") &&
strings.Contains(s, "└  default 10")
strings.Contains(s, "└  default 10")
})

// Create destroy
Expand All @@ -367,7 +367,7 @@ func TestExplorer_SingleDestroy(t *testing.T) {
waitFor(t, tm, func(s string) bool {
return strings.Contains(s, "apply (destroy) 󰠱 modules/a  default") &&
strings.Contains(s, "exited +0~0-10") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})
}

Expand Down Expand Up @@ -433,7 +433,7 @@ func TestExplorer_WithVars(t *testing.T) {
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└ 󰠱 a") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})

// Create plan for default workspace
Expand Down Expand Up @@ -511,7 +511,7 @@ func setupAndInitModule_Explorer(t *testing.T) *testModel {
return strings.Contains(s, "Terraform has been successfully initialized!") &&
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})

// Go back to explorer
Expand Down
4 changes: 2 additions & 2 deletions internal/integration/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestState_NoState(t *testing.T) {
return strings.Contains(s, "Terraform has been successfully initialized!") &&
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})

// Go to state page for workspace
Expand Down Expand Up @@ -471,7 +471,7 @@ func setupState(t *testing.T) *testModel {
return strings.Contains(s, "Terraform has been successfully initialized!") &&
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└  default 10")
strings.Contains(s, "└  default 10")
})

// Go to state page for workspace
Expand Down
18 changes: 9 additions & 9 deletions internal/integration/terragrunt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func TestTerragrunt_Dependencies(t *testing.T) {
matchPattern(t, `modules/frontend-app.*default.*\+0~0-0`, s) &&
matchPattern(t, `\..*default.*errored`, s) &&
// Expect several modules to now have some resources
strings.Contains(s, "└  default 3") &&
strings.Contains(s, "└  default 2") &&
strings.Contains(s, "└  default 1") &&
strings.Contains(s, "└  default 1") &&
strings.Contains(s, "└  default 0") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 3") &&
strings.Contains(s, "└  default 2") &&
strings.Contains(s, "└  default 1") &&
strings.Contains(s, "└  default 1") &&
strings.Contains(s, "└  default 0") &&
strings.Contains(s, "└  default 0")
})

// Go back to explorer.
Expand All @@ -112,7 +112,7 @@ func TestTerragrunt_Dependencies(t *testing.T) {
matchPattern(t, `modules/frontend-app.*default.*apply \(destroy\).*exited.*\+0~0-0`, s) &&
matchPattern(t, `\..*default.*apply \(destroy\).*exited.*\+0~0-0`, s) &&
// Expect modules to now have some 0 resources
strings.Count(s, "└  default 0") >= 6
strings.Count(s, "└  default 0") >= 6
})
}

Expand All @@ -138,7 +138,7 @@ func setupAndInitTerragruntModule(t *testing.T) *testModel {
return strings.Contains(s, "Terraform has been successfully initialized!") &&
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})

// Show task info sidebar so tests can check that terragrunt is indeed being
Expand Down Expand Up @@ -178,7 +178,7 @@ func setupAndInitTerragruntModulesWithDependencies(t *testing.T) *testModel {
matchPattern(t, `modules/backend-app.*init.*exited`, s) &&
matchPattern(t, `\..*init.*exited`, s) &&
// Expect modules to be listed along with their default workspace.
strings.Count(s, "└  default 0") >= 6
strings.Count(s, "└  default 0") >= 6
})

// Go back to explorer and clear selection.
Expand Down
9 changes: 5 additions & 4 deletions internal/integration/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func TestWorkspace_SetCurrentWorkspace(t *testing.T) {

// Expect dev to be the new current workspace
waitFor(t, tm, func(s string) bool {
return strings.Contains(s, "set current workspace to dev")
return strings.Contains(s, "dev ✓") &&
strings.Contains(s, "set current workspace to dev")
})
}

Expand Down Expand Up @@ -139,7 +140,7 @@ func TestWorkspace_SingleDestroy(t *testing.T) {
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "└ 󰠱 a") &&
strings.Contains(s, "└  default 10")
strings.Contains(s, "└  default 10")
})

// Go back to explorer and place cursor on default workspace
Expand All @@ -157,7 +158,7 @@ func TestWorkspace_SingleDestroy(t *testing.T) {
waitFor(t, tm, func(s string) bool {
return strings.Contains(s, "apply (destroy) 󰠱 modules/a  default") &&
strings.Contains(s, "exited +0~0-10") &&
strings.Contains(s, "└  default 0")
strings.Contains(s, "└  default 0")
})
}

Expand Down Expand Up @@ -250,7 +251,7 @@ func setupAndInitModuleWithTwoWorkspaces(t *testing.T) *testModel {
return strings.Contains(s, "Terraform has been successfully initialized!") &&
strings.Contains(s, "init 󰠱 modules/a") &&
strings.Contains(s, "exited") &&
strings.Contains(s, "├  default 0") &&
strings.Contains(s, "├  default 0") &&
strings.Contains(s, "└  dev 0")
})

Expand Down
6 changes: 5 additions & 1 deletion internal/tui/explorer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ func (w workspaceNode) ID() any {

func (w workspaceNode) String() string {
name := lipgloss.NewStyle().
Bold(w.current).
Render(w.name)
s := tui.WorkspaceNameWithIcon(name, false)
if w.current {
s += lipgloss.NewStyle().
Foreground(tui.LighterGrey).
Render(" ✓")
}
if w.resourceCount != "" {
s += lipgloss.NewStyle().
Foreground(tui.LighterGrey).
Expand Down

0 comments on commit 2e6cf4c

Please sign in to comment.