Skip to content

Easy to use CLI builder with integrated logging capabilities, infinite levels of subcommands, options and arguments.

License

Notifications You must be signed in to change notification settings

TheMasterCado/easy-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy CLI

Easy CLI is a small shard that provides a structure for your CLI utilities.

Features:

  • Define commands and infinite levels of subcommands.
  • Define options and arguments.
  • Define channels for your output with a verbosity level and if it should write to a file.

This project is under development.

GitHub release Build Status

Contact

For issues/bugs, feature requests or anything else you can:

Documentation

Simple use case

The full documentation isn't available yet.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  easy-cli:
    github: themastercado/easy-cli
  1. Run shards install

Usage

Require the shard

require "easy-cli"

...

Create a CLI

Create a CLI named mycli:

...

class MyCLI < Easy_CLI::CLI
  def initialize
    name "mycli"
  end
end

...

Create a Command

Create a command named com with an argument name and an option night:

...

class Com < Easy_CLI::Command
  def initialize
    name "com"
    desc "My first command with Easy CLI"

    argument "name"
    option "night", :boolean, nil, "--night", "Say good night instead of good morning"
  end

  def call(data)
    if data["night"]
      puts "Good night #{data["name"]}"
    else
      puts "Good morning #{data["name"]}"
    end
  end
end

...

Register a Command

Register an instance of the Com class to an instance of the MyCLI class:

...

cli = MyCLI.new
cli.register Com.new

...

Call a CLI

Call the run method with the passed arguments on the MyCLI instance:

...

cli.run(ARGV)

Examples

$ mycli com bob
Good morning bob
$ mycli com bob --night
Good night bob
$ mycli com
ERROR: Invalid number of arguments for 'mycli com' (given 0, expected 1).
Usage: mycli com NAME [options]

Description:
    My first command with Easy CLI

Options:
    --night                          Say good night instead of good morning
    -h, --help                       Show this help
$ mycli
Usage: mycli COMMAND

Commands:
    com                              My first command with Easy CLI

*If you haven't compiled your program yet, use crystal run <path to your main .cr> -- <arguments>

Contributing

  1. Fork it (https://github.com/TheMasterCado/easy-cli/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

Author

About

Easy to use CLI builder with integrated logging capabilities, infinite levels of subcommands, options and arguments.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published