class Bricolage::CommandLineApplication
Constants
- DataSourceOpt
Attributes
name[R]
options[R]
Public Class Methods
define() { |opts| ... }
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 7 def CommandLineApplication.define Application.install_signal_handlers opts = new yield opts opts.parse! opts end
new()
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 15 def initialize @name = File.basename($0) @home = nil @env = nil @subsys = nil @ds = {} @options = OptionParser.new @options.banner = "Usage: #{@name} [options]" define_default_options end
Public Instance Methods
context()
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 69 def context @context ||= create_context end
create_context()
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 73 def create_context Bricolage::Context.for_application(@home, environment: @env) end
data_source(long_option)
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 56 def data_source(long_option) ent = @ds[long_option] or raise ArgumentError, "no such data source entry: #{long_option}" ent.ds ||= context.get_data_source(ent.kind, ent.name) end
data_source_option(long_option, description, kind:, short: nil, default: nil)
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 49 def data_source_option(long_option, description, kind:, short: nil, default: nil) @ds[long_option] = DataSourceOpt.new(kind, default || kind) @options.on(* [short, long_option + "=NAME", description + " (default: #{default || kind})"].compact) {|ds_name| @ds[long_option] = DataSourceOpt.new(kind, ds_name) } end
define_default_options()
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 29 def define_default_options @options.on_tail('-e', '--environment=ENV', "Bricolage execution environment. (default: #{Context.environment})") {|env| @env = env } default_home = Context.home_path @options.on_tail('-C', '--home=PATH', "Bricolage home directory. (default: #{default_home == Dir.getwd ? '.' : default_home})") {|path| @home = path } @options.on_tail('--help', 'Prints this message and quit.') { puts @options.help exit 0 } end
main() { || ... }
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 77 def main yield rescue => ex $stderr.puts "#{@name}: error: #{ex.message}" exit 1 end
parse!()
click to toggle source
# File lib/bricolage/commandlineapplication.rb, line 61 def parse! return @options.parse! rescue OptionParser::ParseError => err $stderr.puts "#{$0}: error: #{err.message}" $stderr.puts @options.help exit 1 end