Class: Rulebow::CLI
- Inherits:
-
Object
- Object
- Rulebow::CLI
- Defined in:
- lib/rulebow/cli.rb
Overview
Rulebow’s command line interface.
Class Method Summary collapse
-
.fire!(argv = ARGV) ⇒ Object
Fire her up!.
Instance Method Summary collapse
-
#cli_parse ⇒ Object
Parse command line arguments with just the prettiest little CLI parser there ever was.
-
#debug! ⇒ Boolean
Set debug flag to true.
-
#debug? ⇒ Boolean
Is debug mode on?.
- #ensure_options(args) ⇒ Object
-
#fire ⇒ Object
Fire her up!.
-
#fire!(argv = ARGV) ⇒ void
Execute command.
-
#fresh! ⇒ Boolean
Set fresh flag to true.
-
#fresh? ⇒ Boolean
Shall we make a fresh start of it, and remove all digests?.
-
#init_project(*args) ⇒ void
Initialize project for rulebow.
-
#initialize(argv = ARGV) ⇒ void
constructor
Initialize new instance of Rulebow::CLI.
- #print_help(*names) ⇒ Object
-
#print_rules(*names) ⇒ void
Print out a list of availabe manual triggers.
-
#runner ⇒ Runner
Returns runner instance.
-
#script=(script) ⇒ Array
Use alternate rulebow script.
-
#watch=(seconds) ⇒ Fixnum[
Set the “watch” period –the rate at which autofiring of occurs.
Constructor Details
#initialize(argv = ARGV) ⇒ void
Initialize new instance of Rulebow::CLI. If ‘argv` is not provided than ARGV is used.
19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |
Class Method Details
.fire!(argv = ARGV) ⇒ Object
Fire her up!
9 10 11 |
# File 'lib/rulebow/cli.rb', line 9 def self.fire!(argv=ARGV) new(argv).fire! end |
Instance Method Details
#cli_parse ⇒ Object
Parse command line arguments with just the prettiest little CLI parser there ever was.
80 81 82 83 84 85 86 87 88 89 90 |
# 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 |
#debug! ⇒ Boolean
Set debug flag to true.
134 135 136 |
# File 'lib/rulebow/cli.rb', line 134 def debug! $DEBUG = true end |
#debug? ⇒ Boolean
Is debug mode on?
127 128 129 |
# File 'lib/rulebow/cli.rb', line 127 def debug? $DEBUG end |
#ensure_options(args) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/rulebow/cli.rb', line 103 def (args) erropts = args.select{ |a| a.start_with?('-') } unless erropts.empty? raise "unsupported options #{erropts.join(' ')}" end end |
#fire ⇒ Object
Fire her up!
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rulebow/cli.rb', line 59 def fire args = cli_parse (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 |
#fire!(argv = ARGV) ⇒ void
This method returns an undefined value.
Execute command.
48 49 50 51 52 53 54 55 56 |
# 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 |
#fresh! ⇒ Boolean
Set fresh flag to true.
120 121 122 |
# File 'lib/rulebow/cli.rb', line 120 def fresh! @fresh = true end |
#fresh? ⇒ Boolean
Shall we make a fresh start of it, and remove all digests?
113 114 115 |
# File 'lib/rulebow/cli.rb', line 113 def fresh? @fresh end |
#init_project(*args) ⇒ void
This method returns an undefined value.
Initialize project for rulebow.
156 157 158 |
# File 'lib/rulebow/cli.rb', line 156 def init_project(*args) # anything to do? end |
#print_help(*names) ⇒ Object
93 94 95 96 97 98 99 100 |
# 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_rules(*names) ⇒ void
This method returns an undefined value.
Print out a list of availabe manual triggers.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# 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 |
#runner ⇒ Runner
Returns runner instance. [Runner]
33 34 35 36 37 38 39 40 41 |
# File 'lib/rulebow/cli.rb', line 33 def runner @runner ||= ( Runner.new( :script => @script, :fresh => @fresh, :watch => @watch ) ) end |
#script=(script) ⇒ Array
Use alternate rulebow script.
149 150 151 |
# File 'lib/rulebow/cli.rb', line 149 def script=(script) @script = script.to_s end |
#watch=(seconds) ⇒ Fixnum[
Set the “watch” period –the rate at which autofiring of occurs.
142 143 144 |
# File 'lib/rulebow/cli.rb', line 142 def watch=(seconds) @watch = seconds.to_i end |