# Comonicon.jl - Fast, Simple and Light weight CLI generator

**URL:** https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744
**Category:** Package Announcements
**Tags:** package, announcement
**Created:** [July 27, 2020, 7:12am UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744 "2020-07-27T07:12:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [July 27, 2020, 7:12am UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/1 "2020-07-27T07:12:27Z")

</div>

I’m pleased to announce a new package [GitHub - comonicon/Comonicon.jl: Your best CLI generator in JuliaLang](https://github.com/Roger-luo/Comonicon.jl)  
for making CLI (Command Line Interface) in Julia. Comonicon is now on beta, I’ll be happy to see some feedbacks and potential collaborations from the community.

# Comonicon features

## Colorful and Neat Help Info

You can see an example created by Comonicon below at [IonCLI](https://github.com/Roger-luo/IonCLI.jl)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/61336bf6aacaeeb977914c94e1c046939516ed3f.png)

Comonicon will parse your markdown docstring and reformat it as your terminal help message.

## Fast Start-Up

The long start-up time of Julia scripts has always been a painful part in creating CLI. Even creating a simple CLI that parses 2 arguments and 2 options via [ArgParse](https://github.com/carlobaldassi/ArgParse.jl) will take about 4s on the author’s laptop.

But with the improvements from **PackageCompiler** , and recent Julia compiler updates, **this is actually not true**. By making use of these Comonicon provides you a way faster start-up time on creating CLIs with Julia without compromise on simplicity, color and many other features.

```sh
➜ Comonicon git:(master) ✗ hyperfine "julia example/comonicon_zero.jl 2"
Benchmark #1: julia example/comonicon_zero.jl 2
  Time (mean ± σ): 399.5 ms ± 8.5 ms [User: 556.6 ms, System: 121.7 ms]
  Range (min … max): 389.7 ms … 409.0 ms 10 runs

➜ Comonicon git:(master) hyperfine "julia --project example/comonicon.jl 2"
Benchmark #1: julia --project example/comonicon.jl 2
  Time (mean ± σ): 781.2 ms ± 4.3 ms [User: 926.5 ms, System: 132.4 ms]
  Range (min … max): 773.1 ms … 787.5 ms 10 runs

➜ Comonicon git:(master) ✗ hyperfine "julia example/fire.jl 2"
Benchmark #1: julia example/fire.jl 2
  Time (mean ± σ): 722.5 ms ± 4.4 ms [User: 870.3 ms, System: 130.3 ms]
  Range (min … max): 717.9 ms … 729.6 ms 10 runs

➜ Comonicon git:(master) ✗ hyperfine "julia example/argmacros.jl 2"
Benchmark #1: julia example/argmacros.jl 2
  Time (mean ± σ): 668.8 ms ± 2.7 ms [User: 814.7 ms, System: 136.2 ms]
  Range (min … max): 664.4 ms … 674.9 ms 10 runs

➜ Comonicon git:(master) hyperfine "julia --project example/argparse.jl 2"
Benchmark #1: julia --project example/argparse.jl 2
  Time (mean ± σ): 3.885 s ± 0.038 s [User: 3.997 s, System: 0.159 s]
  Range (min … max): 3.839 s … 3.964 s 10 runs

```

Comonicon parses your command line into an internal intermediate representation and then generates a human-readable Julia script that has zero dependencies on Comonicon itself. You can choose to run using the compile cache created by Comonicon (`comonicon.jl`) or you can just get rid of Comonicon entirely (`comonicon_zero.jl`) to achieve the best scripting performance.

Moreover, Comonicon allows you to decrease the start-up time further using `compile=min` or building system image when you build a Comonicon CLI package.

## Simple Interface

In most cases, all you need to know about Comonicon is only two macros `@cast` and `@main`, it uses a [python-fire](https://github.com/google/python-fire) like interface plus a [docopt](http://docopt.org/) flavor annotation to your commands - it will not only parse your expression, but also your markdown doc string.

**a glance of how you use it** (the code in `example/comonicon.jl`)

```julia
using Comonicon

"""
ArgParse example implemented in Comonicon.

# Arguments

- `x`: an argument

# Options

- `--opt1 <arg>`: an option
- `-o, --opt2 <arg>`: another option

# Flags

- `-f, --flag`: a flag
"""
@main function main(x; opt1=1, opt2::Int=2, flag=false)
    println("Parsed args:")
    println("flag=>", flag)
    println("arg=>", x)
    println("opt1=>", opt1)
    println("opt2=>", opt2)
end

```

## Zero Dependency

Comonicon can generate a human readable Julia script that contains one function `command_main` to process your command line interfaces that has zero dependency on Comonicon itself. Thus after you generate the script, you can choose to remove Comonicon itself.

# Planned Features

- shell auto-completion
- distributable system image (so users don’t need to compile it locally but download as an artifact)

Fore more details about this package please refer to the website: [https://rogerluo.me/Comonicon.jl/](https://rogerluo.me/Comonicon.jl/) and the doc: [https://rogerluo.me/Comonicon.jl/dev/](https://rogerluo.me/Comonicon.jl/dev/)

---

<div class="post-metadata">

### Author: ![musm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/musm/32/3675_2.png) [@musm](https://discourse.julialang.org/u/musm)
#### Post date: [July 28, 2020, 7:04pm UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/2 "2020-07-28T19:04:00Z")

</div>

Excellent work. This look quite useful.

---

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [August 3, 2020, 3:13am UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/3 "2020-08-03T03:13:12Z")

</div>

SHELL completion for ZSH is supported in the new v0.5 version, the system image CI is also supported using a new build system. I think all planned features are at least implemented now.

still need BASH support, if someone knows how to write BASH autocompletes. and I’m not sure about how to support command lines for Windows given it’s in powershell.

I also registered the IonCLI, which I will make an announcement about it later, but you can see how the system image works in the CI and get downloaded automatically via this project.

---

<div class="post-metadata">

### Author: ![alexkyllo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexkyllo/32/17969_2.png) [@alexkyllo](https://discourse.julialang.org/u/alexkyllo)
#### Post date: [September 17, 2020, 4:52am UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/4 "2020-09-17T04:52:32Z")

</div>

This is fantastic. To me, scripts are always better as CLIs and the first thing I looked for when starting my latest project was a way to compile and install my package with a CLI entry point. This is exactly what I needed.

Just a few little issues I worked through setting it up:

- The doc page here seems to be 404: [https://rogerluo.me/Comonicon.jl/dev/](https://rogerluo.me/Comonicon.jl/dev/)
- The `Comonicon.install` method doesn’t seem to be documented
- The `Comonicon.install` workflow example on your homepage shows calling it like `Comonicon.install(Dummy, "dummy")` but the actual method wasn’t expecting the second string argument, just `Comonicon.install(Dummy)`.
- Your project website and docs don’t seem to mention the Comonicon.toml file, at least I couldn’t find where that was documented.

Seeing the example of how you use it in your IonCLI project [https://github.com/Roger-luo/IonCLI.jl](https://github.com/Roger-luo/IonCLI.jl) was very helpful, I was able to figure out how to use the package based on that.

---

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [September 17, 2020, 10:38pm UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/5 "2020-09-17T22:38:14Z")

</div>

Thanks! I’ll update the documentation soon. It seems Documenter somehow removes all the old docs but only the latest stable version. I’ll check that first.

The tutorial in this documentation is a bit out of date indeed, since we had quite a few changes since it was written, I’ll update this too. I might take some knowledge for granted, which makes it hard for people to understand what happens and how to use it, so please feel free to correct docs as well!

---

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [September 24, 2020, 12:42am UTC](https://discourse.julialang.org/t/comonicon-jl-fast-simple-and-light-weight-cli-generator/43744/6 "2020-09-24T00:42:48Z")

</div>

Now in Comonicon v0.9, it has a new tutorial [https://rogerluo.me/Comonicon.jl/dev/](https://rogerluo.me/Comonicon.jl/dev/) with a new configuration system: [https://rogerluo.me/Comonicon.jl/dev/configurations/](https://rogerluo.me/Comonicon.jl/dev/configurations/)

and now it supports building standalone CLI app, e.g you can download IonCLI directly without depending on an external julia compiler: [https://github.com/Roger-luo/IonCLI.jl/releases/tag/v0.8.0](https://github.com/Roger-luo/IonCLI.jl/releases/tag/v0.8.0)
