diff options
author | elijah <elijah@riseup.net> | 2013-06-25 20:46:26 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-06-25 20:46:26 -0700 |
commit | e486a1d185d5cdf58cc095a79c4c813a74f02cf4 (patch) | |
tree | d4743d6cc059cf3801d5eba3ac4835d3e635d18d /lib | |
parent | 663261bb315ee1d1c693398c7f5ef02cefaaffc1 (diff) | |
download | leap_cli-e486a1d185d5cdf58cc095a79c4c813a74f02cf4.tar.gz leap_cli-e486a1d185d5cdf58cc095a79c4c813a74f02cf4.tar.bz2 |
log the version and git info if log level >= 2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/leap_cli/commands/pre.rb | 153 | ||||
-rw-r--r-- | lib/leap_cli/util.rb | 6 |
2 files changed, 93 insertions, 66 deletions
diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb index 291ad2a..cedce7f 100644 --- a/lib/leap_cli/commands/pre.rb +++ b/lib/leap_cli/commands/pre.rb @@ -2,77 +2,98 @@ # # check to make sure we can find the root directory of the platform # -module LeapCli - module Commands - - desc 'Verbosity level 0..5' - arg_name 'LEVEL' - default_value '1' - flag [:v, :verbose] - - desc 'Override default log file' - arg_name 'FILE' - default_value nil - flag :log - - desc 'Display version number and exit' - switch :version, :negatable => false - - desc 'Skip prompts and assume "yes"' - switch :yes, :negatable => false - - pre do |global,command,options,args| - # - # set verbosity - # - LeapCli.log_level = global[:verbose].to_i - if LeapCli.log_level > 1 - ENV['GLI_DEBUG'] = "true" - else - ENV['GLI_DEBUG'] = "false" - end +module LeapCli; module Commands - # - # load Leapfile - # - unless LeapCli.leapfile.load - bail! { log :missing, 'Leapfile in directory tree' } - end - Path.set_platform_path(LeapCli.leapfile.platform_directory_path) - Path.set_provider_path(LeapCli.leapfile.provider_directory_path) - if !Path.provider || !File.directory?(Path.provider) - bail! { log :missing, "provider directory '#{Path.provider}'" } - end - if !Path.platform || !File.directory?(Path.platform) - bail! { log :missing, "platform directory '#{Path.platform}'" } - end + desc 'Verbosity level 0..5' + arg_name 'LEVEL' + default_value '1' + flag [:v, :verbose] - if LeapCli.leapfile.platform_branch && LeapCli::Util.is_git_directory?(Path.platform) - branch = LeapCli::Util.current_git_branch(Path.platform) - if branch != LeapCli.leapfile.platform_branch - bail! "Wrong branch for #{Path.platform}. Was '#{branch}', should be '#{LeapCli.leapfile.platform_branch}'. Edit Leapfile to disable this check." - end - end + desc 'Override default log file' + arg_name 'FILE' + default_value nil + flag :log + + desc 'Display version number and exit' + switch :version, :negatable => false + + desc 'Skip prompts and assume "yes"' + switch :yes, :negatable => false + + pre do |global,command,options,args| + # + # set verbosity + # + LeapCli.log_level = global[:verbose].to_i + if LeapCli.log_level > 1 + ENV['GLI_DEBUG'] = "true" + else + ENV['GLI_DEBUG'] = "false" + end + + # + # load Leapfile + # + unless LeapCli.leapfile.load + bail! { log :missing, 'Leapfile in directory tree' } + end + Path.set_platform_path(LeapCli.leapfile.platform_directory_path) + Path.set_provider_path(LeapCli.leapfile.provider_directory_path) + if !Path.provider || !File.directory?(Path.provider) + bail! { log :missing, "provider directory '#{Path.provider}'" } + end + if !Path.platform || !File.directory?(Path.platform) + bail! { log :missing, "platform directory '#{Path.platform}'" } + end - # - # set log file - # - LeapCli.log_file = global[:log] || LeapCli.leapfile.log - LeapCli::Util.log_raw(:log) { $0 + ' ' + ORIGINAL_ARGV.join(' ')} - - # - # load all the nodes everything - # - manager - - # - # check requirements - # - REQUIREMENTS.each do |key| - assert_config! key + if LeapCli.leapfile.platform_branch && LeapCli::Util.is_git_directory?(Path.platform) + branch = LeapCli::Util.current_git_branch(Path.platform) + if branch != LeapCli.leapfile.platform_branch + bail! "Wrong branch for #{Path.platform}. Was '#{branch}', should be '#{LeapCli.leapfile.platform_branch}'. Edit Leapfile to disable this check." end + end + + # + # set log file + # + LeapCli.log_file = global[:log] || LeapCli.leapfile.log + LeapCli::Util.log_raw(:log) { $0 + ' ' + ORIGINAL_ARGV.join(' ')} + log_version + # + # load all the nodes everything + # + manager + + # + # check requirements + # + REQUIREMENTS.each do |key| + assert_config! key end end -end + + private + + # + # add a log entry for the leap command and leap platform versions + # + def log_version + if LeapCli.log_level >= 2 + str = "leap command v#{LeapCli::VERSION}" + cli_dir = File.dirname(__FILE__) + if Util.is_git_directory?(cli_dir) + str << " (%s %s)" % [Util.current_git_branch(cli_dir), Util.current_git_commit(cli_dir)] + end + log 2, str + str = "leap platform v#{Leap::Platform.version}" + if Util.is_git_directory?(Path.platform) + str << " (%s %s)" % [Util.current_git_branch(Path.platform), Util.current_git_commit(Path.platform)] + end + log 2, str + end + end + + +end; end diff --git a/lib/leap_cli/util.rb b/lib/leap_cli/util.rb index f602d89..e52c8a1 100644 --- a/lib/leap_cli/util.rb +++ b/lib/leap_cli/util.rb @@ -420,6 +420,12 @@ module LeapCli end end + def current_git_commit(dir) + Dir.chdir(dir) do + `git rev-parse HEAD 2>/dev/null`.strip + end + end + end end |