Comonicon, a full stack solution for building CLI applications

07/27/2022, 3:00 PM — 3:10 PM UTC
Purple

Abstract:

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.

Description:

Comonicon is a CLI generator that aims to provide a full solution for CLI applications, this includes

Clean and Julian syntax

the interface only has @main and @cast that will collect all the information from docstring to function signature to create the CLI. The usage is extremely simple, just put @main or @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.

Powerful and extensible code generators

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:

  • a zero dependency command line arguments parsing function in Julia
  • shell autocompletion (only ZSH is supported at the moment)

and this can be easily extended to generate code for other interfaces, one very experimental work is generating GUI directly from the Comonicon IR.

Mitigating startup latencies

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.

Build System

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.

Configurable

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:

  • enable/disable colorful help message
  • set Julia compile options
  • bundle custom assets
  • installation options
  • ...

Summary

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.

Platinum sponsors

Julia ComputingRelational AIJulius Technology

Gold sponsors

IntelAWS

Silver sponsors

Invenia LabsBeacon BiosignalsMetalenzASMLG-ResearchConningPumas AIQuEra Computing Inc.Jeffrey Sarnoff

Media partners

Packt PublicationGather TownVercel

Community partners

Data UmbrellaWiMLDS

Fiscal Sponsor

NumFOCUS