$ show comonicon/Comonicon.jl
Comonicon is a Julia CLI generator that transforms function definitions and docstrings into full-featured command-line interfaces with zero duplication, zero overhead, and zero dependencies after code generation. The system follows a classic compiler pipeline: Julia source code is parsed by the frontend (@cast/@main macros) into an AST representation, which is then walked by the codegen module to produce executable Julia Expr, and finally processed by the builder module for installation, system image generation, and distribution. Key features include automatic CLI documentation generation from docstrings, shell completion generation (bash/zsh), and flexible build options via PackageCompiler. The architecture shows clear separation of concerns across frontend, AST, codegen, and builder modules, with thoughtful use of Julia's macro system and type features.
The LLM identified 3 files worth highlighting for reuse:
Defines specialized argument types (Path, FileName, DirName, UserName, Prefix, Suffix) with custom Base.tryparse implementations for CLI-specific validation and shell completion hints. Demonstrates non-obvious use of Julia's type system to integrate validation directly into the parsing process. Completely self-contained with no internal dependencies, making it easily reusable in any CLI parsing library.
Provides text processing utilities including splittext (keeps separators with preceding words), splitlines (wraps text to specified width), and content_brief (creates intelligent truncations). These functions handle common terminal text formatting needs with careful attention to edge cases like hyphenated words. Zero internal dependencies, purely functional design, and clear documentation make this highly reusable across any text processing application.
Defines a clean hierarchy of CLI-specific exception types (CommandException, CommandExit, CommandError) with corresponding handler functions (cmd_error, cmd_exit). Establishes a pattern where CLI errors carry exit codes while preserving stack traces in normal Julia execution. No internal dependencies, demonstrating sound API design for CLI applications that need to balance Julia-native error handling with CLI conventions.