How aditya005/tokenizer-cli works
tokcount is a Rust command-line token counter. Users select or import a tokenizer, then provide text as an argument, option, file, or stdin; the program resolves a temporary or default tokenizer, tokenizes the text, and prints a count or token details. Its other commands manage cached tokenizers and configuration. The excerpts show command orchestration and Hub downloads; some config persistence and cache behavior is documented in the README but its implementation is only partially excerpted.
Main entry points: main.rs Command handling · hub.rs Hub download · config.rs Tokenizer cache · cli.rs CLI arguments
Components 13
CLI and orchestration
- CLI arguments
src/cli.rs - Command handling
src/main.rs
Tokenizer selection
- Source resolution
src/config.rs - Hub download
src/hub.rs - Tokenizer sources
src/config.rs
Local state
- Tokenizer cache
src/config.rs - Config management
src/config.rs - Config file
src/config.rs
Token counting
- Text input
src/main.rs - Tokenizer engine
src/main.rs - Count and details
src/main.rs
Other components
- User
- Hugging Face Hub
Connections 14
- User → CLI arguments: provides commands
src/cli.rs - Command handling → CLI arguments: parses arguments
src/main.rs - Command handling → Config management: loads and updates
src/main.rs - Command handling → Source resolution: classifies and resolves
src/main.rs - Command handling → Hub download: requests download
src/main.rs - Hub download → Hugging Face Hub: downloads tokenizer
src/hub.rs - Hub download → Tokenizer cache: writes tokenizer
src/hub.rs - Tokenizer sources → Tokenizer cache: imports and lists
src/config.rs - Config management → Config file: persists settings
README.md - Command handling → Text input: resolves text
src/main.rs - Command handling → Tokenizer engine: loads and encodes
src/main.rs - Source resolution → Tokenizer cache: resolves cached paths
src/main.rs - Tokenizer engine → Count and details: produces token IDs
src/main.rs - Command handling → Count and details: prints count or JSON
src/main.rs