lib/vagabond/commands.rb in vagabond-0.1.0 vs lib/vagabond/commands.rb in vagabond-0.1.2
- old
+ new
@@ -1,27 +1,41 @@
require 'mixlib/cli'
+require 'chef/log'
require 'vagabond/config'
require 'vagabond/vagabond'
require 'vagabond/server'
+require 'vagabond/knife'
module Vagabond
class Commands
include Mixlib::CLI
+
+ DEFAULT_ACTIONS = Actions.constants.map do |konst|
+ const = Actions.const_get(konst)
+ const.public_instance_methods(false) if const.is_a?(Module)
+ end.flatten.sort
- VALID_COMMANDS = %w(
- up destroy provision status freeze thaw ssh server
+ banner(
+ (
+ %w(Nodes:) + DEFAULT_ACTIONS.map{ |cmd|
+ "\tvagabond #{cmd} NODE [options]"
+ }.compact + %w(Server:) + (DEFAULT_ACTIONS + Server.public_instance_methods(false)).sort.map{ |cmd|
+ next if cmd == 'server'
+ "\tvagabond server #{cmd} [options]"
+ }.compact + ['Knife:', "\tvagabond knife COMMAND [knife_options]"] + %w(Options:)
+ ).join("\n")
)
-
+
option(:force_solo,
- :long => '--force-solo',
+ :long => '--force-configure',
:boolean => true,
:default => false
)
option(:disable_solo,
- :long => '--disable-solo',
+ :long => '--disable-configure',
:boolean => true,
:default => false
)
option(:disable_auto_provision,
@@ -38,21 +52,36 @@
option(:disable_local_server,
:long => '--disable-local-server',
:boolean => true,
:default => false
)
+
+ option(:debug,
+ :long => '--debug',
+ :boolean => true,
+ :default => false
+ )
+
+ option(:color,
+ :long => '--color',
+ :boolean => true
+ )
def run!(argv)
+ # Turn off Chef logging since we will deal with
+ # our own output
+ Chef::Log.init('/dev/null')
parse_options
name_args = parse_options(argv)
- unless(VALID_COMMANDS.include?(name_args.first))
- raise ArgumentError.new('Invalid command provided!')
- end
Config.merge!(config)
- if(name_args.first.to_s == 'server')
- Server.new(name_args.shift, name_args).execute
+ Config[:debug] = STDOUT if Config[:debug]
+ case name_args.first.to_s
+ when 'server'
+ Server.new(name_args.shift, name_args).send(:execute)
+ when 'knife'
+ Knife.new(name_args.shift, name_args).send(:execute)
else
- Vagabond.new(name_args.shift, name_args).execute
+ Vagabond.new(name_args.shift, name_args).send(:execute)
end
end
end
end