# GitLab CLI Development

GitLab Duo CLI (`@gitlab/duo-cli`) - GitLab Duo for your command line.

## Installing

The Duo CLI can be installed from the npm registry using `npm`, `bun`, `yarn` etc:

```shell
npm install -g @gitlab/duo-cli
```

After installing, the CLI can be run with `duo`.

Alternatively, the CLI can be directly run without an explicit install:

```shell
npx -y @gitlab/duo-cli
```

### Updating

The CLI can be updated the same way you installed it, specifying `@latest` to ensure the latest version is installed:

```shell
npm install -g @gitlab/duo-cli@latest
```

### Usage

Run `duo` to start the CLI terminal UI. You will be prompted for an [authentication token](https://docs.gitlab.com/user/profile/personal_access_tokens/) on first run. Your token must have the `api` scope granted.

The CLI help text can be displayed with the `--help` flag, globally or per-command for more details:

```shell
duo --help
duo run --help
```

This will provide details of all available commands and flags.

## Contributing

### Prerequisites

This CLI project is built using [bun](https://bun.sh/). Make sure you have the following installed:

1. Install mise and bun: `mise install`
1. Install dependencies using bun package manager: `npm run install:bun`

in order to continue working with the language server, install dependencies with npm package manager: `npm run install:npm`

### Compilation

To create standalone executables for distribution, use the compilation script:

```shell
npm run build:binary
```

This will create cross-platform executables in the `./bin` directory:

- `duo-linux-x64` - Linux 64-bit
- `duo-linux-arm64` - Linux ARM64
- `duo-darwin-x64` - macOS Intel
- `duo-darwin-arm64` - macOS Apple Silicon
- `duo-windows-x64.exe` - Windows 64-bit

#### Development

There are a few handy commands available for development:

- `dev:watch` - starts the application with bun in watch mode. The application will be automatically restarted if code changes are made
- `dev:watch-tools` - as above, but react devtools will be started alongside connected to the application
- `start` - compiles the application to js and starts it. This is exactly the version of the app that will be packaged to the npm package. It is recommended to test your changes with it before creating an MR

When using the `package.json` scripts, use `--` to separate flags between npm/CLI. For example:

```shell
cd packages/cli
npm run dev:watch -- --cwd /foo/bar # this passes through --cwd to the CLI, rather than npm itself getting the flag
```

### Troubleshooting

If you have issues with Bun not resolving installed node_modules in the packages, you may need to clear node_modules folders and reinstall:

```shell
npm run install:bun
```
