aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-03-24 08:32:44 -0700
committerelijah <elijah@riseup.net>2014-03-24 08:32:44 -0700
commit347f4d0b301b19a791f463af4b21a66ec8596a4a (patch)
treeb6a4c080110a93160479046112e8befffdd533f2
parent5d326dc9bbf8ecb282e6606f4af1b1929d3c475e (diff)
downloadleap_cli-347f4d0b301b19a791f463af4b21a66ec8596a4a.tar.gz
leap_cli-347f4d0b301b19a791f463af4b21a66ec8596a4a.tar.bz2
improved robustness of `leap new`
-rw-r--r--lib/leap_cli/commands/new.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/leap_cli/commands/new.rb b/lib/leap_cli/commands/new.rb
index 286fde7..038e6e4 100644
--- a/lib/leap_cli/commands/new.rb
+++ b/lib/leap_cli/commands/new.rb
@@ -14,10 +14,11 @@ module LeapCli; module Commands
c.action do |global, options, args|
directory = File.expand_path(args.first)
create_provider_directory(global, directory)
- options[:domain] ||= ask("The primary domain of the provider: ") {|q| q.default = 'example.org'}
- options[:name] ||= ask("The name of the provider: ") {|q| q.default = 'Example'}
- options[:platform] ||= ask("File path of the leap_platform directory: ") {|q| q.default = File.expand_path('../leap_platform', directory)}
- options[:contacts] ||= ask("Default email address contacts: ") {|q| q.default = 'root@' + options[:domain]}
+ options[:domain] ||= ask_string("The primary domain of the provider: ") {|q| q.default = 'example.org'}
+ options[:name] ||= ask_string("The name of the provider: ") {|q| q.default = 'Example'}
+ options[:platform] ||= ask_string("File path of the leap_platform directory: ") {|q| q.default = File.expand_path('../leap_platform', directory)}
+ options[:platform] = "./" + options[:platform] unless options[:platform] =~ /^\//
+ options[:contacts] ||= ask_string("Default email address contacts: ") {|q| q.default = 'root@' + options[:domain]}
options[:platform] = relative_path(options[:platform])
create_initial_provider_files(directory, global, options)
end
@@ -28,6 +29,21 @@ module LeapCli; module Commands
DEFAULT_REPO = 'https://leap.se/git/leap_platform.git'
#
+ # don't let the user specify any of the following: y, yes, n, no
+ # they must actually input a real string
+ #
+ def ask_string(str, &block)
+ while true
+ value = ask(str, &block)
+ if value =~ /^(y|yes|n|no)$/i
+ say "`#{value}` is not a valid value. Try again"
+ else
+ return value
+ end
+ end
+ end
+
+ #
# creates a new provider directory
#
def create_provider_directory(global, directory)
@@ -77,7 +93,7 @@ module LeapCli; module Commands
end
def relative_path(path)
- Pathname.new(path).relative_path_from(Pathname.new(Path.provider)).to_s
+ Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(Path.provider)).to_s
end
def leapfile_content(options)