class Minitar::CLI

The Minitar command-line application.

Attributes

commander[R]
ioe[R]

Public Class Methods

new(input = $stdin, output = $stdout, error = $stderr) click to toggle source
# File lib/minitar/cli.rb, line 22
def initialize(input = $stdin, output = $stdout, error = $stderr)
  @ioe = {
    :input  => input,
    :output => output,
    :error  => error
  }
  @commander = Minitar::CLI::Commander.new(ioe)
  Minitar::CLI::Command.children.each do |command|
    commander.register(command)
  end
  commander.default_command = 'help'
end
run(argv, input = $stdin, output = $stdout, error = $stderr) click to toggle source
# File lib/minitar/cli.rb, line 15
def self.run(argv, input = $stdin, output = $stdout, error = $stderr)
  new(input, output, error).run(argv)
end

Public Instance Methods

run(argv) click to toggle source
# File lib/minitar/cli.rb, line 35
def run(argv)
  opts = {}

  output << "minitar #{VERSION}\n" if argv.include?('--version')

  if argv.include?('--verbose') or argv.include?('-V')
    opts[:verbose] = true
    argv.delete('--verbose')
    argv.delete('-V')
  end

  if argv.include?('--progress') or argv.include?('-P')
    opts[:progress] = true
    opts[:verbose]  = false
    argv.delete('--progress')
    argv.delete('-P')
  end

  command = commander[(argv.shift or '').downcase]
  command ||= commander['help']
  command.call(argv, opts)
end