Class: Firebrew::CommandLine
- Inherits:
-
Object
- Object
- Firebrew::CommandLine
- Defined in:
- lib/firebrew/command_line.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args = []) ⇒ CommandLine
constructor
A new instance of CommandLine.
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. = " Usage: firebrew [--help] [--version]\n [--base-dir=<path>] [--profile=<name>] [--firefox=<path>]\n <command> [<args>]\n \n commands:\n install:\n firebrew install <extension-name>\n \n uninstall:\n firebrew uninstall <extension-name>\n \n info:\n firebrew info <extension-name>\n \n search:\n firebrew search <term>\n \n list:\n firebrew list\n \n options:\n USAGE\n \n self.arguments = {\n command: nil,\n params: {},\n config: {}\n }\n \n self.register_global_options(opt)\n self.class.opt_operation(opt, :order!, args)\n \n case args.shift\n when 'install' then\n self.class.opt_operation(opt, :permute!, args)\n self.arguments[:command] = :install\n self.arguments[:params][:term] = args[0]\n \n when 'uninstall' then\n self.class.opt_operation(opt, :permute!, args)\n self.arguments[:command] = :uninstall\n self.arguments[:params][:term] = args[0]\n \n when 'info' then\n self.class.opt_operation(opt, :permute!, args)\n self.arguments[:command] = :info\n self.arguments[:params][:term] = args[0]\n \n when 'search' then\n self.class.opt_operation(opt, :permute!, args)\n self.arguments[:command] = :search\n self.arguments[:params][:term] = args[0]\n \n when 'list' then\n self.class.opt_operation(opt, :permute!, args)\n self.arguments[:command] = :list\n \n when nil then\n self.class.opt_operation(opt, :permute, ['--help'])\n \n else\n raise Firebrew::CommandLineError\n end\nend\n".split(/\n/).map{|v| v.gsub(/^( ){4}/,'')}.join("\n") |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/firebrew/command_line.rb', line 5 def arguments @arguments end |
Class Method Details
.execute ⇒ Object
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. 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
#execute ⇒ Object
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 |