# CLI Reference

CLI Reference

## Global Options

| Option | Description |
|--------|-------------|
| `-p, --profile <NAME>` | Profile name to use (uses default if not specified) |

---

## Profiles

Manage authentication profiles.

### `profiles add`

Add a new profile with URL and API tokens.

```bash
bookstack profiles add --name mywiki --url https://wiki.example.com \
  --token-id <TOKEN_ID> --token-secret <TOKEN_SECRET>
```

| Option | Description | Environment Variable |
|--------|-------------|---------------------|
| `--name <NAME>` | Profile name | — |
| `--url <URL>` | BookStack instance URL | `BOOKSTACK_URL` |
| `--token-id <ID>` | API Token ID | `BOOKSTACK_TOKEN_ID` |
| `--token-secret <SECRET>` | API Token Secret | `BOOKSTACK_TOKEN_SECRET` |

### `profiles list`

List all configured profiles.

```bash
bookstack profiles list
```

### `profiles delete`

Delete a profile by name.

```bash
bookstack profiles delete --name mywiki
```

---

## Books

### `list-books`

List all books, optionally filtered by shelf.

```bash
bookstack list-books [--shelf-id <ID>] [--count <NUM>]
```

| Option | Description |
|--------|-------------|
| `--shelf-id <ID>` | Filter by shelf ID |
| `--count <NUM>` | Max results (default: 20) |

### `get-book`

Get details of a single book.

```bash
bookstack get-book <ID>
```

### `create-book`

Create a new book.

```bash
bookstack create-book <NAME> [DESCRIPTION]
```

### `update-book`

Update an existing book.

```bash
bookstack update-book <ID> [--name <NAME>] [--description <DESC>]
```

### `delete-book`

Delete a book.

```bash
bookstack delete-book <ID>
```

---

## Chapters

### `list-chapters`

List all chapters, optionally filtered by book.

```bash
bookstack list-chapters [--book-id <ID>] [--count <NUM>]
```

| Option | Description |
|--------|-------------|
| `--book-id <ID>` | Filter by book ID |
| `--count <NUM>` | Max results (default: 20) |

### `get-chapter`

Get details of a single chapter.

```bash
bookstack get-chapter <ID>
```

### `create-chapter`

Create a new chapter in a book.

```bash
bookstack create-chapter --book-id <ID> --name <NAME> [--description <DESC>]
```

### `update-chapter`

Update an existing chapter.

```bash
bookstack update-chapter <ID> [--name <NAME>] [--description <DESC>] [--book-id <ID>]
```

### `delete-chapter`

Delete a chapter.

```bash
bookstack delete-chapter <ID>
```

---

## Pages

### `list-pages`

List all pages, optionally filtered by book or chapter.

```bash
bookstack list-pages [--book-id <ID>] [--chapter-id <ID>] [--count <NUM>]
```

| Option | Description |
|--------|-------------|
| `--book-id <ID>` | Filter by book ID |
| `--chapter-id <ID>` | Filter by chapter ID (includes sub-chapters) |
| `--count <NUM>` | Max results (default: 20) |

### `get-page`

Get a page with optional content display.

```bash
bookstack get-page <ID> [--content|--markdown]
```

| Option | Description |
|--------|-------------|
| `--content` | Show full HTML content |
| `--markdown` | Show markdown content |

### `create-page`

Create a new page in a book or chapter.

```bash
bookstack create-page --name <NAME> \
  [--book-id <ID>] [--chapter-id <ID>] \
  [--html <HTML>] [--markdown <MD>] [--content <TEXT>]
```

At least one of `--book-id` or `--chapter-id` is required. At least one of `--html`, `--markdown`, or `--content` is required.

### `update-page`

Update an existing page.

```bash
bookstack update-page <ID> \
  [--name <NAME>] [--html <HTML>] [--markdown <MD>] [--content <TEXT>] \
  [--book-id <ID>] [--chapter-id <ID>]
```

### `delete-page`

Delete a page.

```bash
bookstack delete-page <ID>
```

---

## Shelves

### `list-shelves`

List all shelves.

```bash
bookstack list-shelves [--count <NUM>]
```

### `get-shelf`

Get details of a single shelf.

```bash
bookstack get-shelf <ID>
```

### `create-shelf`

Create a new shelf.

```bash
bookstack create-shelf <NAME> [DESCRIPTION]
```

---

## Search

Search across all content types.

```bash
bookstack search <QUERY> [--type <TYPE>] [--count <NUM>]
```

| Option | Description |
|--------|-------------|
| `--type <TYPE>` | Filter by type: `page`, `chapter`, `book`, `bookshelf` |
| `--count <NUM>` | Max results (default: 20) |

### Examples

```bash
# Search all content for "rust"
bookstack search "rust"

# Search only pages
bookstack search "rust" --type page

# Search with limit
bookstack search "configuration" --count 5
```