diff options
author | elijah <elijah@riseup.net> | 2014-09-30 13:36:26 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-09-30 13:36:26 -0700 |
commit | a5b77fa30ed5548978c0907b74ba986cdbf6c11a (patch) | |
tree | fad9db58d566fb3cc2b4a605bc941ea580dfb1a9 /lib/leap_cli/commands/env.rb | |
parent | 410b5d793e8b8ee0abd42b581f09d8c7d5721ed3 (diff) |
environment pinning: new commands `leap env`, `leap env pin X` and `leap env unpin`. See `leap help env` for more information.
Diffstat (limited to 'lib/leap_cli/commands/env.rb')
-rw-r--r-- | lib/leap_cli/commands/env.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/leap_cli/commands/env.rb b/lib/leap_cli/commands/env.rb new file mode 100644 index 0000000..d81e82f --- /dev/null +++ b/lib/leap_cli/commands/env.rb @@ -0,0 +1,53 @@ +module LeapCli + module Commands + + desc "Manipulate and query environment information." + long_desc "The 'environment' node property can be used to isolate sets of nodes into entirely separate environments. "+ + "A node in one environment will never interact with a node from another environment. "+ + "Environment pinning works by modifying your ~/.leaprc file and is dependent on the "+ + "absolute file path of your provider directory (pins don't apply if you move the directory)" + command :env do |c| + c.desc "List the available environments. The pinned environment, if any, will be marked with '*'." + c.command :ls do |ls| + ls.action do |global_options, options, args| + envs = ["default"] + manager.environment_names.compact.sort + envs.each do |env| + if env + if LeapCli.leapfile.environment == env + puts "* #{env}" + else + puts " #{env}" + end + end + end + end + end + + c.desc 'Pin the environment to ENVIRONMENT. All subsequent commands will only apply to nodes in this environment.' + c.arg_name 'ENVIRONMENT' + c.command :pin do |pin| + pin.action do |global_options,options,args| + environment = args.first + if environment == 'default' || + (environment && manager.environment_names.include?(environment)) + LeapCli.leapfile.set('environment', environment) + log 0, :saved, "Leapfile with environment set to #{environment}." + end + end + end + + c.desc "Unpin the environment. All subsequent commands will apply to all nodes." + c.command :unpin do |unpin| + unpin.action do |global_options, options, args| + LeapCli.leapfile.unset('environment') + log 0, :saved, "Leapfile, removing environment property." + end + end + + c.default_command :ls + end + + protected + + end +end
\ No newline at end of file |