# Commands

Full reference for all `fma` CLI commands.

## Global options

```bash
fma [--debug] <command>
```

| Option      | Description                                                     |
|-------------|-----------------------------------------------------------------|
| `--debug`   | Enable verbose debug logging. Useful for troubleshooting.       |

Example:

```bash
fma --debug deploy
```

---

## `fma init`

Initialize a new model project.

```bash
fma init <model_name>
```

Creates a directory `<model_name>/` with a `model.py` template and an empty `metadata.yaml` in the current folder.

**Example:**

```bash
mkdir my-project && cd my-project
fma init image_generator
```

Result:

```
my-project/
├── image_generator/
│   └── model.py
└── metadata.yaml
```

---

## `fma login`

Authenticate with FlyMyAI.

```bash
fma login [--username <username>] [--password <password>]
```

| Option       | Description                                       |
|--------------|---------------------------------------------------|
| `--username` | Your FlyMyAI username. Prompted if not provided.  |
| `--password` | Your FlyMyAI password. Prompted securely if not provided. |

Credentials are stored locally in `~/.config/fma/config.yaml`.

**Examples:**

```bash
# Provide credentials inline
fma login --username alice --password s3cret

# Interactive - prompts for username and password
fma login
```

---

## `fma logout`

Log out and clear stored credentials.

```bash
fma logout
```

Removes the auth token and profile from local configuration.

---

## `fma deploy`

Deploy the current model to FlyMyAI infrastructure.

```bash
fma deploy
```

Must be run from the project root directory (the folder that contains your `<model_name>/` folder and `metadata.yaml`). Requires authentication via `fma login` first.

On success, the model metadata is written to `metadata.yaml`.

**Example:**

```bash
cd my-project
fma deploy
# => Successfully deployed model image_generator! ✅
# => Model data was saved in metadata.yaml file
```

If the model already exists, the CLI will suggest running `fma update` instead.

---

## `fma update`

Redeploy the model. This is a shortcut that runs `fma delete` followed by `fma deploy`.

```bash
fma update
```

Use this when you've made changes to your model and want to push a new version under the same name.

**Example:**

```bash
# After modifying model.py
fma update
# => Model deleted successfully! ✅
# => Successfully deployed model image_generator! ✅
```

---

## `fma delete`

Delete the currently deployed model.

```bash
fma delete
```

Removes the model from FlyMyAI infrastructure. Requires authentication.

**Example:**

```bash
fma delete
# => Model deleted successfully! ✅
```

---

## `fma logs`

Fetch startup logs for the deployed model. This is useful for debugging issues during model initialization (e.g. missing dependencies, import errors, crashes in `initialize()`).

```bash
fma logs [--output-file <filename>]
```

| Option          | Description                                              |
|-----------------|----------------------------------------------------------|
| `--output-file` | Save logs to a file instead of printing to the terminal. |

**Examples:**

```bash
# Print logs to terminal
fma logs

# Save logs to a file
fma logs --output-file startup_logs.txt
# => Logs were save into startup_logs.txt.
```

> **Tip**
>
> If the model started successfully, logs may not be available. You will see a message:
> ```
> Logs are not available. This could happen because project started succesfully.
> ```
> This is normal - startup logs are primarily available when something goes wrong.

---

## Typical workflow

Here is a complete example of the end-to-end workflow:

```bash
# 1. Create and enter a project directory
mkdir my-project && cd my-project

# 2. Initialize the model
fma init text_summarizer

# 3. Edit the model code
#    (edit text_summarizer/model.py with your inference logic)

# 4. Log in
fma login

# 5. Deploy
fma deploy

# 6. Check logs if something went wrong
fma logs --output-file logs.txt

# 7. Make changes and redeploy
fma update

# 8. When you're done, clean up
fma delete
```
