send-sms CLI
Modern command-line interface for sending SMS via FreeMobile API, using the freemobile-api library.
Overview
This crate provides a comprehensive and intuitive CLI tool for SMS sending. It builds upon the freemobile-api crate for all API operations and focuses on command-line user experience.
Features
- Flexible input modes: direct arguments, file, stdin, or interactive
- Automatic stdin detection: recognition of pipes and redirections
- Flexible configuration: environment variables, .env files, or CLI arguments
- Interactive mode: user-friendly interface with informative prompts
- Robust error handling: clear error messages and appropriate exit codes
- Graceful interruption: Ctrl+C support with clean shutdown
- Verbose interface: detailed mode for debugging and monitoring
- Optimized binary: 2.4MB size with maximum performance
Installation
From the parent workspace:
Usage
Basic syntax
)
Usage examples
# Direct message
# From a file
# From stdin (automatic detection)
|
# Interactive mode (default)
# Verbose mode for debugging
Configuration
The CLI supports multiple configuration methods (in order of priority):
- CLI Arguments:
-uand-p - Environment Variables:
FREEMOBILE_USERandFREEMOBILE_PASS - .env File: in the working directory
- Interactive Prompts: Asked automatically when credentials are missing
Environment Variables
.env File
FREEMOBILE_USER=12345678
FREEMOBILE_PASS=your-api-key
Interactive Mode
When credentials are not provided via CLI arguments or environment variables, the CLI will prompt you interactively:
# FreeMobile User ID: [you type your 8-digit user ID]
# FreeMobile API Key: [you type your API key, hidden, no confirmation needed]
This makes the CLI user-friendly for first-time users or when testing.
Architecture
Modules
config: CLI configuration management with validationinput: Management of different input sources (file, stdin, interactive)main: Main entry point with operation orchestration
Dependencies
freemobile-api: API library (local crate)clap: CLI argument parsing with validationinquire: Interactive user interfacetokio: Async runtime for performancedotenv: .env file support
Error Handling
The CLI provides clear error messages for all use cases:
- Missing credentials: Instructions to configure
FREEMOBILE_USERandFREEMOBILE_PASS - Invalid user ID: Must be exactly 8 digits
- Empty message: Cannot be empty or contain only spaces
- File not found: Invalid file path
- API errors: Clear error messages from the
freemobile-apilibrary
All error messages include action suggestions to resolve the problem.
Integration
Scripts and automation
#!/bin/bash
# Deployment notification script
if ; then
else
fi
System monitoring
# High CPU alert
cpu_usage=
if ; then
fi
CI/CD Pipeline
# Build notification
&& \
|| \
Development
Tests
# Unit tests
# Tests with detailed output
# Test specific module
Debugging
Use verbose mode (-v) to see execution details:
# Shows:
# 🚀 Starting send-sms v0.1.0
# 📱 User ID: 1234****
# 📄 Message preview: ...
# 📤 Sending SMS...
# ✅ SMS sent successfully!
For advanced debugging (shows original message when emoji sanitization occurs):
DEBUG=1
# Shows:
# 🐛 DEBUG - Original message: Hello 😀 world!
# 🐛 DEBUG - Sanitized message (what will be sent):
# 📄 Message preview: Hello [] world!