Skip to content

Commit

Permalink
chore: Clean up README
Browse files Browse the repository at this point in the history
  • Loading branch information
abyss committed Jun 19, 2024
1 parent 2365315 commit b9ec4e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

The Terraform Workspace Selector is a command-line tool that helps you interactively select a Terraform workspace from the available options.

I generated this entirely using ChatGPT and don't know what I'm doing, so there might be problems or inefficiencies. Feel free to open issues.


## Functionality

The application provides the following basic functionality:
Expand All @@ -13,14 +10,18 @@ The application provides the following basic functionality:
- Displays an interactive prompt that allows you to select a workspace.
- Sets the selected workspace using the `terraform workspace select` command.

## Install

## Usage
To install Terraform Workspace Selector, you can do either of the following:
- Run `go install github.com/abyss/tfws@latest`

To use the Terraform Workspace Selector, follow these steps:
- Download a binary from GitHub and put it in your PATH

`tfws` calls `terraform` directly, so terraform will need to be resolvable from your path. Tools like [tenv](https://github.com/tofuutils/tenv) or [asdf](https://github.com/asdf-vm/asdf) should natively work.

## Usage

1. Run `task build` to create a binary (located in `bin/`)
2. Copy that binary somewhere in your path.
3. Run `tfws` in your Terraform project.
To use the Terraform Workspace Selector, just run `tfws` in a Terraform project with multiple workspaces.

Upon running the application, it will retrieve the list of Terraform workspaces and display an interactive prompt. Use the arrow keys or fuzzy search to navigate the options and press Enter to select a workspace. The selected workspace will be set using the `terraform workspace select` command.

Expand Down
4 changes: 0 additions & 4 deletions tfws.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func main() {
return
}

// Create items for the prompt
items := make([]string, len(validWorkspaces))
defaultIndex := 0
for i, workspace := range validWorkspaces {
Expand All @@ -57,14 +56,12 @@ func main() {
}
}

// Create the select prompt
prompt := &survey.Select{
Message: "Select a Terraform workspace:",
Options: items,
Default: items[defaultIndex],
}

// Run the prompt
var selectedWorkspace string
err = survey.AskOne(prompt, &selectedWorkspace, survey.WithPageSize(10))
if err != nil {
Expand All @@ -73,7 +70,6 @@ func main() {

fmt.Printf("Selected workspace: %s\n", selectedWorkspace)

// Select the chosen workspace
cmd = exec.Command("terraform", "workspace", "select", selectedWorkspace)
if err := cmd.Run(); err != nil {
log.Fatalf("Failed to execute 'terraform workspace select': %s", err)
Expand Down

0 comments on commit b9ec4e9

Please sign in to comment.