4 releases (breaking)

0.6.0 Feb 20, 2022
0.5.0 Jul 26, 2020
0.4.0 Jul 17, 2020
0.3.0 Jul 16, 2020
0.1.0 Feb 28, 2019

#630 in Configuration

39 downloads per month

MIT license

38KB
671 lines

gcloud-ctx (gctx)

Build and Test Version

A fast replacement for gcloud config configurations written in Rust for managing Google Cloud Platform gcloud configurations easily and quickly

Note: This project is independent and not affiliated with Google in any way

Screencast

Installation

Windows

Install via scoop:

scoop bucket add adamrodger https://github.com/adamrodger/scoop-bucket
scoop install gctx

Mac/Linux

Install via brew

brew install adamrodger/tap/gctx

Pre-Built Binaries (Windows, Linux, Mac)

Grab the latest binary, extract it and add it to your PATH.

From Source

Get the latest stable version of Rust via rustup and run:

cargo install gctx

Usage

## show the current configuration (useful for adding to default prompt)
gctx current
gctx          # shorthand, just omit current

## list all configurations
gctx list

## activate a different configuration
gctx my-config
gctx activate my-config   # explicitly activate, e.g. if your configuration name clashes with a gctx command
gctx activate             # if fzf is installed, you can omit the name and select from a list

## create (and optionally activate) a new configuration
gctx create my-config --project foo \
                      --account a.user@example.org \
                      --zone europe-west1-d \
                      --region europe-west1 \
                      --force \
                      --activate

## copy an existing configuration
gctx copy src-name dest-name --force --activate

## show the properties of a configuration (like gcloud config configurations describe)
gctx describe           # defaults to the current configuration
gctx describe name      # describe a named configuration

## rename a configuration
gctx rename old-name new-name
gctx rename --force old-name existing-name   # use force to overwrite an existing configuration

## delete a configuration. note: you can't delete the active configuration
gctx delete my-config

## show help and usage
gctx --help

Output

gctx auto-detects terminal capabilities by default and supports the NO_COLOR and CLICOLOR standards as provided by the colored crate. For example:

# will have colors if the terminal supports them
gctx list

# force no colors on output
NO_COLOR=1 gctx list
CLICOLOR=0 gctx list

# force colors on output
CLICOLOR_FORCE=1 gctx list

Motivation

I'm often working with multiple GCP projects with a variety of different settings (e.g. default compute zone).However, the standard gcloud tool has two major problems:

  • It's quite a lot of typing if you're switching often. Sure, an alias can help, but...
  • gcloud is slow to initialise which makes it annoying to use and to add to your default prompt

After having used kubectx to solve a similar problem switching between Kubernetes contexts easily, I searched for a similar tool that could easily switch between gcloud configurations but couldn't find anything. So, having spent a while learning Rust and being incredibly impressed, I thought it would make a great starter project.

Goals

gctx aims to achieve similar goals to kubectx, such as:

  • Extremely fast switching between different gcloud configurations
  • Cross platform
  • Shorter to type than gcloud config configurations activate 😄
  • Fuzzy finding using fzf (if installed)

License

gctx is distributed under the terms of the MIT license

Previous gctx crate

Note that versions prior to 0.3.0 of the gctx crate are unrelated works by a previous author that were yanked and abandoned. The previous author kindly passed the crate name over to me so that I can reuse it. Thank you again!

Dependencies

~6–20MB
~236K SLoC