summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/util.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-08-12 14:37:21 -0700
committerelijah <elijah@riseup.net>2015-08-19 12:24:51 -0700
commit64787942086b6fbfdf432cd6250f0937c785de1a (patch)
tree06634196af8066cb782032f731ee7cae939367ce /lib/leap_cli/commands/util.rb
parente6f6324ebea9fc46d5d617a08c2eb239349d9f90 (diff)
mv commands and macros to lib/leap_cli
Diffstat (limited to 'lib/leap_cli/commands/util.rb')
-rw-r--r--lib/leap_cli/commands/util.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/leap_cli/commands/util.rb b/lib/leap_cli/commands/util.rb
new file mode 100644
index 00000000..c1da570e
--- /dev/null
+++ b/lib/leap_cli/commands/util.rb
@@ -0,0 +1,50 @@
+module LeapCli; module Commands
+
+ extend self
+ 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
+
+end; end