Project

cli_tool

0.0
No commit activity in last 3 years
No release in over 3 years
Have trouble with advanced command line options, software dependency presence validation, handling inputs, confirmations and colorizing? Then this gem is for you. It provides you with some modules you can include to add those specific features.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

CliTool

Have trouble with advanced command line options, software dependency presence validation, handling inputs, confirmations and colorizing? Then this gem is for you. It provides you with some modules you can include to add those specific features.

Installation

Add this line to your application's Gemfile:

gem 'cli_tool'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cli_tool

Usage

To include the GetoptLong option parser:

include CliTool::OptionParser

You can then define command line arguments using the following class method.

class New
  include CliTool::OptionParser

  options {
    :log => :required,
    [:other, :alias] => {
      :dependency => :optional, # Valid values are :none, :optional and :required.
      :short      => :o,        # The short arg this would be '-o'
      :default    => 'default value'
    }
  }

These are then returned as GetoptLong array syntax. So to use in GetoptLong:

GetoptLong(*New.options).each |option, value|
  puts option
  # => :other
  puts value
  # => 'default value'
end

To include the software dependency module

include CliTool::SoftwareDependencies

You can then have you application check that dependencies are accessible in your $PATH on startup by using the following class method.

class New
  include CliTool::SoftwareDependencies

  software(:git, :ls, :cp, :mysqld, ...)
end

If the executable cannot be found in the $PATH then it will throw CliTool::MissingDependencies.

To include the input, confirm and colorized_puts tool

include CliTool::StdinOut

You can then make use of the methods as follows.

include CliTool::StdinOut

puts("My normal message", :red)
puts("My normal message", [:red, :purple_bg, :bold])

input("What is your name?", :red)
input("What is your name?", [:red, :purple_bg, :bold])

confirm("Do you really want to do that?", :red)
confirm("Do you really want to do that?", [:red, :purple_bg, :bold])

The available options for the methods are.

puts(message, color = :reset, sleep_in_seconds = nil) input(message, color = :reset, timeout_in_seconds = nil, default_value_for_timeout = nil) confirm(message, color = :reset, default_value = :n, timeout_in_seconds = nil)

The only required values are message.

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 new Pull Request