class Rulebow::CLI
Rulebow’s command line interface.
Public Class Methods
Fire her up!
# File lib/rulebow/cli.rb, line 9 def self.fire!(argv=ARGV) new(argv).fire! end
Initialize new instance of Rulebow::CLI
. If ‘argv` is not provided than ARGV is used.
argv - Command line argument. [Array<String>]
Returns nothing.
# File lib/rulebow/cli.rb, line 19 def initialize(argv=ARGV) #begin # require 'dotopts' #rescue LoadError #end @argv = Array(argv || ARGV) @script = nil @watch = nil @fresh = false end
Public Instance Methods
Parse command line arguments with just the prettiest little CLI
parser there ever was.
# File lib/rulebow/cli.rb, line 80 def cli_parse @command = nil cli @argv, "-R --rules" => lambda{ @command = :list }, "-H --help" => lambda{ @command = :help }, "-a --auto" => method(:watch=), "-f --fresh" => method(:fresh!), "-s --script" => method(:script=), "-D --debug" => method(:debug!) end
Set debug flag to true.
Returns [Boolean]
# File lib/rulebow/cli.rb, line 134 def debug! $DEBUG = true end
Is debug mode on?
Returns [Boolean]
# File lib/rulebow/cli.rb, line 127 def debug? $DEBUG end
# File lib/rulebow/cli.rb, line 103 def ensure_options(args) erropts = args.select{ |a| a.start_with?('-') } unless erropts.empty? raise "unsupported options #{erropts.join(' ')}" end end
Fire her up!
# File lib/rulebow/cli.rb, line 59 def fire args = cli_parse ensure_options(args) #if args.first == 'init' && !runner.root? # init_project(*args) #end case @command when :list print_rules(*args) when :help print_help(*args) else runner.run(args.first) end end
Execute command.
command - Which command to execute.
Returns nothing.
# File lib/rulebow/cli.rb, line 48 def fire!(argv=ARGV) $DEBUG = argv.include?('--debug') || $DEBUG return fire if $DEBUG begin fire rescue => err puts "#{$0}: error #{err}" end end
Set fresh flag to true.
Returns [Boolean]
# File lib/rulebow/cli.rb, line 120 def fresh! @fresh = true end
Shall we make a fresh start of it, and remove all digests?
Returns [Boolean]
# File lib/rulebow/cli.rb, line 113 def fresh? @fresh end
Initialize project for rulebow.
Returns nothing.
# File lib/rulebow/cli.rb, line 156 def init_project(*args) # anything to do? end
# File lib/rulebow/cli.rb, line 93 def print_help(*names) puts "-R --rules list ruleset descriptions" puts "-H --help list these help options" puts "-a --auto [TIME] autorun every so many seconds" puts "-f --fresh clear digest for fresh run" puts "-s --script [SCRIPT] use alternate script" puts "-D --debug extra error information" end
Print out a list of availabe manual triggers.
Returns nothing.
# File lib/rulebow/cli.rb, line 163 def print_rules(*names) names = nil if names.empty? puts "(#{runner.root})" runner.rulesets.each do |name, set| next unless names.member?(name.to_s) if names print "#{name}" print " (#{set.chain.join(' ')})" unless set.chain.empty? puts set.docs.each_with_index do |d, i| puts " * #{d}" end end #exit end
Returns runner instance. [Runner]
# File lib/rulebow/cli.rb, line 33 def runner @runner ||= ( Runner.new( :script => @script, :fresh => @fresh, :watch => @watch ) ) end
Use alternate rulebow script.
Returns [Array]
# File lib/rulebow/cli.rb, line 149 def script=(script) @script = script.to_s end
Set the “watch” period –the rate at which autofiring of occurs.
Returns [Fixnum[
# File lib/rulebow/cli.rb, line 142 def watch=(seconds) @watch = seconds.to_i end