module Travis::CLI
Public Instance Methods
command(name)
click to toggle source
# File lib/travis/cli.rb, line 67 def command(name) const_name = command_name(name) constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name if command? constant constant else $stderr.puts "unknown command #{name}" exit 1 end end
commands()
click to toggle source
# File lib/travis/cli.rb, line 78 def commands CLI.constants.map { |n| try_const_get(n) }.select { |c| command? c } end
run(*args)
click to toggle source
# File lib/travis/cli.rb, line 59 def run(*args) args, opts = preparse(args) name = args.shift unless args.empty? command = command(name).new(opts) command.parse(args) command.execute end
silent() { || ... }
click to toggle source
# File lib/travis/cli.rb, line 82 def silent stderr, $stderr = $stderr, dummy_io stdout, $stdout = $stdout, dummy_io yield ensure $stderr = stderr if stderr $stdout = stdout if stdout end
Private Instance Methods
command?(constant)
click to toggle source
# File lib/travis/cli.rb, line 103 def command?(constant) constant.is_a? Class and constant < Command and not constant.abstract? end
command_name(name)
click to toggle source
# File lib/travis/cli.rb, line 107 def command_name(name) case name when nil, '-h', '-?' then 'Help' when '-v' then 'Version' when /^--/ then command_name(name[2..-1]) else name.split('-').map(&:capitalize).join end end
dummy_io()
click to toggle source
# File lib/travis/cli.rb, line 98 def dummy_io return StringIO.new unless defined? IO::NULL and IO::NULL File.open(IO::NULL, 'w') end
preparse(unparsed, args = [], opts = {})
click to toggle source
can't use flatten as it will flatten hashes
# File lib/travis/cli.rb, line 117 def preparse(unparsed, args = [], opts = {}) case unparsed when Hash then opts.merge! unparsed when Array then unparsed.each { |e| preparse(e, args, opts) } else args << unparsed.to_s end [args, opts] end
try_const_get(name)
click to toggle source
# File lib/travis/cli.rb, line 93 def try_const_get(name) CLI.const_get(name) rescue Exception end