Code Monkey home page Code Monkey logo

comonicon.jl's Introduction

Comonicon

gith averminaluk ayh juldas mausan urdan

Build Status codecov

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 command

For stable release

pkg> add Comonicon

For current master

pkg> add Comonicon#main

Usage

The simplest way to use it is via @main macro, please refer to the demo in Zero Duplication.

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. You can check the example Ion here.

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.

"""
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

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 but with 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

comonicon.jl's People

Contributors

roger-luo avatar github-actions[bot] avatar xukai92 avatar xgdgsc avatar kwatmdphd avatar mehalter avatar johnnychen94 avatar vpetukhov avatar banhbio avatar qiaojunfeng avatar kmsquire avatar samrodkey avatar eggiverse avatar tecosaur avatar sunoru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.