Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Added Windows Support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
StiviiK authored May 15, 2023
1 parent 05efcc6 commit 4c55202
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 121 deletions.
40 changes: 20 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License
Copyright (c) 2022 Stefan Kürzeder <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MIT License

Copyright (c) 2022 Stefan Kürzeder <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
146 changes: 73 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
# `azctx`: Power tool for the Azure CLI

![Proudly written in Go](https://img.shields.io/badge/written%20in-go-29BEB0.svg)
![Latest GitHub release](https://img.shields.io/github/v/release/StiviiK/azctx.svg)
![GitHub stars](https://img.shields.io/github/stars/stiviik/azctx.svg?label=github%20stars)
![GitHub contributors](https://img.shields.io/github/contributors/stiviik/azctx.svg?label=github%20contributors)

**`azctx`** helps you switch between azure cli subscriptions back and forth:

![azctx demo GIF](assets/img/azctx-demo.png)


# azctx(1)
#
```bash
azctx is a CLI tool for managing azure cli subscriptions.
It is a helper for the azure cli and provides a simple interface for managing subscriptions.
Pass a subscription name to select a specific subscription.
Pass - to switch to the previous subscription.

Usage:
azctx [- / -- NAME] [flags]
azctx [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
login Login to Azure
version Print the CLI version

Flags:
-c, --current Display the current active subscription
--filter-tenant-level Filter tenant level accounts with no available subscriptions (default true)
-h, --help help for azctx
-r, --refresh Re-Authenticate and refresh the subscriptions.
Deprecated. Please use azctx login instead.
-s, --short Use a short prompt

Use "azctx [command] --help" for more information about a command.
```
-----
## Installation
### Homebrew
* Install `azctx` with `brew install stiviik/tap/azctx`
### Linux
* Install the `azctx` binary from the [repository](https://github.com/StiviiK/azctx/releases)
* Add the `azctx` binary to your PATH
-----
## Troubleshooting
### Error: `AZURE_CONFIG_DIR is not set / a valid directory. [...]`
Run once `az configure` to create the configuration directory.
Check the [Microsoft Documentation](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file) for the correct path to the azure cli config directory and export it as AZURE_CONFIG_DIR environment variable.
```bash
export AZURE_CONFIG_DIR=$HOME/.azure
```
-----
## Todos
* [ ] Implement Unit Tests
# `azctx`: Power tool for the Azure CLI

![Proudly written in Go](https://img.shields.io/badge/written%20in-go-29BEB0.svg)
![Latest GitHub release](https://img.shields.io/github/v/release/StiviiK/azctx.svg)
![GitHub stars](https://img.shields.io/github/stars/stiviik/azctx.svg?label=github%20stars)
![GitHub contributors](https://img.shields.io/github/contributors/stiviik/azctx.svg?label=github%20contributors)

**`azctx`** helps you switch between azure cli subscriptions back and forth:

![azctx demo GIF](assets/img/azctx-demo.png)


# azctx(1)
#
```bash
azctx is a CLI tool for managing azure cli subscriptions.
It is a helper for the azure cli and provides a simple interface for managing subscriptions.
Pass a subscription name to select a specific subscription.
Pass - to switch to the previous subscription.

Usage:
azctx [- / -- NAME] [flags]
azctx [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
login Login to Azure
version Print the CLI version

Flags:
-c, --current Display the current active subscription
--filter-tenant-level Filter tenant level accounts with no available subscriptions (default true)
-h, --help help for azctx
-r, --refresh Re-Authenticate and refresh the subscriptions.
Deprecated. Please use azctx login instead.
-s, --short Use a short prompt

Use "azctx [command] --help" for more information about a command.
```
-----
## Installation
### Homebrew
* Install `azctx` with `brew install stiviik/tap/azctx`
### Linux
* Install the `azctx` binary from the [repository](https://github.com/StiviiK/azctx/releases)
* Add the `azctx` binary to your PATH
-----
## Troubleshooting
### Error: `AZURE_CONFIG_DIR is not set / a valid directory. [...]`
Run once `az configure` to create the configuration directory.
Check the [Microsoft Documentation](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file) for the correct path to the azure cli config directory and export it as AZURE_CONFIG_DIR environment variable.
```bash
export AZURE_CONFIG_DIR=$HOME/.azure
```
-----
## Todos
* [ ] Implement Unit Tests
12 changes: 7 additions & 5 deletions azurecli/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const (
TENANTS_JSON = "azctxTenants.json"
)

var (
defaultConfigDir = os.Getenv("HOME") + "/.azure"
)

// ensureConfigDir ensures that the config dir exists
func ensureConfigDir() (string, error) {
// Verify that the AZURE_CONFIG_DIR environment variable is set
configDir := os.Getenv(CONFIG_DIR_ENV)
if configDir == "" {
log.Warn("%s environment variable is not set. Using default config directory.", CONFIG_DIR_ENV)
configDir = defaultConfigDir

// Get the user's home directory
userhomeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("could not get user home directory: %s", err.Error())
}
configDir = fmt.Sprintf("%s/.azure", userhomeDir)
}

// Verify that the config dir exists
Expand Down
2 changes: 1 addition & 1 deletion azurecli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func (cli *CLI) MapTenantIdsToNames() {
cli.profile.Subscriptions[i].TenantName = subscription.Tenant
}
} else {
log.Info("If you want to fetch the tenant names, please authenticate the azure cli again using the wraper command: `azctx login`.")
log.Info("If you want to fetch the tenant names, please authenticate the azure cli again using the wraper command: `azctx login`")
}
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.18

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/lithammer/fuzzysearch v1.1.5
github.com/lithammer/fuzzysearch v1.1.7
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/afero v1.9.5
github.com/spf13/cobra v1.7.0
go.szostok.io/version v1.1.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/term v0.7.0
go.szostok.io/version v1.2.0
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
)

require (
Expand Down Expand Up @@ -40,8 +40,8 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 4c55202

Please sign in to comment.