aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-10-09 00:05:44 -0700
committerelijah <elijah@riseup.net>2012-10-09 00:05:44 -0700
commit73b126976ad7843eb47a84944cf191bf05b14216 (patch)
tree918656f8d7c637e8c7a8f0c010eff55bfd98ae1b /lib/leap_cli/commands
parent578ac2f5dc7432317d7a022bed9d869ab89ee45c (diff)
downloadleap_cli-73b126976ad7843eb47a84944cf191bf05b14216.tar.gz
leap_cli-73b126976ad7843eb47a84944cf191bf05b14216.tar.bz2
fixed paths
Diffstat (limited to 'lib/leap_cli/commands')
-rw-r--r--lib/leap_cli/commands/README101
-rw-r--r--lib/leap_cli/commands/compile.rb15
-rw-r--r--lib/leap_cli/commands/deploy.rb20
-rw-r--r--lib/leap_cli/commands/init.rb24
-rw-r--r--lib/leap_cli/commands/list.rb61
-rw-r--r--lib/leap_cli/commands/pre.rb38
6 files changed, 259 insertions, 0 deletions
diff --git a/lib/leap_cli/commands/README b/lib/leap_cli/commands/README
new file mode 100644
index 0000000..00fcd84
--- /dev/null
+++ b/lib/leap_cli/commands/README
@@ -0,0 +1,101 @@
+This directory contains ruby source files that define the available sub-commands of the `leap` executable.
+
+For example, the command:
+
+ leap init <directory>
+
+Lives in lib/leap_cli/commands/init.rb
+
+These files use a DSL (called GLI) for defining command suites.
+See https://github.com/davetron5000/gli for more information.
+
+
+ c.command
+ c.commands
+ c.default_command
+ c.default_value
+ c.get_default_command
+ c.commands
+ c.commands_declaration_order
+
+ c.flag
+ c.flags
+ c.switch
+ c.switches
+
+ c.long_desc
+
+ c.default_desc
+ c.default_description
+ c.desc
+ c.description
+ c.long_description
+ c.context_description
+ c.usage
+
+ c.arg_name
+ c.arguments_description
+ c.arguments_options
+
+ c.skips_post
+ c.skips_pre
+ c.skips_around
+
+ c.action
+
+ c.copy_options_to_aliases
+ c.nodoc
+ c.aliases
+ c.execute
+ c.names
+
+
+#desc 'Describe some switch here'
+#switch [:s,:switch]
+
+#desc 'Describe some flag here'
+#default_value 'the default'
+#arg_name 'The name of the argument'
+#flag [:f,:flagname]
+
+# desc 'Describe deploy here'
+# arg_name 'Describe arguments to deploy here'
+# command :deploy do |c|
+# c.action do |global_options,options,args|
+# puts "deploy command ran"
+# end
+# end
+
+# desc 'Describe dryrun here'
+# arg_name 'Describe arguments to dryrun here'
+# command :dryrun do |c|
+# c.action do |global_options,options,args|
+# puts "dryrun command ran"
+# end
+# end
+
+# desc 'Describe add-node here'
+# arg_name 'Describe arguments to add-node here'
+# command :"add-node" do |c|
+# c.desc 'Describe a switch to init'
+# c.switch :s
+#
+# c.desc 'Describe a flag to init'
+# c.default_value 'default'
+# c.flag :f
+# c.action do |global_options,options,args|
+# puts "add-node command ran"
+# end
+# end
+
+# post do |global,command,options,args|
+# # Post logic here
+# # Use skips_post before a command to skip this
+# # block on that command only
+# end
+
+# on_error do |exception|
+# # Error logic here
+# # return false to skip default error handling
+# true
+# end
diff --git a/lib/leap_cli/commands/compile.rb b/lib/leap_cli/commands/compile.rb
new file mode 100644
index 0000000..6b38de5
--- /dev/null
+++ b/lib/leap_cli/commands/compile.rb
@@ -0,0 +1,15 @@
+module LeapCli
+ module Commands
+
+ desc 'Compile json files to hiera configs'
+ command :compile do |c|
+ c.action do |global_options,options,args|
+ manager = ConfigManager.new
+ manager.load(Path.provider)
+ Path.ensure_dir(Path.hiera)
+ manager.export(Path.hiera)
+ end
+ end
+
+ end
+end \ No newline at end of file
diff --git a/lib/leap_cli/commands/deploy.rb b/lib/leap_cli/commands/deploy.rb
new file mode 100644
index 0000000..3694a38
--- /dev/null
+++ b/lib/leap_cli/commands/deploy.rb
@@ -0,0 +1,20 @@
+module LeapCli
+ module Commands
+
+ desc 'Apply recipes to a node or set of nodes'
+ long_desc 'The node filter can be the name of a node, service, or tag.'
+ arg_name '<node filter>'
+ command :deploy do |c|
+ c.action do |global_options,options,args|
+ nodes = ConfigManager.filter(args)
+ say "Deploying to these nodes: #{nodes.keys.join(', ')}"
+ if agree "Continue? "
+ say "deploy not yet implemented"
+ else
+ say "OK. Bye."
+ end
+ end
+ end
+
+ end
+end \ No newline at end of file
diff --git a/lib/leap_cli/commands/init.rb b/lib/leap_cli/commands/init.rb
new file mode 100644
index 0000000..75cc876
--- /dev/null
+++ b/lib/leap_cli/commands/init.rb
@@ -0,0 +1,24 @@
+module LeapCli
+ module Commands
+ desc 'Creates a new provider configuration directory.'
+ arg_name '<directory>'
+ skips_pre
+ command :init do |c|
+ c.action do |global_options,options,args|
+ directory = args.first
+ unless directory && directory.any?
+ help_now! "Directory name is required."
+ end
+ directory = File.expand_path(directory)
+ if File.exists?(directory)
+ raise "#{directory} already exists."
+ end
+ if agree("Create directory '#{directory}'? ")
+ LeapCli.init(directory)
+ else
+ puts "OK, bye."
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
new file mode 100644
index 0000000..a186049
--- /dev/null
+++ b/lib/leap_cli/commands/list.rb
@@ -0,0 +1,61 @@
+module LeapCli
+ module Commands
+
+ def self.print_config_table(type, config_list)
+ style = {:border_x => '-', :border_y => ':', :border_i => '-', :width => 60}
+
+ if type == :services
+ t = table do
+ self.style = style
+ self.headings = ['SERVICE', 'NODES']
+ list = config_list.keys.sort
+ list.each do |name|
+ add_row [name, config_list[name].nodes.keys.join(', ')]
+ add_separator unless name == list.last
+ end
+ end
+ puts t
+ puts "\n\n"
+ elsif type == :tags
+ t = table do
+ self.style = style
+ self.headings = ['TAG', 'NODES']
+ list = config_list.keys.sort
+ list.each do |name|
+ add_row [name, config_list[name].nodes.keys.join(', ')]
+ add_separator unless name == list.last
+ end
+ end
+ puts t
+ puts "\n\n"
+ elsif type == :nodes
+ t = table do
+ self.style = style
+ self.headings = ['NODE', 'SERVICES', 'TAGS']
+ list = config_list.keys.sort
+ list.each do |name|
+ add_row [name, config_list[name].services.to_a.join(', '), config_list[name].tags.to_a.join(', ')]
+ add_separator unless name == list.last
+ end
+ end
+ puts t
+ end
+ end
+
+ desc 'List nodes and their classifications'
+ long_desc 'Prints out a listing of nodes, services, or tags.'
+ arg_name 'filter'
+ command :list do |c|
+ c.action do |global_options,options,args|
+ if args.any?
+ print_config_table(:nodes, ConfigManager.filter(args))
+ else
+ print_config_table(:services, ConfigManager.services)
+ print_config_table(:tags, ConfigManager.tags)
+ print_config_table(:nodes, ConfigManager.nodes)
+ end
+ end
+ end
+
+ end
+end
diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb
new file mode 100644
index 0000000..ae58fc8
--- /dev/null
+++ b/lib/leap_cli/commands/pre.rb
@@ -0,0 +1,38 @@
+
+#
+# check to make sure we can find the root directory of the platform
+#
+module LeapCli
+ module Commands
+
+ desc 'Verbosity level 0..2'
+ arg_name 'level'
+ default_value '0'
+ flag [:v, :verbose]
+
+ desc 'Specify the root directory'
+ arg_name 'path'
+ default_value Path.root
+ flag [:root]
+
+ pre do |global,command,options,args|
+ #
+ # set verbosity
+ #
+ LeapCli.log_level = global[:verbose].to_i
+
+ #
+ # require a root directory
+ #
+ if global[:root]
+ Path.set_root(global[:root])
+ end
+ if Path.ok?
+ true
+ else
+ exit_now!("Could not find the root directory. Change current working directory or try --root")
+ end
+ end
+
+ end
+end