class Ubiquity::CLI
Attributes
argument_parser[W]
arguments[W]
arguments_from_command_line[W]
arguments_from_options_file[W]
default_arguments[W]
help_usage[W]
Public Class Methods
argument_parser(options = { })
click to toggle source
# File lib/ubiquity/cli.rb, line 60 def self.argument_parser(options = { }) return @argument_parser if @argument_parser and !options[:force_new] @argument_parser = OptionParser.new arguments and define_parameters if options.fetch(:define_parameters, true) @argument_parser end
arguments()
click to toggle source
# File lib/ubiquity/cli.rb, line 67 def self.arguments @arguments ||= begin default_arguments.dup end end
arguments_from_command_line(array_of_arguments = ARGV)
click to toggle source
# File lib/ubiquity/cli.rb, line 73 def self.arguments_from_command_line(array_of_arguments = ARGV) @arguments_from_command_line ||= parse_arguments_from_command_line(array_of_arguments) end
arguments_from_options_file(options_file_path = arguments[:options_file_path])
click to toggle source
# File lib/ubiquity/cli.rb, line 77 def self.arguments_from_options_file(options_file_path = arguments[:options_file_path]) @arguments_from_options_file ||= parse_arguments_from_options_file(options_file_path) end
clear_cached_arguments()
click to toggle source
# File lib/ubiquity/cli.rb, line 105 def self.clear_cached_arguments @arguments_from_command_line = nil @arguments_from_options_file = nil @arguments = nil @default_arguments = nil argument_parser(:force_new => true) true end
default_arguments()
click to toggle source
# File lib/ubiquity/cli.rb, line 20 def self.default_arguments @default_arguments ||= { :options_file_path => default_options_file_path, } end
default_options_file_path()
click to toggle source
# File lib/ubiquity/cli.rb, line 16 def self.default_options_file_path File.expand_path(File.basename($0, '.*'), '~/.options') end
define_parameters()
click to toggle source
# File lib/ubiquity/cli.rb, line 7 def self.define_parameters # To be implemented by the child class argument_parser.on_tail('-h', '--help', 'Display this message.') { puts help; exit } end
executable_name()
click to toggle source
# File lib/ubiquity/cli.rb, line 114 def self.executable_name @executable_name ||= File.basename($0) end
help()
click to toggle source
# File lib/ubiquity/cli.rb, line 40 def self.help @help_usage ||= help_usage_default argument_parser.banner = <<-BANNER Usage: #{help_usage} Options: BANNER argument_parser end
help_usage()
click to toggle source
# File lib/ubiquity/cli.rb, line 26 def self.help_usage # To be implemented by the child class help_usage_default end
help_usage_append(string = '')
click to toggle source
# File lib/ubiquity/cli.rb, line 31 def self.help_usage_append(string = '') usage_string = "\n #{executable_name} #{string}" @help_usage << usage_string unless (@help_usage ||= help_usage_default).include?(usage_string) end
help_usage_default()
click to toggle source
# File lib/ubiquity/cli.rb, line 36 def self.help_usage_default " #{executable_name} -h | --help" end
new(args = self.class.parse_arguments)
click to toggle source
# File lib/ubiquity/cli.rb, line 12 def initialize(args = self.class.parse_arguments) # To be implemented by the child class end
parse_arguments()
click to toggle source
# File lib/ubiquity/cli.rb, line 100 def self.parse_arguments argument_parser @arguments = default_arguments.merge(arguments_from_options_file).merge(arguments_from_command_line) end
parse_arguments_from_command_line(array_of_arguments = ARGV)
click to toggle source
# File lib/ubiquity/cli.rb, line 81 def self.parse_arguments_from_command_line(array_of_arguments = ARGV) arguments_before = arguments.dup arguments.clear argument_parser.parse!(array_of_arguments.dup) _arguments_from_options_file = arguments.dup @arguments = arguments_before _arguments_from_options_file end
parse_arguments_from_options_file(options_file_path = arguments[:options_file_path])
click to toggle source
# File lib/ubiquity/cli.rb, line 91 def self.parse_arguments_from_options_file(options_file_path = arguments[:options_file_path]) arguments_before = arguments.dup arguments.clear argument_parser.load(options_file_path) _arguments_from_options_file = arguments.dup @arguments = arguments_before _arguments_from_options_file end
run(args = nil, init_options = { }, run_options = { })
click to toggle source
# File lib/ubiquity/cli.rb, line 118 def self.run(args = nil, init_options = { }, run_options = { }) args ||= parse_arguments new(args, init_options).run(args, run_options) end