Class: Firebrew::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/firebrew/command_line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ CommandLine

Returns a new instance of CommandLine.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/firebrew/command_line.rb', line 28

def initialize(args=[])
  opt = OptionParser.new
  opt.version = Firebrew::VERSION
  opt.banner = <<-USAGE.split(/\n/).map{|v| v.gsub(/^(  ){4}/,'')}.join("\n")
    Usage: firebrew [--help] [--version]
           [--base-dir=<path>] [--profile=<name>] [--firefox=<path>]
           <command> [<args>]
    
    commands:
        install:
            firebrew install <extension-name>
        
        uninstall:
            firebrew uninstall <extension-name>
        
        info:
            firebrew info <extension-name>
        
        search:
            firebrew search <term>
        
        list:
            firebrew list
    
    options:
  USAGE
  
  self.arguments = {
    command: nil,
    params: {},
    config: {}
  }
  
  self.register_global_options(opt)
  self.class.opt_operation(opt, :order!, args)
  
  case args.shift
  when 'install' then
    self.class.opt_operation(opt, :permute!, args)
    self.arguments[:command] = :install
    self.arguments[:params][:term] = args[0]
    
  when 'uninstall' then
    self.class.opt_operation(opt, :permute!, args)
    self.arguments[:command] = :uninstall
    self.arguments[:params][:term] = args[0]
    
  when 'info' then
    self.class.opt_operation(opt, :permute!, args)
    self.arguments[:command] = :info
    self.arguments[:params][:term] = args[0]
    
  when 'search' then
    self.class.opt_operation(opt, :permute!, args)
    self.arguments[:command] = :search
    self.arguments[:params][:term] = args[0]
    
  when 'list' then
    self.class.opt_operation(opt, :permute!, args)
    self.arguments[:command] = :list
    
  when nil then
    self.class.opt_operation(opt, :permute, ['--help'])
  
  else
    raise Firebrew::CommandLineError
  end
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



5
6
7
# File 'lib/firebrew/command_line.rb', line 5

def arguments
  @arguments
end

Class Method Details

.executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/firebrew/command_line.rb', line 7

def self.execute
  begin
    if block_given? then
      yield
    else
      self.new(ARGV).execute
    end
  rescue Firebrew::Error => e
    $stderr.puts e.message
    exit e.status
  rescue SystemExit => e
    exit 1
  rescue Exception => e
    $stderr.puts e.inspect
    $stderr.puts e.backtrace
    exit 255
  else
    exit 0
  end
end

Instance Method Details

#executeObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/firebrew/command_line.rb', line 97

def execute
  runner = Runner.new(self.arguments[:config])
  
  case self.arguments[:command]
  when :search, :list then
    results = runner.send(self.arguments[:command], self.arguments[:params])
    results.each do |result|
      puts result.name
    end
    
  when :info then
    result = runner.send(self.arguments[:command], self.arguments[:params])
    puts result.to_xml
    
  else
    runner.send(self.arguments[:command], self.arguments[:params])
  end
end