Cliq Build GitHub GitHub release

The quick way to create a user-friendly Command Line Interface in Crystal. ⚡powered by Toːka

Features

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      cliq:
        github: busyloop/cliq
  2. Run shards install

Basic Usage

require "cliq"

class GreetPerson < Cliq::Command
  command "greet person"
  summary "Greet someone"
  description "I greet, therefore I am"
  args ["<name> Name to greet"]

  flags({
    yell: Bool?,
    count: {
      type: Int32,
      default: 1,
      value_name: "TIMES",
      description: "Print the greeting this many times"
    }
  })

  def call(args)
    raise Cliq::Error.new("Must provide a <name>") if args.size < 1
    greeting = "Hello #{args[0]}!"
    greeting = greeting.upcase if @yell
    @count.times { puts greeting }
  end
end

# Let's go!
Cliq.invoke(ARGV)

How it works

The flags-macro

Short-hand syntax

flags({
  verbose: Bool?,
  count: Int32
})

This allows --verbose or -v
and requires --count N or -c N (where N must be an integer).

Long-hand syntax

flags({
  verbose: {
    type: Bool,
    nilable: true,
    description: "Enable verbosity"
  }
  count: {
    type: Int32,
    description: "Print the greeting this many times",
    verifier: ->(n : Int32){ n >= 0 || "Must be greater than zero" }
  }
})

Reference

Credits

Cliq is a thin wrapper around Toːka. Please refer to the Toːka documentation for advanced usage.

If you do not need sub-commands in your program then you should consider using Toːka directly.

Contributing

  1. Fork it (https://github.com/busyloop/cliq/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