crap

A Crystal command-line application helper, with completion.

crap 💩

A Crystal library to help write command-line applications with programmable completion, inspired by Rust's clap crate and Go's cobra.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      crap:
        github: bjjb/crap
    
  2. Run shards install

The project is developed on GitLab, but mirrored on GitHub.

Usage

Here's a fairly basic example: a clone of the echo(1) command/builtin.

require "crap"

Crap.parse do
  name "echo"
  summary "Write arguments to the standard output."
  description <<-DESC
    Display the args, separated by a single space character and followed by a
    newline, on the standard output. Returns success unless a write error
    occurs.
  DESC
  option "-n", "don't append a newline"
  action do |args|
    print args.join(" ")
    puts unless option?("n")
  end
end

You can build arbitrarily complex command-line apps by using sub-commands (Crap#crap). See the examples folder for some inspiration.

Development

There are no special dependencies; develop it as you would any Crystal project.

Related projects

  • cobra - a great CLI-helper package in Go
  • clap - a great CLI helper package in Rust
  • crapi - a compatible Crystal shard to build apps from OpenAPI specs

Contributing

  1. Fork it
  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 merge request

Contributors

Repository

crap

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • over 1 year ago
  • February 21, 2022
License

MIT License

Links
Synced at

Fri, 22 Nov 2024 09:31:51 GMT

Languages