class Rulebow::CLI

Rulebow’s command line interface.

Public Class Methods

fire!(argv=ARGV) click to toggle source

Fire her up!

# File lib/rulebow/cli.rb, line 9
def self.fire!(argv=ARGV)
  new(argv).fire!
end
new(argv=ARGV) click to toggle source

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

cli_parse() click to toggle source

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
debug!() click to toggle source

Set debug flag to true.

Returns [Boolean]

# File lib/rulebow/cli.rb, line 134
def debug! 
  $DEBUG = true
end
debug?() click to toggle source

Is debug mode on?

Returns [Boolean]

# File lib/rulebow/cli.rb, line 127
def debug?
  $DEBUG
end
ensure_options(args) click to toggle source
# 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() click to toggle source

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
fire!(argv=ARGV) click to toggle source

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
fresh!() click to toggle source

Set fresh flag to true.

Returns [Boolean]

# File lib/rulebow/cli.rb, line 120
def fresh! 
  @fresh = true
end
fresh?() click to toggle source

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
init_project(*args) click to toggle source

Initialize project for rulebow.

Returns nothing.

# File lib/rulebow/cli.rb, line 156
def init_project(*args)
  # anything to do?
end
print_help(*names) click to toggle source
print_rules(*names) click to toggle source

Print out a list of availabe manual triggers.

Returns nothing.

runner() click to toggle source

Returns runner instance. [Runner]

# File lib/rulebow/cli.rb, line 33
def runner
  @runner ||= (
    Runner.new(
      :script => @script,
      :fresh  => @fresh,
      :watch  => @watch
    )  
  )
end
script=(script) click to toggle source

Use alternate rulebow script.

Returns [Array]

# File lib/rulebow/cli.rb, line 149
def script=(script)
  @script = script.to_s
end
watch=(seconds) click to toggle source

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