npm package: @gext/cli
Description: CLI for Gext by ixigo - Google Docs/Slides template engine. Create templates, generate documents, manage forms, and more.
Author: ixigo
Latest version: 1.1.0

<div align="center">

# Gext CLI

**Command-line interface for [Gext](https://gext.ixigo.com) -- the Google Docs/Slides template engine.**

Built by [ixigo](https://www.ixigo.com)

[Website](https://gext.ixigo.com) | [Documentation](https://gext.ixigo.com/help) | [AI Agents (MCP)](https://gext.ixigo.com/agents)

</div>

## Installation

```bash
npm install -g @gext/cli
```

Or run locally from the project:

```bash
npm link
```

## Quick Start

```bash
# Sign in with Google
gext login

# Check who you are
gext whoami

# Search your Drive for documents
gext drive search "Invoice Template"

# Create a template from a Google Doc
gext templates create --file 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms

# List your templates
gext templates list

# View template schema (variables)
gext templates schema <template-id>

# Generate a document with inline JSON
gext generate <template-id> --json '{"name": "John Doe", "amount": "1500"}'

# Generate interactively
gext generate <template-id> --interactive
```

## Commands

### Authentication

```bash
# Sign in (opens browser for Google OAuth)
gext login
gext login --full-access    # Request full Drive/Docs/Slides permissions

# Show current user
gext whoami

# Sign out
gext logout
```

### Templates

```bash
# List all templates
gext templates list
gext templates list --json

# Get template details
gext templates get <id>
gext templates get <id> --json

# Create from a Google Doc/Slides file
gext templates create --file <google-doc-id>
gext templates create --file <google-doc-id> --name "My Template"

# Show variable schema
gext templates schema <id>
gext templates schema <id> --json

# Generate AI sample data for variables
gext templates sample-data <id>
gext templates sample-data <id> --context "US healthcare"

# Delete a template
gext templates delete <id>
```

### Document Generation

```bash
# Generate with inline JSON
gext generate <id> --json '{"name": "Alice", "date": "2026-03-05"}'

# Generate from a JSON file
gext generate <id> --file data.json

# Interactive mode (prompts for each variable)
gext generate <id> --interactive

# Pipe JSON from stdin
echo '{"name": "Bob"}' | gext generate <id>

# Use API key instead of session (for automation)
gext generate <id> --json '{"name": "Bot"}' --api-key gext_sk_xxx

# Get structured JSON output
gext generate <id> --json '{"name": "Alice"}' --output-json
```

### Google Drive

```bash
# Search for documents and slides
gext drive search "quarterly report"

# Search for folders
gext drive search "invoices" --type folder

# JSON output (pipe to jq)
gext drive search "template" --json | jq '.[].name'
```

### Public Forms

```bash
# Enable/disable public form for a template
gext form enable <template-id>
gext form disable <template-id>

# Get the public form URL
gext form link <template-id>

# Fetch form schema (no auth required)
gext form get <form-token>
gext form get <form-token> --json

# Submit a form (no auth required)
gext form submit <form-token> --json '{"name": "Jane", "email": "jane@example.com"}'
gext form submit <form-token> --file submission.json
cat data.json | gext form submit <form-token>

# JSON output
gext form submit <form-token> --json '{"name": "Jane"}' --output-json
```

### API Keys

```bash
# Show the API key for a template
gext api-key show <template-id>

# Regenerate (rotate) the API key
gext api-key regenerate <template-id>
```

### Configuration

```bash
# List all settings
gext config list

# Point to a different server (e.g., local dev)
gext config set serverUrl http://localhost:5173

# Reset to production
gext config set serverUrl https://gext.ixigo.com

# Get a specific value
gext config get serverUrl
```

## Recipes

### Batch generate documents from a CSV

```bash
# Convert CSV to JSON lines, then generate for each row
cat contacts.csv | python3 -c "
import csv, json, sys
reader = csv.DictReader(sys.stdin)
for row in reader:
    print(json.dumps(row))
" | while read -r line; do
  gext generate <template-id> --json "$line" --output-json
done
```

### Integrate with CI/CD

```bash
# Use API key auth (no browser login needed)
gext generate <template-id> \
  --api-key "$GEXT_API_KEY" \
  --json '{"version": "'$VERSION'", "date": "'$(date +%Y-%m-%d)'"}' \
  --output-json
```

### Search Drive and create template in one go

```bash
# Find the doc ID, then create a template
DOC_ID=$(gext drive search "Invoice" --json | jq -r '.[0].id')
gext templates create --file "$DOC_ID" --name "Invoice Template"
```

### Generate sample data and use it to generate a document

```bash
gext templates sample-data <id> | gext generate <id>
```

### Agent/automation workflow

```bash
# 1. List templates to find the right one
gext templates list --json | jq '.[] | {id, name}'

# 2. Get schema to know what variables are needed
gext templates schema <id> --json

# 3. Generate document
gext generate <id> --json '{"field1": "value1", "field2": "value2"}' --output-json

# 4. Extract the PDF URL from output
PDF_URL=$(gext generate <id> --json '...' --output-json | jq -r '.pdf_url')
```

## Output Formats

Most commands support `--json` for machine-readable output. This makes it easy to pipe results through `jq` or use in scripts.

```bash
# Pretty-print template list
gext templates list --json | jq '.[] | {id, name, created_at}'

# Get just template IDs
gext templates list --json | jq -r '.[].id'
```

## Configuration Storage

Credentials and configuration are stored at:
- **macOS**: `~/Library/Preferences/gext-nodejs/config.json`
- **Linux**: `~/.config/gext-nodejs/config.json`
- **Windows**: `%APPDATA%/gext-nodejs/config.json`

The session token is a JWT with a 30-day expiry. Run `gext login` to refresh it.

## Related

- [Gext Web App](https://gext.ixigo.com) -- Create and manage templates in the browser
- [Gext MCP Server](https://gext.ixigo.com/agents) -- Connect AI agents (Claude, Cursor, Gemini, ChatGPT) via Model Context Protocol
- [ixigo](https://www.ixigo.com) -- Built with care by the ixigo team

## License

MIT