Metadata-Version: 2.4
Name: circleci-env-cli
Version: 0.3.1
Summary: CLI tool for managing CircleCI contexts and environment vars
Author-email: Phillipe Smith <phsmithcc@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/phsmith/circleci-env-cli
Keywords: circleci,cli,api
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.3.2
Requires-Dist: requests>=2.33.1
Requires-Dist: pycircleci>=0.7.0
Dynamic: license-file

# circleci-env-cli

[![Build Status](https://github.com/phsmith/circleci-env-cli/actions/workflows/release.yml/badge.svg)](https://github.com/phsmith/circleci-env-cli/actions/workflows/release.yml)
[![PyPI version](https://img.shields.io/pypi/v/circleci-env-cli?color=yellow)](https://python.org/pypi/circleci-env-cli)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/phsmith/circleci-env-cli?label=docker%20version&color=blue)](https://hub.docker.com/r/phsmith/circleci-env-cli)
[![Docker Pulls](https://img.shields.io/docker/pulls/phsmith/circleci-env-cli?color=lightblue)](https://hub.docker.com/r/phsmith/circleci-env-cli)

CLI tool for managing CircleCI contexts and environment variables.

## Installation

### Install via UV (recommended)

```sh
uv tool install circleci-env-cli
```

### Install via Pip

```sh
pip install circleci-env-cli
```

### Run without installing

```sh
uvx circleci-env-cli [OPTIONS]
```

### Install via Docker

```sh
docker pull phsmith/circleci-env-cli:[VERSION]

# Run example
docker run --rm -it \
  -v $HOME/project/.env:/env \
  -e CIRCLE_TOKEN=${CIRCLE_TOKEN} \
  phsmith/circleci-env-cli:latest [OPTIONS]
```

## Usage

A [CircleCI personal API token](https://circleci.com/docs/managing-api-tokens/#creating-a-personal-api-token) must be created before using this tool.

> All options can be specified as environment variables in the format: `CIRCLE_<OPTION>`.
>
> Example: `CIRCLE_TOKEN=********`

```text
Usage: circleci-env-cli [OPTIONS]

  CLI tool for manage CircleCI contexts and environment vars

Options:
  --version                       Show the version and exit.
  -u, --api-url <circleci_api_url>
                                  [default: https://circleci.com/api]
  -t, --token <circleci_token>    [default: (CIRCLE_TOKEN)]
  -c, --context <context_name>    It will ask for create if does not exists
  -p, --project <project_slug>    Example: github/org-name/project-name
                                  [required]
  -e, --env <environment_var>
  -ef, --env-file <environment_vars_file>
  -l, --list-envs
  -d, --delete                    Delete mode. Behavior depends on other
                                  options:
                                    -c only:      delete the entire context
                                    -c + -e/-ef:  delete specific context vars
                                    -e/-ef only:  delete specific project vars
  -ot, --owner-type <owner_type>  [default: organization]
  --debug
  --help                          Show this message and exit.
```

### Examples

#### List project environment variables

```sh
$ circleci-env-cli -p github/myorg/myproject -l
> Project variables (2):
KEY1
KEY2
```

#### Add project environment variables

```sh
$ circleci-env-cli -p github/myorg/myproject -e KEY1=VAL1 -e KEY2=VAL2 -ef project.envs.txt
> Successfully added/updated variable: KEY1
> Successfully added/updated variable: KEY2
> Successfully added/updated variable: KEY3
> Successfully added/updated variable: KEY4
```

The env file (`-ef`) must contain one `KEY=VALUE` pair per line:

```sh
KEY3=VAL3
KEY4=VAL4
```

#### Delete project environment variables

```sh
$ circleci-env-cli -p github/myorg/myproject -e KEY1 -e KEY2 -d
> Successfully deleted variable: KEY1
> Successfully deleted variable: KEY2
```

#### List context variables

```sh
$ circleci-env-cli -p github/myorg/myproject -c mycontext -l
> Context variables (2):
KEY1
KEY2
```

#### Create/update context and add variables

```sh
$ circleci-env-cli -p github/myorg/myproject -c mycontext -e KEY1=VAL1 -e KEY2=VAL2
The context named "mycontext" was not found. Do you want to create it? [y/n]: y
> Successfully created context: mycontext
> Successfully added/updated context variable: KEY1
> Successfully added/updated context variable: KEY2
```

#### Delete context variables

```sh
$ circleci-env-cli -p github/myorg/myproject -c mycontext -e KEY1 -e KEY2 -d
> Successfully deleted context variable: KEY1
> Successfully deleted context variable: KEY2
```

#### Delete context

```sh
$ circleci-env-cli -p github/myorg/myproject -c mycontext -d
Are you sure want to delete the context "mycontext"? [y/n]: y
> Successfully deleted context: mycontext
```
