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

  1. Command Proliferation: Too many top-level commands (12+ commands)
  2. Discoverability: Hard to find related functionality
  3. Scalability: Adding new features creates more command clutter
  4. 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

  1. Organized: Related commands grouped logically
  2. Scalable: Easy to add new subcommands
  3. Discoverable: Tab completion shows available options
  4. Familiar: Follows CLI conventions users expect
  5. 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

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