Class: TorqueBox::CLI

Inherits:
Object
  • Object
show all
Defined in:
core/lib/torquebox/cli.rb,
core/lib/torquebox/cli/jar.rb,
core/lib/torquebox/cli/war.rb,
core/lib/torquebox/cli/archive.rb

Defined Under Namespace

Classes: Archive, Jar, War

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CLI) initialize(argv)

Returns a new instance of CLI



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'core/lib/torquebox/cli.rb', line 37

def initialize(argv)
  @argv = argv = argv.dup
  require_torquebox_gems
  options = {}
  @extension = TorqueBox::CLI.extensions[argv.first]
  @parser = OptionParser.new
  if @extension
    setup_extension_parser(@extension, argv.shift, @parser, options)
  else
    setup_usage_parser(@parser)
  end

  setup_common_parser(@parser, options)
  @options = options
end

Instance Attribute Details

- (Object) parser (readonly)

Returns the value of attribute parser



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

def parser
  @parser
end

Class Method Details

+ (Object) extension_descriptions



27
28
29
# File 'core/lib/torquebox/cli.rb', line 27

def extension_descriptions
  @extension_descriptions ||= {}
end

+ (Object) extensions



23
24
25
# File 'core/lib/torquebox/cli.rb', line 23

def extensions
  @extensions ||= {}
end

+ (Object) register_extension(command, extension, description)



31
32
33
34
# File 'core/lib/torquebox/cli.rb', line 31

def register_extension(command, extension, description)
  extensions[command] = extension
  extension_descriptions[command] = description
end

Instance Method Details

- (Object) require_torquebox_gems



123
124
125
126
127
128
129
130
131
132
# File 'core/lib/torquebox/cli.rb', line 123

def require_torquebox_gems
  # Ensure all other known TorqueBox gems are loaded so we can see their
  # CLI extensions and jars
  %W(torquebox-web torquebox-messaging torquebox-scheduling torquebox-caching).each do |gem|
    begin
      require gem
    rescue LoadError
    end
  end
end

- (Object) run



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'core/lib/torquebox/cli.rb', line 53

def run
  begin
    @parser.parse!(@argv)
  rescue OptionParser::InvalidOption => e
    puts e.message
    puts
    puts @parser
    exit 1
  end

  if @extension
    log_level = case @options.delete(:verbosity)
                when :quiet then 'ERROR'
                when :verbose then 'DEBUG'
                when :really_verbose then 'TRACE'
                else 'INFO'
                end
    TorqueBox::Logger.log_level = log_level
    @extension.run(@argv, @options)
  else
    puts @parser
    exit 1
  end
end

- (Object) setup_common_parser(parser, options)



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'core/lib/torquebox/cli.rb', line 100

def setup_common_parser(parser, options)
  parser.separator ""
  parser.separator "Common options:"
  parser.on '-q', '--quiet', 'Log only errors' do
    options[:verbosity] = :quiet
  end
  parser.on '-v', '--verbose', 'Log more - use twice for even more' do
    if options[:verbosity] == :verbose
      options[:verbosity] = :really_verbose
    else
      options[:verbosity] = :verbose
    end
  end
  parser.on('-h', '--help', 'Show this message') do
    puts parser
    exit 1
  end
  parser.on('--version', 'Show version') do
    puts "TorqueBox #{TorqueBox::VERSION}"
    exit 1
  end
end

- (Object) setup_extension_parser(extension, command, parser, options)



78
79
80
81
82
83
84
# File 'core/lib/torquebox/cli.rb', line 78

def setup_extension_parser(extension, command, parser, options)
  parser.banner = "Usage: torquebox #{command} #{extension.usage_parameters}"
  parser.separator TorqueBox::CLI.extension_descriptions[command]
  parser.separator ""
  parser.separator "#{command} options:"
  extension.setup_parser(parser, options)
end

- (Object) setup_usage_parser(parser)



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'core/lib/torquebox/cli.rb', line 86

def setup_usage_parser(parser)
  parser.banner = "Usage: torquebox [command] [options]"
  parser.separator ""
  parser.separator "Commands:"
  TorqueBox::CLI.extensions.keys.each do |command|
    description = TorqueBox::CLI.extension_descriptions[command]
    command = "#{command}:".ljust(8)
    parser.separator "    #{command} #{description}"
  end
  parser.separator ""
  parser.separator "Installing additional torquebox gems may provide additional commands."
  parser.separator "'torquebox [command] -h' for additional help on each command"
end