Sha256: 91f8b4e69d3283264548af753f882c45ac4835d6b1a21657d4ca0d3e7da00e63
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
module Upstart::Exporter::Options class CommandLine < Hash include Upstart::Exporter::Errors def initialize(command_line_args) super self[:procfile_commands] = if command_line_args[:clear] {} else process_procfile(command_line_args[:procfile]) end self[:app_name] = process_appname(command_line_args[:app_name]) end def process_procfile(name) error "#{name} is not a readable file" unless FileTest.file?(name) commands = {} content = File.read(name) content.lines.each do |line| line.chomp! if line =~ /^(\w+?):(.*)$/ label = $1 command = $2 commands[label] = command elsif line =~ /^\s*#/ # do nothing, comment elsif line =~ /^\s*$/ # do nothing, empty else break if commands['version'] && commands['version'].strip == '2' error "procfile version 1 lines should have the following format: 'some_label: command'" end end if commands['version'] && commands['version'].strip == '2' commands = Upstart::Exporter::HashUtils::symbolize_keys(YAML.load(content)) error('procfile should include "commands" key') unless commands[:commands] if invalid_name = commands[:commands].keys.find {|k| k.to_s !~ /\A[A-z\d_]*?\z/} error("command name #{invalid_name} should include only letters and/or underscores") end end commands end def process_appname(app_name) error "Application name should contain only letters (and underscore) and be nonempty, so #{app_name.inspect} is not suitable" unless app_name =~ /^\w+$/ app_name end end end
Version data entries
3 entries across 3 versions & 1 rubygems