Skip to content
Yet another CLI Builder library for Crystal
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
spec
src
.editorconfig
.gitignore
.travis.yml
LICENSE
Makefile
README.md
shard.yml

README.md

cmds.cr Build Status

Yet another CLI Builder library for Crystal (0.26.1).

features

  • Simple and readable syntax for command and task
  • Automatic generation of command candidates
  • Automatic generation of task candidates
  • Around filter to commands

Usage

hello world

Writing logics into run method provides a command.

Cmds.command "hello" do
  def run
    puts "Hello world!"
  end
end

Cmds.run(ARGV)
$ prog hello
Hello world!

with args

  • args[0] is automatically saved as task_name
  • args[1..-1] can be used as args

with tasks

Writing logics as task provides sub commands.

Cmds.command "json" do
  usage "pretty file.json"

  task "pretty" do
    path = args.shift? || abort "specify file"
    puts Pretty.json(File.read(path))
  end
end

Cmds.run(ARGV)
$ prog
Error: unknown command: ''
Possible commands are: ["json"]

$ prog json
Error: unknown task: ''
Possible tasks are: ["pretty"]
  prog json pretty file.json

$ prog json pretty
specify file

around filter

before and after methods will be automatically fired. See examples/hello.cr.

Installation

Add this to your application's shard.yml:

dependencies:
  cmds:
    github: maiha/cmds.cr
    version: 0.3.3
require "cmds"

Development

make test

Contributing

  1. Fork it (https://github.com/maiha/cmds.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer
You can’t perform that action at this time.