bin/tl in testlab-0.2.1 vs bin/tl in testlab-0.3.0
- old
+ new
@@ -1,44 +1,20 @@
#!/usr/bin/env ruby
require 'gli'
require 'testlab'
include GLI::App
+include TestLab::Utility::Misc
-program_desc %(TestLab #{TestLab::VERSION} - A framework for building lightweight virtual infrastructure using LXC)
+version TestLab::VERSION
-version Testlab::VERSION
+program_desc %(A framework for building lightweight virtual infrastructure using LXC)
+program_long_desc %(Program Long Description)
-# desc 'Describe some switch here'
-# switch [:s,:switch]
+sort_help :manually
+default_command :help
-# desc 'Describe some flag here'
-# default_value 'the default'
-# arg_name 'The name of the argument'
-# flag [:f,:flagname]
-
-# desc 'Manage the test lab'
-# arg_name 'Describe arguments to lab here'
-# command :lab do |c|
-
-# # c.desc 'Describe a switch to lab'
-# # c.switch :s
-
-# # c.desc 'Describe a flag to lab'
-# # c.default_value 'default'
-# # c.flag :f
-# # c.action do |global_options,options,args|
-
-# # # Your command logic here
-
-# # # If you have any errors, just raise them
-# # # raise "that command made no sense"
-
-# # puts "lab command ran"
-# # end
-# end
-
desc 'Create the test lab'
command :create do |create|
create.action do |global_options,options,args|
@testlab.create
end
@@ -88,11 +64,12 @@
desc 'Manage nodes'
arg_name 'Describe arguments to node here'
command :node do |c|
- c.desc 'Node ID'
+ c.desc 'Node ID or Name'
+ c.arg_name 'node'
c.flag [:i, :id]
c.desc 'Open an SSH console to a node'
c.command :ssh do |ssh|
ssh.action do |global_options,options,args|
@@ -115,11 +92,12 @@
desc 'Manage containers'
arg_name 'Describe arguments to container here'
command :container do |c|
- c.desc 'Container ID'
+ c.desc 'Container ID or Name'
+ c.arg_name 'container'
c.flag [:i, :id]
c.desc 'Open an SSH console to a container'
c.command :ssh do |ssh|
ssh.action do |global_options,options,args|
@@ -168,11 +146,11 @@
log_file = File.join(Dir.pwd, "testlab.log")
@logger = ZTK::Logger.new(log_file)
@ui = ZTK::UI.new(:logger => @logger)
@testlab = TestLab.new(:ui => @ui)
- message = TestLab::Utility.format_message("TestLab v#{TestLab::VERSION} Loaded".black.bold)
+ message = format_message("TestLab v#{TestLab::VERSION} Loaded".black.bold)
@testlab.ui.stdout.puts(message)
true
end
@@ -181,18 +159,27 @@
# Use skips_post before a command to skip this
# block on that command only
end
on_error do |exception|
- # Error logic here
- # return false to skip default error handling
- @ui.stderr.puts(["EXCEPTION:".red.bold, exception.inspect.red].join(' '))
+ @ui.stderr.puts
+ @ui.stderr.puts(format_message(["ERROR:".red, exception.message.red.bold].join(' ')))
- @logger.fatal { exception.inspect }
- exception.backtrace.each do |line|
- @logger.logdev.write("#{line}\n")
- end
+ case exception
+ when GLI::BadCommandLine, GLI::UnknownCommand, GLI::UnknownCommandArgument, GLI::UnknownGlobalArgument then
+ command_regex = /Command '([\w]+)' /
+ command = exception.message.scan(command_regex).flatten.first
- false
+ commands[:help] and commands[:help].execute({}, {}, (command.nil? ? [] : [command.to_s]))
+
+ false
+ else
+ @logger.fatal { exception.inspect }
+ exception.backtrace.each do |line|
+ @logger.logdev.write("#{line}\n")
+ end
+
+ false
+ end
end
exit run(ARGV)