# Commands

## Initialization

To get started in no time, the `init` command will walk you through the basic commands to help you set the string sources that you would like to connect to your codebase, and the output file location (existing or a newly created one).

To initialize the CLI, run the next command and follow the instructions:

```bash
$ frontitude init
```

## Connect to data source

Connecting string sources (Frontitude **projects**, **project folders**, or the **copy library**) to your codebase will let you to pull their latest copy into your codebase and stay up to date effortlessly.

To set the sources that you would like to connect to your codebase, run the next command and use the checkbox selection:

```bash
$ frontitude source set
```

To view the list of connected sources:

```bash
$ frontitude source list
```

## Pull

After setting the sources that you would like to connect to your codebase, you will be able to pull their latest copy directly to the configured output file, that later can be consumed in your codebase using any i18n framework of your choice (e.g. [i18next](https://www.i18next.com/), [react-i18next](https://react.i18next.com/), etc.), or directly (using require/import).

To pull the latest copy from your connected sources:

```bash
$ frontitude pull
```

Options:

| Name                     | Default | Description                                                                                                                                                                                                                                                |
| ------------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--nested`               | `false` | *Applicable for JSON format only.* By default, content is pulled in a flat format. Setting this option to `true` will output the content in a nested structure, where keys are broken into namespaces according to the workspace key convention delimiter. |
| `--status`               | `all`   | Available statuses: draft/review/final/all.                                                                                                                                                                                                                |
| `--has-key`              | `false` | Use this flag to pull only content that has been assigned keys. By default, content without keys is assigned auto-generated, non-human-readable IDs.                                                                                                       |
| `--tags`                 | `''`    | Pull content by tags. Specify comma-separated tag names string to filter copy (AND relation).                                                                                                                                                              |
| `--include-metadata`     | `false` | Include metadata for each text, such as tags, status, note, mixed style indication, and more.                                                                                                                                                              |
| `--include-translations` | `false` | Include latest translations. Each locale is saved to a dedicated file, in the same location as the source file. The locale will be concatenated to the file’s name as part of the extension. E.g. ./strings-es.json                                        |
| `--dry-run`              | `false` | Display the results in the CLI without creating or updating any files.                                                                                                                                                                                     |
| `--access-token`         |         | Authenticate the pull request using this access token, taking precedence over any other configured access token.                                                                                                                                           |
| `--pages`                |         | Filter content by Frontitude pages from your connected projects. Specify a comma-separated page names string to filter content (OR relation). **Applicable only when the source is a project.**                                                            |
| `--screens`              |         | Filter content by Frontitude screens from your connected projects. Specify a comma-separated screen names string to filter content (OR relation). **Applicable only when the source is a project.**                                                        |

## Using command aliases

To make it easier to run long commands in web projects, you can use the [scripts section in your package.json](https://docs.npmjs.com/cli/v11/using-npm/scripts).

Here’s an example of a command you can add:

```json
"scripts": {
  "pull-copy": "frontitude pull --has-key --tags=Repo1"
}
```

This allows you to run the following command to fetch content from Frontitude:

```sh
npm run pull-copy
```
