notion-cli-rs 0.1.1

A powerful command-line interface for managing Notion tasks
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# 📋 Notion CLI (Rust)

<div align="center">

[![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge&logo=rust&logoColor=white)](https://www.rust-lang.org/)
[![Notion](https://img.shields.io/badge/Notion-%23000000.svg?style=for-the-badge&logo=notion&logoColor=white)](https://www.notion.so/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge)](http://makeapullrequest.com)
[![Minimum Rust Version](https://img.shields.io/badge/rust-1.70%2B-orange.svg?style=for-the-badge)](https://www.rust-lang.org/)
[![Crates.io](https://img.shields.io/crates/v/notion-cli-rs?style=for-the-badge)](https://crates.io/crates/notion-cli-rs)

A powerful command-line interface for managing Notion tasks, written in Rust. 
Streamline your task management workflow directly from your terminal.

[Installation](#installation) •
[Features](#features) •
[Setup Guide](#notion-setup-detailed-guide) •
[Usage](#usage-guide) •
[Contributing](#contributing)

---

</div>

## 📦 Dependencies

This project relies on the following major dependencies:

- **reqwest** (0.11): HTTP client for making API requests
- **tokio** (1.0): Async runtime for handling concurrent operations
- **serde** (1.0): Serialization/deserialization of JSON data
- **clap** (4.0): Command-line argument parsing
- **anyhow** (1.0): Error handling
- **dotenv** (0.15): Environment variable management

For development:
- **mockito** (1.2): HTTP mocking for tests
- **env_logger** (0.10): Logging during development

## 🔧 Requirements

- Rust 1.70 or higher
- Notion API Version: 2022-06-28
- Unix-like OS (Linux/macOS) or Windows
- Notion account with integration capabilities

## ✨ Features

<div align="center">
<table>
<tr>
<td>

### 📝 Task Creation
- Create tasks with rich metadata
- Set priority levels 🔴 🟡 🟢
- Add due dates 📅
- Assign tags 🏷️
- Include descriptions 📝

</td>
<td>

### 📊 Task Management
- Update task status ⭕ 🔄 ✅
- Modify priorities
- Change due dates
- Edit descriptions
- Manage tags

</td>
</tr>
<tr>
<td>

### 🔍 Advanced Filtering
- Filter by status
- Filter by priority
- Filter by tags
- Sort by due date
- Colored terminal output

</td>
<td>

### ⚡ Quick Actions
- Mark tasks complete
- Set task priorities
- Update task status
- Delete tasks
- Bulk operations

</td>
</tr>
</table>
</div>

## 🚀 Quick Start

### Prerequisites

<details>
<summary>Click to expand</summary>

- [Rust and Cargo]https://www.rust-lang.org/tools/install
- A Notion account
- Notion integration token
- Configured Notion database

</details>

### Installation

#### Option 1: Install from crates.io (Recommended)
```bash
cargo install notion-cli-rs
```

#### Option 2: Install from source
```bash
git clone https://github.com/CharlonTank/notion-cli-rs.git
cd notion-cli-rs
cargo install --path .
```

#### Option 3: One-Line Installation Script (Unix-like Systems)
```bash
curl -sSL https://raw.githubusercontent.com/CharlonTank/notion-cli-rs/master/install.sh | bash
```

<details>
<summary>Additional Installation Options</summary>

### Unix-like Systems (Linux/macOS)

#### Local User Installation
```bash
# Create local bin directory if it doesn't exist
mkdir -p ~/.local/bin

# Copy the binary
cp target/release/notion-cli-rs ~/.local/bin/

# Add to PATH in your shell's configuration file:

# For Bash (add to ~/.bashrc or ~/.bash_profile)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

# For Zsh (add to ~/.zshrc)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# For Fish (recommended way)
fish_add_path ~/.local/bin
```

#### System-wide Installation
```bash
# Requires sudo privileges
sudo cp target/release/notion-cli-rs /usr/local/bin/
```

### Windows Installation

#### Manual Installation
```powershell
# Create a directory for the binary
mkdir -p "$env:USERPROFILE\bin"

# Copy the binary
copy "target\release\notion-cli-rs.exe" "$env:USERPROFILE\bin"

# Add to PATH in PowerShell (current session)
$env:PATH += ";$env:USERPROFILE\bin"

# Add to PATH permanently (run in PowerShell as Administrator)
[Environment]::SetEnvironmentVariable(
    "Path",
    [Environment]::GetEnvironmentVariable("Path", "User") + ";$env:USERPROFILE\bin",
    "User"
)
```

#### Using Scoop
```powershell
# Install Scoop if not already installed
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

# Create and switch to a new directory for the package
mkdir ~/.scoop/apps/notion-cli-rs
cd ~/.scoop/apps/notion-cli-rs

# Copy the binary
copy "target\release\notion-cli-rs.exe" "notion-cli-rs.exe"

# Add to Scoop's shims
scoop shim add notion-cli-rs
```

</details>

### Verify Installation

After installation, verify the CLI is properly installed:
```bash
notion-cli-rs --help
```

## 🔧 Configuration

<details>
<summary>1. Create Notion Integration</summary>

1. Visit [Notion Integrations]https://www.notion.so/my-integrations
2. Click "New integration"
3. Configure capabilities:
   - ✅ Read content
   - ✅ Update content
   - ✅ Insert content
   - ✅ Delete content
4. Copy the Integration Token

</details>

<details>
<summary>2. Setup Notion Database</summary>

Create a database with these properties:
| Property | Type | Options |
|----------|------|---------|
| Name | Title | - |
| Status | Select | Not started, In progress, Done |
| Priority | Select | High, Medium, Low |
| Due Date | Date | - |
| Tags | Multi-select | Custom tags |
| Description | Text | - |

</details>

<details>
<summary>3. Configure Environment</summary>

```bash
cp .env.example .env
```

```env
NOTION_TOKEN=secret_your_integration_token_here
NOTION_DATABASE_ID=your_database_id_here
LOCAL_TIMEZONE=America/New_York
```

</details>

## 📖 Usage Examples

### Basic Operations

```bash
# Create a task
notion-cli-rs add "Deploy new feature" \
  --priority high \
  --due "2024-01-20" \
  --tags "dev,feature" \
  --description "Deploy the new authentication system"

# List tasks
notion-cli-rs list

# Update status
notion-cli-rs status <task-id> "in progress"
```

<details>
<summary>View More Examples</summary>

## Usage Guide

### Basic Task Management

```bash
# Add a simple task
notion-cli-rs add "Buy groceries"

# Add a detailed task
notion-cli-rs add "Quarterly report" \
  --priority high \
  --due "2024-01-20" \
  --tags "work,reports,q4" \
  --description "Prepare Q4 2023 financial report for stakeholders"

# List all tasks
notion-cli-rs list

# List tasks with filters
notion-cli-rs list --status "in progress" --priority high

# Update task status
notion-cli-rs status <task-id> "in progress"
notion-cli-rs status <task-id> "done"

# Delete a task
notion-cli-rs delete <task-id>
```

### Advanced Task Management

```bash
# Set/update task priority
notion-cli-rs priority <task-id> high

# Set/update due date
notion-cli-rs due-date <task-id> "2024-01-20"

# Add/update tags
notion-cli-rs tags <task-id> "urgent,priority,q4"

# Set/update description
notion-cli-rs description <task-id> "Detailed task description here"
```

### Filtering and Sorting

```bash
# List high priority tasks
notion-cli-rs list --priority high

# List in-progress tasks
notion-cli-rs list --status "in progress"

# List tasks with specific tag
notion-cli-rs list --tag work

# List tasks sorted by due date
notion-cli-rs list --sort-by-due
```

### Getting Help

```bash
# Show general help
notion-cli-rs --help

# Show help for specific command
notion-cli-rs add --help
notion-cli-rs list --help
# etc.
```

</details>

## 🎯 Task Properties

<div align="center">

| Status | Symbol | | Priority | Symbol |
|--------|--------||-|----------|--------|
| Not Started || | High | 🔴 |
| In Progress | 🔄 | | Medium | 🟡 |
| Done || | Low | 🟢 |

</div>

## 🔍 Troubleshooting

<details>
<summary>Common Issues and Solutions</summary>

### Common Issues:

1. **Authentication Error:**
   - Verify your `NOTION_TOKEN` in `.env`
   - Ensure the token starts with `secret_`
   - Check if the integration has access to the database

2. **Database Not Found:**
   - Verify your `NOTION_DATABASE_ID` in `.env`
   - Ensure the integration is connected to the database
   - Check if the database structure matches the requirements

3. **Command Not Found:**
   - If you haven't added the binary to PATH, use `cargo run -- <command>` instead of direct binary calls
   - Ensure you're in the project directory when using `cargo run`

4. **Invalid Property Values:**
   - Status must be exactly: "Not started", "In progress", or "Done"
   - Priority must be exactly: "High", "Medium", or "Low"
   - Due dates must be in YYYY-MM-DD format

### Getting Help

```bash
# Show general help
notion-cli-rs --help

# Show help for specific command
notion-cli-rs add --help
notion-cli-rs list --help
# etc.
```

</details>

## 🛠️ Development

<details>
<summary>Development Guidelines</summary>

### Running Tests
```bash
cargo test         # Run all tests
cargo test -- --nocapture  # With output
```

### Building
```bash
cargo build --release
```

</details>

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

<div align="center">

Made with ❤️ by [CharlonTank](https://github.com/CharlonTank)

</div>

## 📐 Project Structure

```
notion-cli-rs/
├── src/
│   ├── main.rs      # CLI entry point and command handling
│   ├── lib.rs       # Library interface
│   ├── notion.rs    # Notion API client implementation
│   └── config.rs    # Configuration management
├── tests/
│   └── integration_tests.rs  # Integration tests
├── .env.example     # Environment variables template
├── Cargo.toml       # Project dependencies
└── install.sh       # Installation script
```

## 🔌 Notion API

This CLI uses the Notion API v2022-06-28. For detailed API documentation, visit:
- [Notion API Reference]https://developers.notion.com/reference
- [Notion API Guides]https://developers.notion.com/docs

Key API endpoints used:
- `POST /v1/pages`: Create new tasks
- `PATCH /v1/pages/{id}`: Update task properties
- `POST /v1/databases/{id}/query`: List and filter tasks

## 🛠️ Development Setup

1. **Clone and Setup:**
```bash
git clone https://github.com/CharlonTank/notion-cli-rs.git
cd notion-cli-rs
cargo build
```

2. **Environment Setup:**
```bash
cp .env.example .env
# Edit .env with your test credentials
```

3. **Running Tests:**
```bash
# Unit tests
cargo test

# Integration tests (requires .env setup)
cargo test -- --test integration_tests

# With logging
RUST_LOG=debug cargo test -- --nocapture
```

4. **Code Style:**
- Follow Rust standard naming conventions
- Use `cargo fmt` before committing
- Run `cargo clippy` for linting
- Ensure all public items are documented

## ⚠️ Error Handling

### API Errors

| Error Code | Description | Solution |
|------------|-------------|----------|
| 401 | Unauthorized | Check your NOTION_TOKEN |
| 404 | Not Found | Verify database/page IDs |
| 409 | Conflict | Check for duplicate operations |
| 429 | Rate Limited | Implement backoff strategy |

### Common Issues

1. **Authentication Failures:**
```
Error: NOTION_TOKEN environment variable not set
Solution: Ensure .env file exists and contains valid token
```

2. **Database Access:**
```
Error: Could not access database
Solution: Check integration permissions and connection
```

3. **Invalid Properties:**
```
Error: Invalid task status
Solution: Use exact status values: "Not started", "In progress", "Done"
```

## 🔍 Debugging

Enable debug logging:
```bash
RUST_LOG=debug notion-cli-rs list
```

Common debug flags:
- `RUST_LOG=debug`: Detailed logging
- `RUST_BACKTRACE=1`: Full error backtraces
- `NOTION_API_URL`: Override API endpoint (testing)

## 📊 Performance

- Concurrent API requests where possible
- Connection pooling for multiple operations
- Efficient JSON parsing
- Minimal memory footprint

## 🔒 Security

- Tokens are never logged
- Environment variables for sensitive data
- HTTPS for all API communication
- No data caching by default