Class: VagrantPlugins::OneAndOne::Command::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-oneandone/command/main.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ Main

Returns a new instance of Main.



11
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-oneandone/command/main.rb', line 11

def initialize(argv, env)
  @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)

  @subcommands = Vagrant::Registry.new

  @subcommands.register(:appliances) do
    require File.expand_path('../list_appliances', __FILE__)
    ListAppliances
  end
  @subcommands.register(:datacenters) do
    require File.expand_path('../list_datacenters', __FILE__)
    ListDatacenters
  end
  @subcommands.register(:firewalls) do
    require File.expand_path('../list_firewalls', __FILE__)
    ListFirewalls
  end
  @subcommands.register(:ips) do
    require File.expand_path('../list_ips', __FILE__)
    ListIPs
  end
  @subcommands.register(:loadbalancers) do
    require File.expand_path('../list_load_balancers', __FILE__)
    ListLoadBalancers
  end
  @subcommands.register(:monitors) do
    require File.expand_path('../list_monitor_policies', __FILE__)
    ListMonitorPolicies
  end
  @subcommands.register(:servers) do
    require File.expand_path('../list_servers', __FILE__)
    ListServers
  end
  @subcommands.register(:sizes) do
    require File.expand_path('../list_sizes', __FILE__)
    ListSizes
  end

  super(argv, env)
end

Class Method Details

.synopsisObject



7
8
9
# File 'lib/vagrant-oneandone/command/main.rb', line 7

def self.synopsis
  I18n.t('vagrant_1and1.command.synopsis')
end

Instance Method Details

#executeObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant-oneandone/command/main.rb', line 52

def execute
  if @main_args.include?('-h') || @main_args.include?('--help')
    return help
  end

  command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
  return help if !command_class || !@sub_command

  # Initialize and execute the command class
  command_class.new(@sub_args, @env).execute
end

#helpObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vagrant-oneandone/command/main.rb', line 64

def help
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant oneandone <subcommand> [<api_key>]'
    o.separator ''
    o.separator I18n.t('vagrant_1and1.command.available_subcommands')

    keys = []
    @subcommands.each { |key| keys << key.to_s }

    keys.sort.each { |key| o.separator "     #{key}" }

    o.separator ''
    o.separator I18n.t('vagrant_1and1.command.help_subcommands') +
                ' `vagrant oneandone <subcommand> -h`'
  end

  @env.ui.info(opts.help)
end