Class: Minitar::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/minitar/cli.rb

Overview

The Minitar command-line application.

Defined Under Namespace

Classes: AbstractCommandError, CommandAlreadyExists, UnknownCommandError

Constant Summary collapse

VERSION =

:nodoc:

'0.6.1'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout, error = $stderr) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#commanderObject (readonly)

Returns the value of attribute commander.



19
20
21
# File 'lib/minitar/cli.rb', line 19

def commander
  @commander
end

#ioeObject (readonly)

Returns the value of attribute ioe.



20
21
22
# File 'lib/minitar/cli.rb', line 20

def ioe
  @ioe
end

Class Method Details

.run(argv, input = $stdin, output = $stdout, error = $stderr) ⇒ Object



15
16
17
# File 'lib/minitar/cli.rb', line 15

def self.run(argv, input = $stdin, output = $stdout, error = $stderr)
  new(input, output, error).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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