easy-cli v0.9.2
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.
Contact
For issues/bugs, feature requests or anything else you can:
Documentation
The full documentation isn't available yet.
Installation
- Add the dependency to your
shard.yml
:
dependencies:
easy-cli:
github: themastercado/easy-cli
- 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
- Fork it (https://github.com/TheMasterCado/easy-cli/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Author
- TheMasterCado - creator and maintainer
Repository
easy-cli
Owner
Statistic
- 1
- 0
- 2
- 2
- 0
- over 4 years ago
- January 16, 2019
License
MIT License
Links
Synced at
Thu, 21 Nov 2024 11:23:12 GMT
Languages