class Pamyu::CLI
Constants
- COPY
Public Class Methods
new(argv = [])
click to toggle source
# File lib/pamyu/cli.rb, line 6 def initialize(argv = []) @argv = argv.dup end
Public Instance Methods
execute()
click to toggle source
# File lib/pamyu/cli.rb, line 10 def execute command, options = parse_argv out, err = open_files(options) Executor.new(command, out, err).execute end
new_option_parser(options = {})
click to toggle source
# File lib/pamyu/cli.rb, line 26 def new_option_parser(options = {}) OptionParser.new do |op| op.on "-o", "--out FILE" do |file| options[:out] = file end op.on "-e", "--err FILE" do |file| options[:err] = file end end end
open(file)
click to toggle source
# File lib/pamyu/cli.rb, line 63 def open(file) File.open(file, "wb") end
open_files(options)
click to toggle source
# File lib/pamyu/cli.rb, line 39 def open_files(options) op_out = options.delete(:out) op_err = options.delete(:err) if op_out && op_err if op_out == op_err out = err = open(op_out) elsif op_err == COPY out = err = open(op_out) elsif op_out == COPY out = err = open(op_err) else out = open(op_out) err = open(op_err) end elsif op_out out = open(op_out) elsif op_err err = open(op_err) end [out, err] end
parse_argv()
click to toggle source
# File lib/pamyu/cli.rb, line 16 def parse_argv options = {} op = new_option_parser(options) op.permute!(@argv) abort op.help if @argv.empty? [@argv, options] end