summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-04-27 09:57:35 -0700
committerelijah <elijah@riseup.net>2015-04-27 09:57:35 -0700
commit1c58dd5905bdad68df4f57aa3323d95d8bd2db0a (patch)
treec9e09e6738daf3a59fea23b4c1b99c4ad44a73e8 /lib
parentea5be4ea7b6f0b269ac54655f01c7cd6dc28ece7 (diff)
added --force
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli/commands/deploy.rb65
-rw-r--r--lib/leap_cli/commands/pre.rb14
2 files changed, 55 insertions, 24 deletions
diff --git a/lib/leap_cli/commands/deploy.rb b/lib/leap_cli/commands/deploy.rb
index 394ea61..03240ce 100644
--- a/lib/leap_cli/commands/deploy.rb
+++ b/lib/leap_cli/commands/deploy.rb
@@ -47,7 +47,7 @@ module LeapCli
environments = [nil]
end
environments.each do |env|
- check_platform_pinning(env)
+ check_platform_pinning(env, global)
end
# compile hiera files for all the nodes in every environment that is
# being deployed and only those environments.
@@ -102,6 +102,16 @@ module LeapCli
private
+ def forcible_prompt(forced, msg, prompt)
+ say(msg)
+ if forced
+ log :warning, "continuing anyway because of --force"
+ else
+ say "hint: use --force to skip this prompt."
+ quit!("OK. Bye.") unless agree(prompt)
+ end
+ end
+
#
# The currently activated provider.json could have loaded some pinning
# information for the platform. If this is the case, refuse to deploy
@@ -115,7 +125,7 @@ module LeapCli
# "commit": "e1d6280e0a8c565b7fb1a4ed3969ea6fea31a5e2..HEAD"
# }
#
- def check_platform_pinning(environment)
+ def check_platform_pinning(environment, global_options)
provider = manager.env(environment).provider
return unless provider['platform']
@@ -133,34 +143,46 @@ module LeapCli
# check version
if provider.platform['version']
if !Leap::Platform.version_in_range?(provider.platform.version)
- say("The platform is pinned to a version range of '#{provider.platform.version}' "+
- "by the `platform.version` property in #{provider_json}, but the platform "+
- "(#{Path.platform}) has version #{Leap::Platform.version}.")
- quit!("OK. Bye.") unless agree("Do you really want to deploy from the wrong version? ")
+ forcible_prompt(
+ global_options[:force],
+ "The platform is pinned to a version range of '#{provider.platform.version}' "+
+ "by the `platform.version` property in #{provider_json}, but the platform "+
+ "(#{Path.platform}) has version #{Leap::Platform.version}.",
+ "Do you really want to deploy from the wrong version? "
+ )
end
end
# check branch
if provider.platform['branch']
if !is_git_directory?(Path.platform)
- say("The platform is pinned to a particular branch by the `platform.branch` property "+
- "in #{provider_json}, but the platform directory (#{Path.platform}) is not a git repository.")
- quit!("OK. Bye.") unless agree("Do you really want to deploy anyway? ")
+ forcible_prompt(
+ global_options[:force],
+ "The platform is pinned to a particular branch by the `platform.branch` property "+
+ "in #{provider_json}, but the platform directory (#{Path.platform}) is not a git repository.",
+ "Do you really want to deploy anyway? "
+ )
end
unless provider.platform.branch == current_git_branch(Path.platform)
- say("The platform is pinned to branch '#{provider.platform.branch}' by the `platform.branch` property "+
- "in #{provider_json}, but the current branch is '#{current_git_branch(Path.platform)}' " +
- "(for directory '#{Path.platform}')")
- quit!("OK. Bye.") unless agree("Do you really want to deploy from the wrong branch? ")
+ forcible_prompt(
+ global_options[:force],
+ "The platform is pinned to branch '#{provider.platform.branch}' by the `platform.branch` property "+
+ "in #{provider_json}, but the current branch is '#{current_git_branch(Path.platform)}' " +
+ "(for directory '#{Path.platform}')",
+ "Do you really want to deploy from the wrong branch? "
+ )
end
end
# check commit
if provider.platform['commit']
if !is_git_directory?(Path.platform)
- say("The platform is pinned to a particular commit range by the `platform.commit` property "+
- "in #{provider_json}, but the platform directory (#{Path.platform}) is not a git repository.")
- quit!("OK. Bye.") unless agree("Do you really want to deploy anyway? ")
+ forcible_prompt(
+ global_options[:force],
+ "The platform is pinned to a particular commit range by the `platform.commit` property "+
+ "in #{provider_json}, but the platform directory (#{Path.platform}) is not a git repository.",
+ "Do you really want to deploy anyway? "
+ )
end
current_commit = current_git_commit(Path.platform)
Dir.chdir(Path.platform) do
@@ -171,10 +193,13 @@ module LeapCli
commit_range = commit_range.split("\n")
if !commit_range.include?(current_commit) &&
provider.platform.commit.split('..').first != current_commit
- say("The platform is pinned via the `platform.commit` property in #{provider_json} " +
- "to a commit in the range #{provider.platform.commit}, but the current HEAD " +
- "(#{current_commit}) is not in that range.")
- quit!("OK. Bye.") unless agree("Do you really want to deploy from the wrong commit? ")
+ forcible_prompt(
+ global_options[:force],
+ "The platform is pinned via the `platform.commit` property in #{provider_json} " +
+ "to a commit in the range #{provider.platform.commit}, but the current HEAD " +
+ "(#{current_commit}) is not in that range.",
+ "Do you really want to deploy from the wrong commit? "
+ )
end
end
end
diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb
index 74d7e62..3b316a4 100644
--- a/lib/leap_cli/commands/pre.rb
+++ b/lib/leap_cli/commands/pre.rb
@@ -9,25 +9,31 @@ module LeapCli; module Commands
default_value '1'
flag [:v, :verbose]
- desc 'Override default log file'
+ desc 'Override default log file.'
arg_name 'FILE'
default_value nil
flag :log
- desc 'Display version number and exit'
+ desc 'Display version number and exit.'
switch :version, :negatable => false
- desc 'Skip prompts and assume "yes"'
+ desc 'Skip prompts and assume "yes".'
switch :yes, :negatable => false
+ desc 'Like --yes, but also skip prompts that are potentially dangerous to skip.'
+ switch :force, :negatable => false
+
desc 'Print full stack trace for exceptions and load `debugger` gem if installed.'
switch [:d, :debug], :negatable => false
- desc 'Disable colors in output'
+ desc 'Disable colors in output.'
default_value true
switch 'color', :negatable => true
pre do |global,command,options,args|
+ if global[:force]
+ global[:yes] = true
+ end
initialize_leap_cli(true, global)
true
end