2 releases
new 0.1.1 | Jan 11, 2025 |
---|---|
0.1.0 | Jan 11, 2025 |
#1673 in Command line utilities
45KB
808 lines
📋 Notion CLI (Rust)
A powerful command-line interface for managing Notion tasks, written in Rust. Streamline your task management workflow directly from your terminal.
Installation • Features • Setup Guide • Usage • Contributing
📦 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
📝 Task Creation
|
📊 Task Management
|
🔍 Advanced Filtering
|
⚡ Quick Actions
|
🚀 Quick Start
Prerequisites
Click to expand
- Rust and Cargo
- A Notion account
- Notion integration token
- Configured Notion database
Installation
Option 1: Install from crates.io (Recommended)
cargo install notion-cli-rs
Option 2: Install from source
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)
curl -sSL https://raw.githubusercontent.com/CharlonTank/notion-cli-rs/master/install.sh | bash
Additional Installation Options
Unix-like Systems (Linux/macOS)
Local User Installation
# 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
# Requires sudo privileges
sudo cp target/release/notion-cli-rs /usr/local/bin/
Windows Installation
Manual Installation
# 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
# 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
Verify Installation
After installation, verify the CLI is properly installed:
notion-cli-rs --help
🔧 Configuration
1. Create Notion Integration
- Visit Notion Integrations
- Click "New integration"
- Configure capabilities:
- ✅ Read content
- ✅ Update content
- ✅ Insert content
- ✅ Delete content
- Copy the Integration Token
2. Setup Notion Database
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 | - |
3. Configure Environment
cp .env.example .env
NOTION_TOKEN=secret_your_integration_token_here
NOTION_DATABASE_ID=your_database_id_here
LOCAL_TIMEZONE=America/New_York
📖 Usage Examples
Basic Operations
# 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"
View More Examples
Usage Guide
Basic Task Management
# 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
# 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
# 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
# Show general help
notion-cli-rs --help
# Show help for specific command
notion-cli-rs add --help
notion-cli-rs list --help
# etc.
🎯 Task Properties
| Status | Symbol | | Priority | Symbol | |--------|--------||-|----------|--------| | Not Started | ⭕ | | High | 🔴 | | In Progress | 🔄 | | Medium | 🟡 | | Done | ✅ | | Low | 🟢 |
🔍 Troubleshooting
Common Issues and Solutions
Common Issues:
-
Authentication Error:
- Verify your
NOTION_TOKEN
in.env
- Ensure the token starts with
secret_
- Check if the integration has access to the database
- Verify your
-
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
- Verify your
-
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
- If you haven't added the binary to PATH, use
-
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
# Show general help
notion-cli-rs --help
# Show help for specific command
notion-cli-rs add --help
notion-cli-rs list --help
# etc.
🛠️ Development
Development Guidelines
Running Tests
cargo test # Run all tests
cargo test -- --nocapture # With output
Building
cargo build --release
🤝 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 file for details.
Made with ❤️ by CharlonTank
📐 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:
Key API endpoints used:
POST /v1/pages
: Create new tasksPATCH /v1/pages/{id}
: Update task propertiesPOST /v1/databases/{id}/query
: List and filter tasks
🛠️ Development Setup
- Clone and Setup:
git clone https://github.com/CharlonTank/notion-cli-rs.git
cd notion-cli-rs
cargo build
- Environment Setup:
cp .env.example .env
# Edit .env with your test credentials
- Running Tests:
# Unit tests
cargo test
# Integration tests (requires .env setup)
cargo test -- --test integration_tests
# With logging
RUST_LOG=debug cargo test -- --nocapture
- 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
- Authentication Failures:
Error: NOTION_TOKEN environment variable not set
Solution: Ensure .env file exists and contains valid token
- Database Access:
Error: Could not access database
Solution: Check integration permissions and connection
- Invalid Properties:
Error: Invalid task status
Solution: Use exact status values: "Not started", "In progress", "Done"
🔍 Debugging
Enable debug logging:
RUST_LOG=debug notion-cli-rs list
Common debug flags:
RUST_LOG=debug
: Detailed loggingRUST_BACKTRACE=1
: Full error backtracesNOTION_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
Dependencies
~11–25MB
~362K SLoC