class Forematter::CommandRunner

Public Instance Methods

call() click to toggle source
# File lib/forematter/command_runner.rb, line 5
def call
  run
  exit 1 if @has_error
rescue UsageException
  $stderr.puts "usage: #{super_usage}#{command.usage}"
  exit 1
end

Protected Instance Methods

field() click to toggle source
# File lib/forematter/command_runner.rb, line 26
def field
  partition
  fail UsageException, 'Missing field name' unless @field
  @field
end
files() click to toggle source
# File lib/forematter/command_runner.rb, line 46
def files
  partition
  fail UsageException, 'No file(s) specified' if @files.empty?
  @files
end
files_with(key) click to toggle source
# File lib/forematter/command_runner.rb, line 52
def files_with(key)
  files.select { |f| f.key?(key) }
end
guess_split(args) click to toggle source
# File lib/forematter/command_runner.rb, line 66
def guess_split(args)
  if (i = args.index('--'))
    [args[0..i], args[i..-1]]
  else
    files = []
    files.unshift(args.pop) while !args.empty? && File.exist?(args.last)
    [args, files]
  end
end
log_skip(file, msg) click to toggle source
# File lib/forematter/command_runner.rb, line 15
def log_skip(file, msg)
  $stderr.puts "#{super_usage}#{command.name}: #{file.filename}: #{msg}"
  @has_error = 1
end
partition() click to toggle source
# File lib/forematter/command_runner.rb, line 56
def partition
  return if @args_partitioned
  args = arguments.dup
  @field = args.shift
  @value = args.shift               if command.value_args == :one
  @values, args = guess_split(args) if command.value_args == :many
  @files = args.map { |f| Forematter::FileWrapper.new(f) }
  @args_partitioned = true
end
super_usage() click to toggle source
# File lib/forematter/command_runner.rb, line 20
def super_usage
  path = [command.supercommand]
  path.unshift(path[0].supercommand) until path[0].nil?
  path[1..-1].map { |c| c.name + ' ' }.join
end
value() click to toggle source
# File lib/forematter/command_runner.rb, line 32
def value
  fail 'ARGS!' unless command.value_args == :one
  partition
  fail UsageException, 'Missing argument' unless @value
  @value
end
values() click to toggle source
# File lib/forematter/command_runner.rb, line 39
def values
  fail 'ARGS!' unless command.value_args == :many
  partition
  fail UsageException, 'Missing argument' if @values.empty?
  @values
end