In this talk, I will introduce Comonicon. Comonicon is a CLI generator designed for Julia, unlike other CLI generators such as Fire, ArgParse, and so on, Comonicon does not only parse command-line arguments but also provide a full solution for building CLI application (via PackageCompiler), packing tarballs, generating shell auto-completion, CLI application installation, mitigating CLI latencies. I'll also talk about ideas arise from development about the future official Julia application.
Comonicon is a CLI generator that aims to provide a full solution for CLI applications, this includes
the interface only has
@cast that will collect all the information from docstring to function signature to create the CLI. The usage is extremely simple, just put
@cast in front of the functions or modules you would like to convert to a CLI node. It has proven to have a very intuitive and user-friendly experience in the past 2 years.
Comonicon is built around an intermediate representation for CLIs. This means the Comonicon frontend is decoupled with its backend, one can also directly construct the IR to generate their CLI as a more advanced feature. Then different backends will generate corresponding backend code like a standard compiler codegen. This currently includes:
and this can be easily extended to generate code for other interfaces, one very experimental work is generating GUI directly from the Comonicon IR.
Most Julia CLI generators suffer from startup latencies in Julia because of the JIT compilation, we have put a relatively large effort into mitigating this latency caused by the CLI generators. And because Comonicon is able to generate a zero-dependency function
command_main that parses the CLI arguments, in extreme cases, one can completely get rid of
Comonicon and use the generated code directly to reach the most ideal latency achievable in current Julia.
Comonicon provides a full build system for shipping your CLIs to other people. This means Comonicon can handle the installation of a Julia CLI application that guarantees its reproducibility by handling the corresponding project environment correctly. Or build the CLI application into binaries via PackageCompiler then package the application as tarball. A glance at its build CLI
Comonicon - Builder CLI. Builder CLI for Comonicon Applications. If not sepcified, run the command install by default. USAGE julia --project deps/build.jl [command] COMMAND install install the CLI locally. app [tarball] build the application, optionally make a tarball. sysimg [tarball] build the system image, optionally make a tarball. tarball build application and system image then make tarballs for them. EXAMPLE julia --project deps/build.jl install install the CLI to ~/.julia/bin. julia --project deps/build.jl sysimg build the system image in the path defined by Comonicon.toml or in deps by default. julia --project deps/build.jl sysimg tarball build the system image then make a tarball on this system image. julia --project deps/build.jl app tarball build the application based on Comonicon.toml and make a tarball from it.
The generated CLI application, the build options are all configurable via a
Comonicon.toml file, one can easily change various default options directly from the configuration file to create your favorite CLI:
Comonicon is currently the only CLI generator designed for Julia and handles the entire workflow of creating a serious CLI application and shipping it to users. It still has a few directions to improve and in the future Julia versions, we hope with the progress of static compilation we will eventually be able to build small binaries and ship them to all platforms in a simple workflow via Comonicon so that one day Julia can also do what go/rust/cpp/... can do in CLI application development.