Class: LxcForge::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/lxc_forge/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



7
8
9
10
# File 'lib/lxc_forge/options.rb', line 7

def initialize(argv)
  @argv = argv
  @options = {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/lxc_forge/options.rb', line 5

def options
  @options
end

Instance Method Details

#parseObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lxc_forge/options.rb', line 38

def parse
  parser.parse!(@argv)

  if @argv.length == 0
    puts parser.help
    exit 0
  elsif @argv.length == 1
    options[:command] = @argv.first
  else
    raise ArgumentError.new "Multiple actions not supported"
  end

  options
end

#parserObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lxc_forge/options.rb', line 12

def parser
  OptionParser.new do |opts|
    opts.banner = "Usage: lxc-forge ACTION [options]

Actions:
configure - Configure LXC Forge settings
upload    - Upload an LXC container to S3
download  - Download an LXC container from S3
list      - List available containers on S3

"

    opts.on("-n NAME", "--name NAME", "Set container name") do |v|
      options[:name] = v
    end

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:verbose] = v
    end

    opts.on("-f", "--[no-]force", "Force overwrite") do |v|
      options[:force] = v
    end
  end
end