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:

"1.0.0"

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.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/minitar/cli.rb', line 24

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.



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

def commander
  @commander
end

#ioeObject (readonly)

Returns the value of attribute ioe.



22
23
24
# File 'lib/minitar/cli.rb', line 22

def ioe
  @ioe
end

Class Method Details

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



17
18
19
# File 'lib/minitar/cli.rb', line 17

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

Instance Method Details

#run(argv) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/minitar/cli.rb', line 37

def run(argv)
  opts = {}

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

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

  if argv.include?("--progress") || 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