class Ergo::CLI
Fire’s command line interface.
Public Class Methods
Fire her up!
# File lib/ergo/cli.rb, line 9 def self.fire!(argv=ARGV) new(argv).fire! end
Initialize new instance of Ergo::CLI
. If ‘argv` is not provided than ARGV is uses.
argv - Command line argument. [Array<String>]
Returns nothing.
# File lib/ergo/cli.rb, line 19 def initialize(argv=nil) 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/ergo/cli.rb, line 78 def cli_parse @command = nil cli @argv, "-R --rules" => lambda{ @command = :list }, "-a --auto" => method(:watch=), "-f --fresh" => method(:fresh!), "-s --script" => method(:script=), " --debug" => method(:debug!) end
Set debug flag to true.
Returns [Boolean]
# File lib/ergo/cli.rb, line 121 def debug! @debug = true end
Shall we make a fresh start of it, and remove all digests?
Returns [Boolean]
# File lib/ergo/cli.rb, line 114 def debug? @debug end
# File lib/ergo/cli.rb, line 90 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/ergo/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) else runner.run(*args) end end
Execute command.
command - Which command to execute.
Returns nothing.
# File lib/ergo/cli.rb, line 48 def fire!(argv=ARGV) $DEBUG = argv.include?('--debug') || $DEBUG return fire if $DEBUG begin fire rescue => err puts "ergo: error #{err}" end end
Set fresh flag to true.
Returns [Boolean]
# File lib/ergo/cli.rb, line 107 def fresh! @fresh = true end
Shall we make a fresh start of it, and remove all digests?
Returns [Boolean]
# File lib/ergo/cli.rb, line 100 def fresh? @fresh end
Returns nothing.
# File lib/ergo/cli.rb, line 143 def init_project(*args) FileUtils.mkdir_p('.ergo') end
Print out a list of availabe manual triggers.
Returns nothing.
# File lib/ergo/cli.rb, line 150 def print_rules(*names) names = nil if names.empty? list = [] runner.rules.each do |rule| if Book === rule rule.rules.each do |r| next unless names.any?{ |n| r.mark?(n) } if names list << r.to_a end else next unless names.any?{ |n| rule.mark?(n) } if names list << rule.to_a end end list.reject!{ |desc, marks, prv| desc.to_s == "" } puts "(#{runner.root})" i = 1 list.each do |desc, marks, prv| if marks.empty? puts "%4d. %s%s" % [i, desc, prv ? '*' : ''] else puts "%4d. %s%s (%s)" % [i, desc, prv ? '*' : '', marks.join(' ')] end i += 1 end exit end
Returns runner instance. [Runner]
# File lib/ergo/cli.rb, line 33 def runner @runner ||= ( Runner.new( :script => @script, :fresh => @fresh, :watch => @watch ) ) end
Use alternate ergo script.
Returns [Array]
# File lib/ergo/cli.rb, line 136 def script=(script) @script = script.to_s end
Set the “watch” period –the rate at which autofiring of occurs.
Returns [Fixnum[
# File lib/ergo/cli.rb, line 129 def watch=(seconds) @watch = seconds.to_i end