module Acter
Constants
- VERSION
Attributes
help_wanted[RW]
help_wanted?[RW]
options_text[RW]
Public Class Methods
handle_invalid_command(exn)
click to toggle source
# File lib/acter.rb, line 27 def handle_invalid_command(exn) puts exn puts help = Help.new(exn.schema) case exn when HelpWanted, MissingParameters puts help.help_for_action(exn.action, exn.subject) when InvalidAction puts help.help_for_subject(exn.subject) else puts help.general_help end end
load_schema_data(path = nil)
click to toggle source
# File lib/acter.rb, line 10 def load_schema_data(path = nil) path ||= Pathname.glob("schema.{json,yml}").first or raise NoSchema if path.is_a?(String) uri = URI(path) source = uri.scheme ? uri : Pathname.new(path) elsif path.respond_to?(:read) && path.respond_to?(:to_s) source = path else raise ArgumentError, "Argument to load_schema must be a String or a Pathname-like object" end if source.to_s =~ /\.ya?ml$/ YAML.load(source.read) else MultiJson.load(source.read) end end
program_name()
click to toggle source
# File lib/acter.rb, line 54 def program_name @program_name ||= File.basename($0, ".rb") end
run(args, schema_path = nil, render_options = nil)
click to toggle source
# File lib/acter.rb, line 41 def run(args, schema_path = nil, render_options = nil) schema_data = load_schema_data(schema_path) action = Action.new(args, schema_data) result = action.send_request puts result.render(render_options) result.success? rescue InvalidCommand => e handle_invalid_command(e) rescue NoSchema raise unless args.empty? || args == %w"help" handle_invalid_command(InvalidCommand.new(nil)) end