From d4ee04322ce642c602269738e45f63b800d78cf7 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 21 Jun 2016 15:59:27 -0700 Subject: fix ruby deprecation warnings --- lib/leap_cli/commands/common.rb | 61 ----------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 lib/leap_cli/commands/common.rb (limited to 'lib/leap_cli/commands/common.rb') diff --git a/lib/leap_cli/commands/common.rb b/lib/leap_cli/commands/common.rb deleted file mode 100644 index 7bf49db..0000000 --- a/lib/leap_cli/commands/common.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# Some common helpers available to all LeapCli::Commands -# -# This also includes utility methods, and makes all instance -# methods available as class methods. -# - -module LeapCli - module Commands - - extend self - extend LeapCli::Log - extend LeapCli::Util - extend LeapCli::Util::RemoteCommand - - protected - - def path(name) - Path.named_path(name) - end - - # - # keeps prompting the user for a numbered choice, until they pick a good one or bail out. - # - # block is yielded and is responsible for rendering the choices. - # - def numbered_choice_menu(msg, items, &block) - while true - say("\n" + msg + ':') - items.each_with_index &block - say("q. quit") - index = ask("number 1-#{items.length}> ") - if index.empty? - next - elsif index =~ /q/ - bail! - else - i = index.to_i - 1 - if i < 0 || i >= items.length - bail! - else - return i - end - end - end - end - - def parse_node_list(nodes) - if nodes.is_a? Config::Object - Config::ObjectList.new(nodes) - elsif nodes.is_a? Config::ObjectList - nodes - elsif nodes.is_a? String - manager.filter!(nodes) - else - bail! "argument error" - end - end - - end -end \ No newline at end of file -- cgit v1.2.3 From c7ebb220bc79d3a84e55745ed18d0d7b5baeacdd Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 21 Jun 2016 17:49:42 -0700 Subject: remove highline gem dependency --- lib/leap_cli/commands/common.rb | 104 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/leap_cli/commands/common.rb (limited to 'lib/leap_cli/commands/common.rb') diff --git a/lib/leap_cli/commands/common.rb b/lib/leap_cli/commands/common.rb new file mode 100644 index 0000000..695a9f6 --- /dev/null +++ b/lib/leap_cli/commands/common.rb @@ -0,0 +1,104 @@ +require 'readline' + +module LeapCli; module Commands + + extend LeapCli::LogCommand + extend LeapCli::Util + extend LeapCli::Util::RemoteCommand + + def path(name) + Path.named_path(name) + end + + # + # keeps prompting the user for a numbered choice, until they pick a good one or bail out. + # + # block is yielded and is responsible for rendering the choices. + # + def numbered_choice_menu(msg, items, &block) + while true + say("\n" + msg + ':') + items.each_with_index(&block) + say("q. quit") + index = ask("number 1-#{items.length}> ") + if index.empty? + next + elsif index =~ /q/ + bail! + else + i = index.to_i - 1 + if i < 0 || i >= items.length + bail! + else + return i + end + end + end + end + + def parse_node_list(nodes) + if nodes.is_a? Config::Object + Config::ObjectList.new(nodes) + elsif nodes.is_a? Config::ObjectList + nodes + elsif nodes.is_a? String + manager.filter!(nodes) + else + bail! "argument error" + end + end + + def say(statement) + if ends_in_whitespace?(statement) + $stdout.print(statement) + $stdout.flush + else + $stdout.puts(statement) + end + end + + def ask(question, options={}) + default = options[:default] + if default + if ends_in_whitespace?(question) + question = question + "|" + default + "| " + else + question = question + "|" + default + "|" + end + end + response = Readline.readline(question, true) # set to false if ever reading passwords. + if response + response = response.strip + if response.empty? + return default + else + return response + end + else + return default + end + end + + def agree(question, options={}) + while true + response = ask(question, options) + if response.nil? + say('Please enter "yes" or "no".') + elsif ["y","yes", "ye"].include?(response.downcase) + return true + elsif ["n", "no"].include?(response.downcase) + return false + else + say('Please enter "yes" or "no".') + end + end + end + + private + + # true if str ends in whitespace before a color escape code. + def ends_in_whitespace?(str) + /[ \t](\e\[\d+(;\d+)*m)?\Z/ =~ str + end + +end; end -- cgit v1.2.3 From 263bb5699350a04484463aabde563679c4fed505 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 28 Jun 2016 14:34:47 -0700 Subject: mv sshkey to platform --- lib/leap_cli/commands/common.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/leap_cli/commands/common.rb') diff --git a/lib/leap_cli/commands/common.rb b/lib/leap_cli/commands/common.rb index 695a9f6..d49490e 100644 --- a/lib/leap_cli/commands/common.rb +++ b/lib/leap_cli/commands/common.rb @@ -4,7 +4,6 @@ module LeapCli; module Commands extend LeapCli::LogCommand extend LeapCli::Util - extend LeapCli::Util::RemoteCommand def path(name) Path.named_path(name) -- cgit v1.2.3 From 47b3bb60a20674d029950ebd39f6aacf67e81866 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 20 Jul 2016 23:46:48 -0700 Subject: include support for AWS via fog --- lib/leap_cli/commands/common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/leap_cli/commands/common.rb') diff --git a/lib/leap_cli/commands/common.rb b/lib/leap_cli/commands/common.rb index d49490e..3dab2a0 100644 --- a/lib/leap_cli/commands/common.rb +++ b/lib/leap_cli/commands/common.rb @@ -20,7 +20,7 @@ module LeapCli; module Commands items.each_with_index(&block) say("q. quit") index = ask("number 1-#{items.length}> ") - if index.empty? + if index.nil? || index.empty? next elsif index =~ /q/ bail! -- cgit v1.2.3