Transform any REST API into a powerful command-line interface
anything-cli is a flexible CLI tool that allows you to interact with any REST API through the command line. It dynamically creates custom commands, handles authentication headers, and provides extensible instruction processing for automated workflows.
- Your own command: Install this CLI with any custom command name
- REST API Integration: Seamlessly interact with any HTTP REST API
- Flexible Parameter Handling: Support for query parameters, flags, and nested endpoints
- Custom Headers: Configure authentication and custom headers
- Git Context Awareness: Automatically includes git repository information in requests
- Instruction Processing: Execute server-defined instructions for automation
- Auto-Update: Built-in update command to get the latest version
- Cross-Platform: Supports macOS (Intel/Apple Silicon) and Linux
- Zero Configuration: Works out of the box with minimal setup
Install the CLI with a custom command name and base URL:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/suchlab/anything-cli/HEAD/install/install.sh)" -- --cmd "my-api" --base-url "https://api.example.com"Parameters:
--cmd: Your custom command name (e.g.,github-cli,slack-bot,company-api)--base-url: The base URL of the API you want to interact with
Interactive Installation:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/suchlab/anything-cli/HEAD/install/install.sh)"The installer will prompt you for the command name and base URL.
- macOS: Intel (x64) and Apple Silicon (ARM64)
- Linux: x64
Once installed with your custom command name (e.g., my-api), you can use it to interact with your API:
# Get the root endpoint
my-api # /
# Access specific endpoints
my-api users # /users
my-api users 123 # /users/123
my-api posts recent # /posts/recent
# With query parameters
my-api users --limit 10 --sort name # /users?limit=10&sort=name
my-api search --q "rust programming" --type repositories # /search?q=rust%20programing&type=repositories
# Using flags
my-api posts --published --format json # /posts?published=true&format=json
# Mixed parameters and flags
my-api users/123/posts --limit 5 --draft --since 2023-01-01 # /users/123/posts?limit=5&draft=true&since=2022-04-28<command-name> [endpoint/path] [--param value] [--flag] [-f]
- Endpoint/Path: Path appended to base URL
- Parameters:
--key valueor--key=valueformat - Flags:
--flag(sets flag to "true") - Short Flags:
-f(single character flags)
Each installation includes built-in management commands:
# Set or update headers (for authentication, etc.)
my-api self:set-header "Authorization" "Bearer your-token-here"
my-api self:set-header "X-API-Key" "your-api-key"
# Remove a header
my-api self:set-header "Authorization"
# Update the base URL
my-api self:set-base-url "https://new-api.example.com"
# Update to the latest version
my-api self:update
# Uninstall the command
my-api self:uninstall
# Check version
my-api --version
my-api -vThe CLI creates a configuration directory at ~/.{command-name}/ with a config.json file:
{
"base_url": "https://api.example.com",
"headers": {
"Authorization": "Bearer your-token",
"X-API-Key": "your-key"
}
}# View current configuration
cat ~/.my-api/config.json
# Set headers programmatically
my-api self:set-header "Authorization" "Bearer $(get-fresh-token)"
# Update base URL
my-api self:set-base-url "https://staging-api.example.com"The CLI includes a built-in update mechanism to keep your installation current:
my-api self:updateThe update command will:
- Check your current version against the latest GitHub release
- Download and install the latest version if available
- Show a message if you're already up to date
- Handle system permissions automatically (may prompt for sudo)
The CLI supports a special response schema that enables server-controlled instruction execution:
{
"schema": "anything-cli/v0.1",
"instructions": [
{
"action": "print",
"content": "Hello, World!",
"error": false
},
{
"action": "execute",
"content": "echo 'Running command'",
}
]
}ping: Responds with "pong" (useful for testing)print: Prints content to stdout (or stderr iferror: true)execute: Executes shell commandsnone: Exits silently (with optional error iferror: true)
{
"schema": "anything-cli/v0.1",
"instructions": [
{
"action": "print",
"content": "π Deployment started..."
},
{
"action": "execute",
"content": "git pull origin main && npm install && npm run build"
},
{
"action": "print",
"content": "β
Deployment completed successfully!"
}
]
}- Rust 1.70 or later
- Cargo (comes with Rust)
# Clone the repository
git clone https://github.com/suchlab/anything-cli.git
cd anything-cli
# Build the project
cargo build
# Run tests
cargo test
# Build for release
cargo build --release# Format code
cargo fmt
# Check for errors without building
cargo check
# Run clippy for linting
cargo clippy
# Run tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Build debug version
cargo build
# Build optimized release version
cargo build --release
# Clean build artifacts
cargo clean
# Update dependencies
cargo update
# Generate documentation
cargo doc --open# Run directly with cargo
cargo run -- --help
# Test with sample commands (Make sure ~/.anything-cli/config.json exists)
cargo run -- users --limit 10
cargo run -- self:set-header "Authorization" "Bearer test-token"
# Build and test the binary
cargo build
./target/debug/anything-cli --version# Test locally (requires setting up a local binary)
./install/install.sh --cmd "test-cli" --base-url "https://httpbin.org"
# Test the installed command
test-cli get --format json
test-cli self:set-header "X-Test" "value"
test-cli self:update
test-cli self:uninstallanything-cli/
βββ Cargo.toml # Rust project configuration and dependencies
βββ Cargo.lock # Dependency lock file
βββ LICENSE # MIT license
βββ README.md # Project documentation
βββ benches/
β βββ cli_benchmarks.rs # Performance benchmarks
βββ install/
β βββ install.sh # Installation script for end users
βββ src/
β βββ lib.rs # Library entry point
β βββ main.rs # Application entry point and request handling
β βββ cli/
β β βββ args.rs # Command-line interface definition
β β βββ parse.rs # Parameter and flag parsing logic
β βββ commands/
β β βββ set_base_url.rs # Base URL management command
β β βββ set_header.rs # Header management command
β β βββ uninstall.rs # Uninstallation command
β β βββ update.rs # Update command
β βββ config/
β β βββ data.rs # Configuration data structures
β β βββ loader.rs # Configuration loading logic
β β βββ saver.rs # Configuration saving logic
β βββ instructions/
β β βββ mod.rs # Instruction processing engine
β βββ schema/
β β βββ mod.rs # Anything-CLI schema parsing
β βββ utils/
β βββ executable.rs # Executable name detection
β βββ git.rs # Git repository context detection
βββ tests/
β βββ integration_tests.rs # Integration test suite
βββ target/ # Build artifacts (generated)
cli: Command-line parsing and argument handlingconfig: Configuration file managementcommands: Built-in command implementationsinstructions: Server instruction processingschema: Response schema parsingutils: Utility functions for git context and executable detection
- Parse CLI arguments into commands, parameters, and flags
- Load configuration from
~/.{command-name}/config.json - Build HTTP request with endpoint, query parameters, and headers
- Add context headers including git repository information
- Send request to the configured API
- Process response through schema parser
- Execute instructions or display response content
The CLI automatically adds several headers to requests:
User-Agent:anything-cli/v{version} ({command-name}; repo: https://github.com/suchlab/anything-cli)x-anything-cli-version: CLI versionx-anything-cli-executable-name: Custom command namex-anything-cli-git: "true" (if in git repository)x-anything-cli-git-repo-url: Git remote URLx-anything-cli-git-repo-name: Repository namex-anything-cli-git-branch: Current branch name
- Prepare main branch with all changes
- Create tag: Use GitHub Actions workflow "create tag"
- Create release: Use GitHub Actions workflow "create release"
This automatically builds binaries for all supported platforms and creates a GitHub release.
# Install for GitHub API
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/suchlab/anything-cli/HEAD/install/install.sh)"
# Enter: gh-api
# Enter: https://api.github.com
# Set authentication
gh-api self:set-header "Authorization" "token your-github-token"
# Use the API
gh-api user
gh-api repos octocat Hello-World
gh-api search repositories --q "rust cli" --sort stars# Install for Slack API
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/suchlab/anything-cli/HEAD/install/install.sh)" -- --cmd "slack" --base-url "https://slack.com/api"
# Set authentication
slack self:set-header "Authorization" "Bearer xoxb-your-slack-token"
# Use the API
slack auth.test
slack channels.list --types public_channel
slack chat.postMessage --channel "#general" --text "Hello from CLI!"# Install for your API
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/suchlab/anything-cli/HEAD/install/install.sh)" -- --cmd "deploy" --base-url "https://deploy.yourcompany.com"
# Set authentication
deploy self:set-header "X-API-Key" "your-deploy-key"
# Trigger deployment (server returns anything-cli schema with instructions)
deploy environments production deploy --branch main- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
cargo test) - Format code (
cargo fmt) - Run clippy (
cargo clippy) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.