# Command reference

## Usage

```sh
quill <command> [subcommand] [flags]
```

| Flag            |                         |
| --------------- | ----------------------- |
| `-h, --help`    | Help for any command    |
| `-V, --version` | CLI version             |
| `--agent`       | Agent integration guide |

| Alias               | Command           |
| ------------------- | ----------------- |
| `quill dash`        | `quill dashboard` |
| `quill environment` | `quill env`       |

## Sign-in

### quill login

Sign in and confirm in the browser.

```sh
quill login [flags]
```

| Flag                 | Default                    |                    |
| -------------------- | -------------------------- | ------------------ |
| `--environment <id>` | the organization's default | Environment to use |

### quill logout

Logout.

```sh
quill logout
```

### quill signup

Sign up and confirm in the browser.
Available until the first `quill schema create`.

```sh
quill signup
```

## Environments

### quill create

Create an environment in the organization, switch the CLI to it, and set it up.
After a `quill login` or `quill signup` that left its environment unset, set up
that one instead.
Available until the first `quill schema create`.

```sh
quill create [flags]
```

| Flag                            | Default             |                                                                                                   |
| ------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------- |
| `--app <kind>`                  |                     | `existing`, or `sample` for [quill-sql/demo](https://github.com/quill-sql/demo)                   |
| `--server-dir <path>`           |                     | Server directory; its files pick `--server`, and its `.env` gets `QUILL_PRIVATE_KEY`              |
| `--server <language>`           | from `--server-dir` | `node`, `python`, `go`, `php`, `ruby` or `dotnet`                                                 |
| `--database <type>`             |                     | `postgresql`, `redshift`, `mysql`, `mssql`, `clickhouse`, `snowflake`, `bigquery` or `databricks` |
| `--database-env <name>`         |                     | Env variable holding the connection string, or `<field>=<NAME>` per credential field. Repeatable  |
| `--tenant-field <column>`       |                     | Column holding the tenant id                                                                      |
| `--tenant-table <schema.table>` |                     | Table the tenant column is a foreign key to                                                       |
| `--connection-string <url>`     |                     | Read-only connection string for the Quill web app                                                 |
| `--name <name>`                 |                     | Environment name                                                                                  |

### quill init

Write an environment's keys and server URL to `.quill/config.json`.
Available before `quill login`, or with `enableAdminCommands`.

```sh
quill init [flags]
```

| Flag                          | Default                |                                              |
| ----------------------------- | ---------------------- | -------------------------------------------- |
| `--public-key <key>`          |                        | Environment public key                       |
| `--private-key <key>`         |                        | Environment private key                      |
| `--metadata-server-url <url>` | `https://api.quill.co` | Quill server; API requests go to `<url>/sdk` |

### quill env show

Show the current environment.

```sh
quill env show
```

### quill env status

List the environment's changes.

```sh
quill env status
```

### quill promote

Promote a sandbox's changes to its parent environment. Requires
`enableAdminCommands`.

```sh
quill promote --confirm
quill promote --discard
quill promote --force-sync-to-parent-environment --confirm
```

| Flag                                 | Default |                                                          |
| ------------------------------------ | ------- | -------------------------------------------------------- |
| `--confirm`                          |         | Run the promotion; without it, prints help               |
| `--discard`                          |         | Discard the sandbox's changes                            |
| `--force-sync-to-parent-environment` |         | From a child environment, sync its changes to its parent |

## Tenants

### quill tenant list

List the environment's tenant types and tenant fields.

```sh
quill tenant list [flags]
```

| Flag                       | Default             |                                |
| -------------------------- | ------------------- | ------------------------------ |
| `--environment <nameOrId>` | current environment | Environment public key or name |

### quill tenant create

Define a tenant type.

```sh
quill tenant create --field <field> --table <schema.table> [flags]
quill tenant create --scope database [flags]
```

| Flag                        | Default            |                                                                                |
| --------------------------- | ------------------ | ------------------------------------------------------------------------------ |
| `--field <field>`           | required for `row` | Column on fact tables holding the tenant id, e.g. `organization_id`            |
| `--table <schema.table>`    | required for `row` | Table with one row per tenant                                                  |
| `--scope <scope>`           | `row`              | `row` or `database`                                                            |
| `--name <name>`             | from `--field`     | Tenant type name; `organization_id` → `Organization`                           |
| `--id-column <column>`      | `id`               | Column holding the tenant id                                                   |
| `--label-column <column>`   | `name`             | Column holding the tenant display name                                         |
| `--flag-column <column>`    | `name`             | Column holding the tenant flags                                                |
| `--type <type>`             | `string`           | `string` or `number`, the id column's type                                     |
| `--maps-to <field>`         |                    | Field of another tenant, usually the dashboards' tenant, that this one maps to |
| `--maps-to-column <column>` | `--maps-to`        | Column on `--table` holding the `--maps-to` tenant id                          |

### quill tenant update

Rename a tenant type or change its tenant table.

```sh
quill tenant update --field <field> [flags]
```

| Flag                        | Default     |                                                                                |
| --------------------------- | ----------- | ------------------------------------------------------------------------------ |
| `--field <field>`           | required    | Tenant field of the tenant to update                                           |
| `--name <name>`             |             | New tenant type name                                                           |
| `--table <schema.table>`    |             | Table with one row per tenant                                                  |
| `--id-column <column>`      |             | Column holding the tenant id                                                   |
| `--label-column <column>`   |             | Column holding the tenant display name                                         |
| `--flag-column <column>`    |             | Column holding the tenant flags                                                |
| `--type <type>`             |             | `string` or `number`, the id column's type                                     |
| `--maps-to <field>`         |             | Field of another tenant, usually the dashboards' tenant, that this one maps to |
| `--maps-to-column <column>` | `--maps-to` | Column on `--table` holding the `--maps-to` tenant id                          |

### quill tenant delete

Delete a tenant type and remove it from dashboard tenant filters.

```sh
quill tenant delete --field <field>
```

| Flag              | Default  |                                      |
| ----------------- | -------- | ------------------------------------ |
| `--field <field>` | required | Tenant field of the tenant to delete |

## Virtual tables

### quill schema list

List virtual tables.

```sh
quill schema list [flags]
```

| Flag              | Default |                                    |
| ----------------- | ------- | ---------------------------------- |
| `--name <string>` |         | Part of the name, case-insensitive |

### quill schema show

Show a virtual table, with 5 sample rows.

```sh
quill schema show (--id <id> | --name <name>)
```

| Flag            | Default                  |                                      |
| --------------- | ------------------------ | ------------------------------------ |
| `--id <id>`     | required unless `--name` | Virtual table ID; used over `--name` |
| `--name <name>` | required unless `--id`   | Virtual table name                   |

### quill schema create

Create a virtual table.

```sh
quill schema create --name <name> --sql <query> [flags]
```

| Flag                      | Default                  |                                                    |
| ------------------------- | ------------------------ | -------------------------------------------------- |
| `--name <name>`           | required                 | Virtual table name, valid as a SQL table name      |
| `--sql <query>`           | required                 | SQL query, without a final `LIMIT`                 |
| `--description <string>`  |                          | Description                                        |
| `--tenant-fields <field>` | every owner tenant field | Tenant field, from `quill tenant list`. Repeatable |

### quill schema update

Update a virtual table.

```sh
quill schema update (--id <id> | --name <name>) [flags]
```

| Flag                      | Default                  |                                             |
| ------------------------- | ------------------------ | ------------------------------------------- |
| `--id <id>`               | required unless `--name` | Virtual table ID; used over `--name`        |
| `--name <name>`           | required unless `--id`   | Virtual table name                          |
| `--new-name <newName>`    |                          | New name                                    |
| `--sql <query>`           |                          | New SQL query, without a final `LIMIT`      |
| `--description <string>`  |                          | Description                                 |
| `--tenant-fields <field>` |                          | Tenant field. Repeatable; replaces the list |

### quill schema delete

Delete a virtual table.

```sh
quill schema delete (--id <id> | --name <name>)
```

| Flag            | Default                  |                                      |
| --------------- | ------------------------ | ------------------------------------ |
| `--id <id>`     | required unless `--name` | Virtual table ID; used over `--name` |
| `--name <name>` | required unless `--id`   | Virtual table name                   |

## Saved queries

### quill saved-query list

List saved queries.

```sh
quill saved-query list [flags]
```

| Flag              | Default |                                            |
| ----------------- | ------- | ------------------------------------------ |
| `--name <string>` |         | Part of the display name, case-insensitive |

### quill saved-query show

Show a saved query.

```sh
quill saved-query show --id <id>
```

| Flag        | Default  |                |
| ----------- | -------- | -------------- |
| `--id <id>` | required | Saved query ID |

### quill saved-query create

Create a saved query.

```sh
quill saved-query create --name <name> --sql <query> [flags]
```

| Flag            | Default  |                             |
| --------------- | -------- | --------------------------- |
| `--name <name>` | required | Display name                |
| `--sql <query>` | required | SQL query on virtual tables |
| `--shared`      |          | Share across dashboards     |

### quill saved-query update

Update a saved query.

```sh
quill saved-query update --id <id> [flags]
```

| Flag                | Default  |                                 |
| ------------------- | -------- | ------------------------------- |
| `--id <id>`         | required | Saved query ID                  |
| `--new-name <name>` |          | New display name                |
| `--sql <query>`     |          | New SQL query on virtual tables |
| `--shared`          |          | Share across dashboards         |
| `--no-shared`       |          | Keep private to its reports     |

### quill saved-query delete

Delete a saved query.

```sh
quill saved-query delete --id <id>
```

| Flag        | Default  |                |
| ----------- | -------- | -------------- |
| `--id <id>` | required | Saved query ID |

## Dashboards

### quill dashboard list

List dashboards.

```sh
quill dashboard list
```

### quill dashboard show

Show a dashboard's reports, sections and filters.

```sh
quill dashboard show --name <string>
```

| Flag              | Default  |                |
| ----------------- | -------- | -------------- |
| `--name <string>` | required | Dashboard name |

### quill dashboard create

Create a dashboard.

```sh
quill dashboard create --name <string> [flags]
```

| Flag                            | Default            |                                                                                                                                                                                                                                |
| ------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--name <string>`               | required           | Dashboard name                                                                                                                                                                                                                 |
| `--enable-date-filter <string>` |                    | Turn on the date filter, with this label                                                                                                                                                                                       |
| `--primary-date-range <type>`   | `Last 30 days`     | `This week`, `This month`, `This quarter`, `This year`, `Last 7 days`, `Last 30 days`, `Last 90 days`, `Last 6 months`, `Last 12 months`, `Previous week`, `Previous month`, `Previous quarter`, `Previous year` or `All time` |
| `--owner-tenant <field>`        | first owner tenant | Tenant field that owns the dashboard                                                                                                                                                                                           |

### quill dashboard update

Update a dashboard.

```sh
quill dashboard update --name <string> [flags]
```

| Flag                            | Default        |                                                                                            |
| ------------------------------- | -------------- | ------------------------------------------------------------------------------------------ |
| `--name <string>`               | required       | Dashboard name                                                                             |
| `--enable-date-filter <string>` |                | Turn on the date filter, with this label                                                   |
| `--disable-date-filter`         |                | Turn off the date filter                                                                   |
| `--primary-date-range <type>`   | `Last 30 days` | As in [`quill dashboard create`](#quill-dashboard-create); requires `--enable-date-filter` |
| `--tenant-filter`               |                | Add a filter on the owner tenant                                                           |
| `--no-tenant-filter`            |                | Remove the tenant filter                                                                   |
| `--add-section <string>`        |                | Add an empty section, last                                                                 |
| `--section-after <string>`      |                | Place `--add-section` after this section; `""` is the default section                      |
| `--section-before <string>`     |                | Place `--add-section` before this section                                                  |
| `--delete-section <string>`     |                | Delete a section; its reports move to the default section                                  |

### quill dashboard delete

Delete a dashboard.

```sh
quill dashboard delete --name <name>
```

| Flag            | Default  |                |
| --------------- | -------- | -------------- |
| `--name <name>` | required | Dashboard name |

## Dashboard filters

### quill dashboard filters list

List dashboard filters.

```sh
quill dashboard filters list [flags]
```

| Flag                   | Default         |                |
| ---------------------- | --------------- | -------------- |
| `--dashboard <string>` | every dashboard | Dashboard name |

### quill dashboard filters create

Add a filter to a dashboard.

```sh
quill dashboard filters create --dashboard <string> --table <string> \
  --field <string> --label-field <string> [flags]
```

| Flag                      | Default   |                                      |
| ------------------------- | --------- | ------------------------------------ |
| `--dashboard <string>`    | required  | Dashboard name                       |
| `--table <string>`        | required  | Virtual table                        |
| `--field <string>`        | required  | Field to filter on                   |
| `--label-field <string>`  | required  | Field shown in the filter's dropdown |
| `--display-name <string>` | `--field` | Filter label                         |
| `--multiselect`           |           | Allow several values                 |

### quill dashboard filters delete

Delete a dashboard filter.

```sh
quill dashboard filters delete --dashboard <string> --id <string>
```

| Flag                   | Default  |                                                |
| ---------------------- | -------- | ---------------------------------------------- |
| `--dashboard <string>` | required | Dashboard name                                 |
| `--id <string>`        | required | Filter ID, from `quill dashboard filters list` |

## Reports

### quill report list

List a dashboard's reports.

```sh
quill report list --dashboard <name>
```

| Flag                 | Default  |                |
| -------------------- | -------- | -------------- |
| `--dashboard <name>` | required | Dashboard name |

### quill report show

Show a report.

```sh
quill report show --id <string>
```

| Flag            | Default  |           |
| --------------- | -------- | --------- |
| `--id <string>` | required | Report ID |

### quill report options

Show the valid values of the report builder flags.

```sh
quill report options --id <string> [flags]
quill report options --datasources <name> [flags]
quill report options --saved-query <id> [flags]
```

| Flag                                          | Default     |                                                                                                                                                         |
| --------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--id <string>`                               |             | Existing report ID                                                                                                                                      |
| `--datasources <name>`                        |             | Virtual table. Repeatable                                                                                                                               |
| `--saved-query <id>`                          |             | Saved query ID, instead of virtual tables                                                                                                               |
| `--dashboard <name>`                          |             | Dashboard whose filters the report must map                                                                                                             |
| `--for <fields>`                              | every group | Comma-separated: `datasources`, `group-rows-by`, `group-columns-by`, `date-bucket`, `aggregations`, `columns`, `chart-type`, `x-axis`, `y-axis`, `sort` |
| [Report builder flags](#report-builder-flags) |             |                                                                                                                                                         |

### quill report create

Create a report.

```sh
quill report create --dashboard <name> --name <name> \
  (--datasources <name> | --saved-query <id>) [flags]
```

| Flag                                          | Default                         |                                          |
| --------------------------------------------- | ------------------------------- | ---------------------------------------- |
| `--dashboard <name>`                          | required                        | Dashboard name                           |
| `--name <name>`                               | required                        | Report name                              |
| `--datasources <name>`                        | required unless `--saved-query` | Virtual table. Repeatable                |
| `--saved-query <id>`                          | required unless `--datasources` | Saved query ID                           |
| `--section <name>`                            |                                 | Dashboard section                        |
| `--display-order <number>`                    |                                 | Position in the section                  |
| `--tenant-access <field=ids>`                 | every tenant                    | `<tenant field>=<id>[,<id>]`. Repeatable |
| [Report builder flags](#report-builder-flags) |                                 |                                          |

### quill report update

Update a report.

```sh
quill report update --id <string> [flags]
```

| Flag                                          | Default  |                                                                                 |
| --------------------------------------------- | -------- | ------------------------------------------------------------------------------- |
| `--id <string>`                               | required | Report ID                                                                       |
| `--name <name>`                               |          | Report name                                                                     |
| `--saved-query <id>`                          |          | Saved query ID to switch to                                                     |
| `--section <name>`                            |          | Dashboard section                                                               |
| `--display-order <number>`                    |          | Position in the section                                                         |
| `--tenant-access <field=ids>`                 |          | `<tenant field>=<id>[,<id>]`. Repeatable                                        |
| `--no-tenant-access`                          |          | Visible to every tenant                                                         |
| `--remove-aggregations <value>`               |          | Remove an aggregation by its exact value, e.g. `sum:orders::amount`. Repeatable |
| `--remove-filters <filter>`                   |          | Remove a filter by its exact value, e.g. `orders::amount>=100`. Repeatable      |
| `--remove-y-axis <field>`                     |          | Remove a y-axis series by output column; not on pivots. Repeatable              |
| `--no-group-rows-by`                          |          | Remove the row grouping; a column grouping takes its place                      |
| `--no-group-columns-by`                       |          | Remove the column grouping                                                      |
| `--no-sort`                                   |          | Remove sorting                                                                  |
| `--no-date-field`                             |          | Remove the date filter mapping                                                  |
| `--no-dashboard-filters`                      |          | Remove every dashboard filter mapping                                           |
| `--no-show-legend`                            |          | Hide the legend                                                                 |
| [Report builder flags](#report-builder-flags) |          |                                                                                 |

### quill report delete

Delete a report.

```sh
quill report delete --id <string>
```

| Flag            | Default  |           |
| --------------- | -------- | --------- |
| `--id <string>` | required | Report ID |

### Report builder flags

| Flag                            | Default                |                                                                                                                        |
| ------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `--date-field <field>`          |                        | `<table>::<field>` for the dashboard's date filter                                                                     |
| `--dashboard-filters <mapping>` |                        | `<filter label>=<table>::<field>`. Repeatable                                                                          |
| `--filters <filter>`            |                        | A [filter](#filters). Repeatable; replaces the list                                                                    |
| `--group-rows-by <field>`       |                        | `<table>::<field>`                                                                                                     |
| `--group-columns-by <field>`    |                        | `<table>::<field>`; requires `--group-rows-by`                                                                         |
| `--date-bucket <bucket>`        | `dynamic`              | `dynamic`, `day`, `week`, `month` or `year`; `dynamic` follows the date range                                          |
| `--aggregations <value>`        |                        | An [aggregation](#aggregations). Repeatable; replaces the list                                                         |
| `--columns <field>`             |                        | `<table>::<field>`. Repeatable; replaces the list                                                                      |
| `--sort <field:direction>`      |                        | `<column>[:asc\|desc]`. Repeatable for table reports; pivots take one                                                  |
| `--chart-type <type>`           |                        | `bar`, `line`, `column`, `stacked`, `stacked bar`, `radar`, `pie`, `metric`, `table`, `gauge`, `US map` or `World map` |
| `--x-axis <field:format:label>` | from `--group-rows-by` | `<column>[:<format>][:<label>]`, with an [axis format](#axis-formats)                                                  |
| `--y-axis <field:format:label>` | from `--aggregations`  | `<column>[:<format>][:<label>]`, with an [axis format](#axis-formats). Repeatable; replaces the list                   |
| `--show-legend`                 |                        | Show the legend                                                                                                        |

#### Filters

| Form                                  | Operators                                                                |
| ------------------------------------- | ------------------------------------------------------------------------ |
| `<table>::<field><operator><value>`   | `=`, `==`, `!=`, `<>`, `>`, `>=`, `<`, `<=`                              |
| `<table>::<field>:<operator>`         | `null`, `notnull`                                                        |
| `<table>::<field>:<operator>:<value>` | `contains:<text>`, `in:<a>,<b>`, `notin:<a>,<b>`, `between:<low>,<high>` |
| `and:<filter>`, `or:<filter>`         | on the first filter, how filters combine; `and` by default               |

#### Aggregations

| Form                                  | Types                                             |
| ------------------------------------- | ------------------------------------------------- |
| `<type>:<table>::<field>`             | `sum`, `average`, `min`, `max`, `percentage`      |
| `<type>:<table>`                      | `count`, `percentage`                             |
| `percentage:<table>::<field>/<field>` | sum of the first field over the sum of the second |

#### Axis formats

| Kind   | Formats                                                                                                             |
| ------ | ------------------------------------------------------------------------------------------------------------------- |
| Number | `whole_number`, `one_decimal_place`, `two_decimal_places`, `dollar_amount`, `dollar_cents`, `percent`, `percentage` |
| Date   | `yyyy`, `MMM_yyyy`, `MMM_dd`, `MMM_dd_yyyy`, `MMM_dd-MMM_dd`, `MMM_dd_hh:mm_ap_pm`, `hh_ap_pm`, `wo`                |
| Text   | `string`                                                                                                            |

## Generate

### quill generate database-schema-query

Print the query that lists the database's tables and columns. Available until
the first `quill schema create`.

```sh
quill generate database-schema-query [flags]
```

| Flag                | Default           |                               |
| ------------------- | ----------------- | ----------------------------- |
| `--database <type>` | the environment's | Database type                 |
| `--schema <name>`   | the environment's | Schema to include. Repeatable |
