# Stratumn CLI

## Installation

```bash
$ npm install -g stratumn-cli
```

You might have to sudo:

```bash
$ sudo npm install -g stratumn-cli
```

## Usage

```
  Usage: stratumn [command] [options]


  Commands:

    signup                                  create an account
    login                                   login to your account
    logout                                  delete authentication data
    whoami                                  display logged in user
    passwd                                  change your password
    list                                    list applications
    ls                                      list applications
    show <app-name>                         show application details
    view <app-name>                         show application details
    info <app-name>                         show application details
    metrics <app-name>                      show application metrics
    stats <app-name>                        show application metrics
    operations [app-name]                   show application operations
    ops [app-name]                          show application operations
    logs [app-name]                         show application operations
    create <app-name>                       create an application
    new <app-name>                          create an application
    deploy <app-name> <script-path>         deploy an application
    destroy <app-name>                      destroy an application
    rm <app-name>                           destroy an application
    rename <app-name> <new-name>            rename an application
    mv <app-name> <new-name>                rename an application
    users <app-name>                        show application users
    invite <app-name> <role> <email>        invite another user to an application
    accept <token>                          accept an invitation
    routes <app-name>                       output routes
    set-config <app-name> (<key>=<value>)+  set a new environment variable
    get-config <app-name> [key]             get environment variable(s)
    unset-config <app-name> <key>           unset an environment variable
    help [cmd]                              display help for [cmd]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

## Commands

### stratumn-signup

Starts an interactive prompt to create an account.

```
  Usage: stratumn-signup [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-login

Starts an interactive prompt to log into an account.

The login data is saved to the file `~/.stratumn.json`. It is valid for seven days.
Making API calls refreshes the token.

```
  Usage: stratumn-login [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-logout

Deletes account login data.

```
  Usage: stratumn-logout [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-whoami

Shows the email of the account currently logged in.

```
  Usage: stratumn-whoami [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-passwd

Starts an interactive prompt to change the password of the account currently logged in.

```
  Usage: stratumn-passwd [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-list

Aliases: *stratumn-ls*

Lists the applications the account currently logged in has access to.

```
  Usage: stratumn-list [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-show

Aliases: *stratumn-view, stratumn-info*

Shows the details of an application, its agent script, or the active/last job.

```
  Usage: stratumn-show <app-name>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
    -s, --script   show script
    -j, --job      show active or last job
```

### stratumn-metrics

Aliases: *stratumn-stats*

Shows the metrics of an application.

`from` and `to` can be timestamps in milliseconds or strings compatible with
[moment.js](http://momentjs.com).

```
  Usage: stratumn-metrics <app-name>

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -f, --from <time>  from timestamp (milliseconds) or date
    -t, --to <time>    to timestamp (milliseconds) or date
```

### stratumn-operations

Aliases: *stratumn-ops, stratumn-logs*

Shows the operations of an application.

`from` and `to` can be timestamps in milliseconds or strings compatible with
[moment.js](http://momentjs.com).

`state` can be `SUCCESS` or `ERROR`.

`orders` can be `ASC` or `DESC`.

`format` can be `JSON` or `CSV`.

```
  Usage: stratumn-operations [app-name]

  Options:

    -h, --help               output usage information
    -V, --version            output the version number
    -f, --from <time>        from timestamp (milliseconds) or date
    -t, --to <time>          to timestamp (milliseconds) or date
    -l, --limit <int>        limit number of operations
    -s, --state <string>     filter by state
    -z, --fossilized <bool>  show/hide fossilized operations
    -S, --search <string>    search by map id
    -O, --order <string>     specify order
    -F, --format <string>    specify format
```

### stratumn-create

Aliases: *stratumn-new*

Creates a new application.

```
  Usage: stratumn-create <app-name>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-deploy

Deploys and/or scales an application.

`plan` can be `SANDBOX`, `METAMORPHIC`, `SEISMIC`, or `TECTONIC`.

`SANDBOX` plan can only have one agent.

```
  Usage: stratumn-deploy <app-name> [script-path]

  Options:

    -h, --help               output usage information
    -V, --version            output the version number
    -p, --plan <name>        change the plan
    -n, --agent-count <int>  change the number of agents
```

### stratumn-destroy

Aliases: *stratumn-rm*

Destroys an application.

```
  Usage: stratumn-destroy <app-name>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-rename

Aliases: *stratumn-mv*

Renames an application.

```
  Usage: stratumn-rename <app-name> <new-app-name>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-users

Shows the users that have access to an application.

```
  Usage: stratumn-users <app-name>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-invite

Invites a user to an application.

`role` can be `ADMIN` or `COLLABORATOR`.

```
  Usage: stratumn-invite <app-name> <role> <email>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-accept

Accepts an invitation to an application.

```
  Usage: stratumn-accept <token>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-routes

Lists all routes or a specific route, optionally executes a route.

```
  Usage: stratumn-routes <app-name> [show-app|create-map|show-link|create-link] [hash] [func] [...args]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
    -x, --exec     execute route
    -p, --pretty   pretty output when executing
    -d, --debug    add debug flag to urls
```

When executing routes, arguments will be inflated if their value is:

* null
* false
* true
* a base 10 number

##### Example: Show all routes

```
$ stratumn-routes <appname>
```

##### Example: Create a new map

```
$ stratumn-routes -xp <appname> create-map [arg1] [arg2] [...]
```

##### Example: Show an existing link

```
$ stratumn-routes -xp <appname> show-link <link-hash>
```

##### Example: Create a new link

```
$ stratumn-routes -xp <appname> create-link <prev-link-hash> <func-name> [arg1] [arg2] [...]
```

##### Find links of a map with specified tag

```
$ stratumn-routes -xp <appname> show-map <map-id> -t <tag>
```

### stratumn-set-config

Set a new environment variable for the application.

```
  Usage: stratumn-config-set <app-name> (<key>=<value>)+

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-get-config

Get either all or a specific existing environment variable set for the application.

```
  Usage: stratumn-config-set <app-name> [key]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

### stratumn-unset-config

Unset an existing environment variable for the application.

```
  Usage: stratumn-config-unset <app-name> <key>

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
```

## Env variables

### STRATUMN_BASE_URL

Stratumn backend API base url, default `https://stratumn.net`.

### STRATUMN_APPLICATION_URL

Stratumn application/agent API base url, default `https://%s.stratumn.net`. `%s` is replaced by application name.

### STRATUMN_JWT_TTL

Auth token time to live in seconds, default `604800` (one week).

### STRATUMN_CONFIG_FILE

Where settings are stored (including auth token), default `~/.stratumn.json`.

### STRATUMN_PROXY

Server to proxy requests through, default `null`.

Example values:

```
http://proxy-server-over-tcp.com:3128
https://proxy-server-over-tls.com:3129
socks://username:password@some-socks-proxy.com:9050
socks5://username:password@some-socks-proxy.com:9050
socks4://some-socks-proxy.com:9050
pac+http://www.example.com/proxy.pac
```

### STRATUMN_INSECURE

Allow insecure SSL connections, default `false`.

### STRATUMN_DEBUG

Output debug information, default `false`.
