cmds

Yet another CLI Builder library
0.3.2 released
maiha/cmds.cr
2
maiha

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.2
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
cmds:
  github: maiha/cmds.cr
  version: ~> 0.3.2
License MIT
Crystal none

Authors

Dependencies 2

  • pretty >= 0.6.0
    {'github' => 'maiha/pretty.cr', 'version' => '>= 0.6.0'}
  • var >= 1.2.0
    {'github' => 'maiha/var.cr', 'version' => '>= 1.2.0'}

Development Dependencies 1

  • shell >= 0.2.1
    {'github' => 'maiha/shell.cr', 'version' => '>= 0.2.1'}

Dependents 1

Last synced .
search fire star recently