https://github.com/bbuck/draconic
A small DSL/Framework for building advanced command line applications in Elixir.
https://github.com/bbuck/draconic
Last synced: 4 months ago
JSON representation
A small DSL/Framework for building advanced command line applications in Elixir.
- Host: GitHub
- URL: https://github.com/bbuck/draconic
- Owner: bbuck
- License: mit
- Created: 2018-02-03T20:09:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T03:09:44.000Z (almost 8 years ago)
- Last Synced: 2025-09-16T00:19:55.316Z (5 months ago)
- Language: Elixir
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Draconic
[](https://hexdocs.pm/draconic/api-reference.html) 
Draconic is a DSL for building command line programs. It allows you to define your
CLI via simplistic macro functions that get compiled into simple modules used at
run time to execute the desired command users enter. It's built on top of the
built in `OptionParser` so it's flag definitions are a remnant of those supported
by `OptionParser`. Although the goal was to unify aspects of an option flag as
singular unit.
With Draconic commands are defined as their own modules, and as behaviors you
just implement the run method that will be invoked if the command is given.
Associating these commands to a program is a simple call to a macro passing in the
module defining the command.
Commands in Draconic function like a tree, supporting nested (or "sub") commands
with their own set of flags. Flags are parsed from top to bottom, following the
path of commands, so global flags are parsed, the flags for the first command,
the second and down to the nth. So the lowest command executed (the only one the
`run` method will be called for) has access to all flags defined before it.
#### Examples
Define a program.
```elixir
defmodule CSVParser.CLI do
use Draconic.Program
alias CSVParser.CLI.Commands
name "awesome"
command Commands.Mapper
command Commands.Lister
end
```
Configure your escipt program.
```elixir
defmodule CSVParser.MixProject do
# ...
def escript do
[
main_module: CSVParser.CLI
]
end
# ...
end
```
Then just execute your program!
```bash
csv_parser list --input example.csv
```
## Installation
Draconic can be installed from Hex by adding `draconic` to your list of
dependencies in `mix.exs`:
```elixir
def deps do
[
{:draconic, "~> 0.1.0"}
]
end
```
## Roadmap
- [ ] Options for `command` macro
- [ ] Override command name
- [ ] Override flag defaults