Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/comonicon/Comonicon.jl
Your best CLI generator in JuliaLang
https://github.com/comonicon/Comonicon.jl
command-line command-line-interface command-line-parser command-line-tool julia
Last synced: about 1 month ago
JSON representation
Your best CLI generator in JuliaLang
- Host: GitHub
- URL: https://github.com/comonicon/Comonicon.jl
- Owner: comonicon
- License: mit
- Created: 2020-07-19T16:41:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-09T18:00:24.000Z (about 2 months ago)
- Last Synced: 2024-05-09T19:24:58.640Z (about 2 months ago)
- Topics: command-line, command-line-interface, command-line-parser, command-line-tool, julia
- Language: Julia
- Homepage: https://comonicon.org
- Size: 4.53 MB
- Stars: 265
- Watchers: 5
- Forks: 25
- Open Issues: 38
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-cli-frameworks - Comonicon.jl
README
# Comonicon
*gith averminaluk ayh juldas mausan urdan*
[![Build Status](https://github.com/comonicon/Comonicon.jl/workflows/CI/badge.svg)](https://github.com/comonicon/Comonicon.jl/actions)
[![codecov](https://codecov.io/gh/comonicon/Comonicon.jl/branch/master/graph/badge.svg?token=zZjCxCiFTY)](https://codecov.io/gh/comonicon/Comonicon.jl)
[![][docs-stable-img]][docs-stable-url]
[![][docs-dev-img]][docs-dev-url]Roger's magic book for command line interfaces.
## Installation
Comonicon is a
![]()
Julia Language
package. To install Comonicon,
please open
Julia's interactive session (known as REPL) and press ] key in the REPL to use the package mode, then type the following commandFor stable release
```julia
pkg> add Comonicon
```For current main branch
```julia
pkg> add Comonicon#main
```## Usage
The simplest way to use it is via `@main` macro,
```julia
"""
ArgParse example implemented in Comonicon.# Arguments
- `x`: an argument
# Options
- `--opt1 `: an option
- `-o, --opt2 `: 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
```Now if you save this in a `mail.jl` file, you can run the following in your terminal
```sh
julia main.jl 123 --opt1 3 -o 2 -f
```or use
```sh
julia main.jl --help
```to print out a help message.
Although you can use `Comonicon` in your script, but the recommended way to build CLI with Comonicon is to use `@main` in a Julia project module, so the command line interface entry will get compiled by the
Julia compiler.Moreover, if you wish to create multiple commands. You can use `@cast` macro to annotate a function or module
to create more complicated command line interfaces.## Features
### Zero Duplication
The frontend `@main` and `@cast` will try to **parse everything you typed** and turn them into
part of your command line. This includes your function or module docstrings, your argument and keyword
argument names, types and default values.We don't want to compromise on writing DRY code. If you have mentioned it in the documentation or somewhere in your script, you shouldn't write about it again in your code.
This is like Python [docopt](https://github.com/docopt/docopt) but with [Fire](https://github.com/google/python-fire) and in Julia.
### Zero Overhead
The backend code generator will generate Julia ASTs directly to parse your command line inputs all in one
function `main` with one method `main(::Vector{String})`, which can be precompiled easily during module compilation.### Zero Dependency
You can get rid of `Comonicon` entirely after you generate the command line parsing script
via `write_cmd(filename, command_object)`. It means if you copy this file into your script, you
will get a standalone Julia script (unless the script depends on something else). However,
this is usually not necessary since `Comonicon` itself is quite fast to load, the main latency
of a CLI application usually comes from other dependencies or the application itself.## License
MIT License
[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
[docs-dev-url]: https://comonicon.org/dev/
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-stable-url]: https://comonicon.org/stable/