CLI-Style Command Structure Design
Overview
This document outlines the design for refactoring typstwriter.nvim commands from individual command names to a CLI-style structure with subcommands, similar to git
, docker
, or kubectl
.
Current Issues
- Command Proliferation: Too many top-level commands (12+ commands)
- Discoverability: Hard to find related functionality
- Scalability: Adding new features creates more command clutter
- Inconsistency: No clear organizational structure
Proposed CLI Structure
Main Command
1
| :TypstWriter <subcommand> [options] [arguments]
|
Document Operations
1
2
3
4
| :TypstWriter new [template_type] [title] # Create new document
:TypstWriter compile # Compile current document
:TypstWriter open # Open PDF
:TypstWriter both # Compile and open
|
Template Management
1
2
3
4
| :TypstWriter templates list # List available templates
:TypstWriter templates update # Update plugin templates
:TypstWriter templates reset <name> # Reset template to default
:TypstWriter templates install # Install templates
|
Package Management
1
2
3
| :TypstWriter package status # Check package installation
:TypstWriter package install # Install package and fonts
:TypstWriter package update # Update package and fonts
|
System Operations
1
2
| :TypstWriter setup # Complete system setup
:TypstWriter status # Overall system status
|
Future PKS Commands
1
2
3
4
5
| :TypstWriter search <query> # Search documents
:TypstWriter link <target> # Create document links
:TypstWriter graph generate # Generate knowledge graph
:TypstWriter ai chat # AI chat interface
:TypstWriter ai enhance # AI content enhancement
|
Benefits
- Organized: Related commands grouped logically
- Scalable: Easy to add new subcommands
- Discoverable: Tab completion shows available options
- Familiar: Follows CLI conventions users expect
- Future-proof: Perfect foundation for PKS features
Implementation Plan
Phase 1: Core CLI Infrastructure ✅ COMPLETED
Phase 2: Command Migration ✅ COMPLETED
Phase 3: Enhanced Features ✅ COMPLETED
Phase 4: Documentation Update ✅ COMPLETED
Technical Implementation
Command Registration
1
2
3
4
5
6
7
| -- Single main command with completion
vim.api.nvim_create_user_command('TypstWriter', function(opts)
require('typstwriter.cli').execute(opts)
end, {
nargs = '*',
complete = require('typstwriter.cli').complete,
})
|
Subcommand Routing
1
2
3
4
5
6
7
8
9
| local commands = {
new = require('typstwriter.commands.document').new,
compile = require('typstwriter.commands.document').compile,
templates = {
list = require('typstwriter.commands.templates').list,
update = require('typstwriter.commands.templates').update,
},
-- ... more commands
}
|
Tab Completion
- First level: Main subcommands (new, templates, package, etc.)
- Second level: Sub-subcommands (templates list, package status, etc.)
- Context-aware completion for arguments
Backward Compatibility
Maintain existing commands as deprecated aliases:
1
2
3
| :TypstWriterNew -> :TypstWriter new
:TypstWriterTemplates -> :TypstWriter templates list
:TypstWriterPackageStatus -> :TypstWriter package status
|
Show deprecation warnings with migration suggestions.
Success Criteria ✅ ALL COMPLETED
Development Log
Implementation Complete ✅
Key Files Created/Modified
- NEW:
lua/typstwriter/cli.lua
- Command routing and completion system
- RENAMED:
compiler.lua
→ document.lua
- Better reflects module purpose
- UPDATED:
init.lua
- Uses new CLI system instead of individual commands
- UPDATED: All test files - Reflect new structure
- CREATED:
docs/commands.md
- Comprehensive command documentation
- UPDATED:
README.md
- New command structure and quick start