Module: Jaxx::CLI

Defined in:
lib/jaxx/cli.rb

Class Method Summary collapse

Class Method Details

.aboutme_parserObject



39
40
41
42
43
44
45
# File 'lib/jaxx/cli.rb', line 39

def self.aboutme_parser
  OptionParser.new do |o|
    o.banner = "jaxx-aboutme [options]"
    o.on('-d', '--display')     { |d| options['display'] = d }
    o.on('-h', '--help')        { o }
  end
end

.default_parserObject



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

def self.default_parser 
  OptionParser.new do |o|
    o.banner = "jaxx [options]"

    o.on('-b',  '--bucket [BUCKET]')                 { |b| options['bucket'] = b }
    o.on('-k',  '--access-key [ACCESS_KEY]')         { |k| options['access_key'] = k }
    o.on('-s',  '--access-secret [ACCESS_SECRET]')   { |s| options['access_secret'] = s }
    o.on('-f',  '--file [FILE]')                     { |f| options['file'] = f }
    o.on('-n',  '--name [name]')                     { |f| options['filename'] = f }
    o.on('-p',  '--privacy [privacy]')               { |p| options['privacy'] = p }
    o.on('-r',  '--retries [retries]')               { |r| options['retries'] = r }
    o.on('-h',  '--help')                            { o }
  end
end

.execute(meth, args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jaxx/cli.rb', line 7

def self.execute meth, args

  case meth
  when :upload, :download
    default_parser.parse!(args)
    (Jaxx.logger.write(default_parser) and exit) if options.empty?
  when :aboutme
    aboutme_parser.parse!(args)
    (Jaxx.logger.write(aboutme_parser) and exit) unless options['display']
  end

  Jaxx.send(meth, options)
rescue RuntimeError => exc
  Jaxx.logger.write "An error occurred: #{exc.message}\n"
  exit 1
end

.optionsObject



47
48
49
# File 'lib/jaxx/cli.rb', line 47

def self.options
  @options ||= {}
end