Skip to content

Commit

Permalink
Merge pull request #15 from Andrius521/feature_context
Browse files Browse the repository at this point in the history
Feature context
  • Loading branch information
Andrius521 authored Sep 19, 2022
2 parents 797177c + b548a63 commit 24f88b7
Show file tree
Hide file tree
Showing 64 changed files with 175 additions and 19 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cherryctl
* [Install binary from Release Download](#install-binary-from-release-download)
* [Shell Completion](#shell-completion)
* [Authentication](#authentication)
* [Working With Multiple User Profiles](#working-with-multiple-user-profiles)
* [Configuring Default Values](#configuring-default-values)
* [Documentation](#documentation)
* [Examples](#examples)
Expand Down Expand Up @@ -90,16 +91,31 @@ Token (hidden):
Team ID []: 12345
Project ID []: 123456

Writing /Users/username/.config/cherry/cherry.yaml
Writing configuration to: /Users/username/.config/cherry/default.yaml
```

The Cherry Servers authentication token can be stored in the `$CHERRY_AUTH_TOKEN` environment variable, as well as in JSON or YAML configuration files. The configuration file path can be overridden with the `--config` flag. The default configuration file is stored in "$HOME/config/cherry/cherry.yaml".
The Cherry Servers authentication token can be stored in the `$CHERRY_AUTH_TOKEN` environment variable, as well as in JSON or YAML configuration files. The configuration file path can be overridden with the `--config` flag. The default configuration file is stored in "$HOME/config/cherry/default.yaml".

### Working With Multiple User Profiles

A user profile is a collection of settings specific to a certain user that is stored in a configuration file. It consists of at least an API token, a Team ID and a Project ID, yet you may add many additional configuration options.

You may work with multiple user profiles at the same time, since `cherryctl` allows you to switch between them by using a `--context` option.

By default, the `--context` option has a value `default`. To create a new context, run `cherryctl init --context <new_context_name>`. You will be prompted for a Token, a Team ID and a Project ID which will be associated with the new context. You will be able to add any other options by editing the newly generated configuration file.

To use a non-default context name to any `cherryctl` command:
```sh

cherryctl servers list --context <new_context_name>

```

## Configuring Default Values

The `cherryctl` configuration file is used to store your API authentication token as well as the default command flags settings. If you find yourself using certain flags frequently, you can set their default values to avoid typing them every time. This can be useful when, for example, you want to deploy all infrastructure in the same region.

`cherryctl` saves its configuration in `${HOME}/cherry/config.yaml`. The `${HOME}/cherry/` directory and the `config.yaml` file will be created once you run `cherryctl init`.
`cherryctl` saves its configuration in `${HOME}/cherry/default.yaml`. The `${HOME}/cherry/` directory and the `config.yaml` file will be created once you run `cherryctl init`.

If you want to change the default value for a `--region` flag, open `.config.yaml` file and add the corresponding key-value pair at the end of the file. For isntance, in the following example we have changed the default region to eu_nord_1:

Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ cherryctl is a command line interface (CLI) for Cherry Servers API
### Options

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-h, --help help for cherryctl
-o, --output string Output format (*table, json, yaml)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ See each sub-command's help for details on how to use the generated script.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ cherryctl completion bash
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_completion_fish.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ cherryctl completion fish [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_completion_powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ cherryctl completion powershell [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_completion_zsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ cherryctl completion zsh [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ cherryctl docs <destination>
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Image operations: list.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_image_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ cherryctl image list --plan <plan_slug> [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cherryctl init
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ IP address operations: get, list, create, update, assign, unassign and remove.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ cherryctl ip assign ID {--target-hostname <hostname> | --target-id <server_id> |
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ cherryctl ip create [-p <project_id>] --region <region_slug> [--target-hostname
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ cherryctl ip delete ID [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ cherryctl ip get ID [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ cherryctl ip list [-p <project_id>] [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_unassign.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ cherryctl ip unassign ID [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_ip_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cherryctl ip update ID [--ptr-record <ptr>] [--a-record <a>] [--tags <tags>] [fl
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Plan operations: get, list.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_plan_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cherryctl plan list [-t <team_id>] [--region-id <region_slug>] [--type <type>] [
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Project operations: get, list, create, update and delete.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cherryctl project create [-t <team_id>] --name <project_name> [--bgp <bool>] [fl
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ cherryctl project delete ID [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ cherryctl project get ID [-p <project_id>] [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ cherryctl project list [-p <project_id>] [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_project_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cherryctl project update ID [-p <project_id>] [--name <project_name>] [--bgp <bo
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_region.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Region operations: get, list.
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions docs/cherryctl_region_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ cherryctl region get {ID | SLUG} [flags]
### Options inherited from parent commands

```
--api-url string Override default API endpoint (default "https://api.cherryservers.com/v1/")
--config string Path to JSON or YAML configuration file
--context string Specify a custom context name (default "default")
--fields strings Comma separated object field names to output in result. Fields can be used for list and get actions.
-o, --output string Output format (*table, json, yaml)
--token string API Token (CHERRY_AUTH_TOKEN)
Expand Down
Loading

0 comments on commit 24f88b7

Please sign in to comment.