lib/envied/cli.rb in envied-0.7.1 vs lib/envied/cli.rb in envied-0.7.2
- old
+ new
@@ -1,12 +1,34 @@
require 'thor'
+require 'envied/env_var_extractor'
class ENVied
class Cli < Thor
include Thor::Actions
source_root File.expand_path('../templates', __FILE__)
+ desc "--version", "Shows version number"
+ def version
+ puts ENVied::VERSION
+ end
+ map %w(-v --version) => :version
+
+ desc "extract", "Shows candidate variables (i.e. occurences of ENV['X'])"
+ option :globs, type: :array, default: ENVied::EnvVarExtractor.defaults[:globs], banner: "*.* lib/*"
+ def extract
+ var_occurences = ENVied::EnvVarExtractor.new(globs: options[:globs]).extract
+
+ puts "Found %d occurrences of %d variables:" % [var_occurences.values.flatten.size, var_occurences.size]
+ var_occurences.sort.each do |var, occs|
+ puts var
+ occs.sort_by{|i| i[:path].size }.each do |occ|
+ puts "* %s:%s" % occ.values_at(:path, :line)
+ end
+ puts
+ end
+ end
+
desc "init", "Generates a default Envfile in the current working directory"
def init
puts "Writing new Envfile to #{File.expand_path('Envfile')}"
template("Envfile.tt")
end
@@ -15,23 +37,23 @@
define_method "init:rails" do
init
template("rails-initializer.tt", 'config/initializers/envied.rb')
end
- desc "check", "Checks whether you environment contains the defined variables"
+ desc "check", "Checks whether you environment contains required variables"
long_desc <<-LONG
- Checks whether defined variables are present and valid in your shell.
+ Checks whether required variables are present and valid in your shell.
On success the process will exit with status 0.
Else the missing/invalid variables will be shown, and the process will exit with status 1.
LONG
option :groups, type: :array, default: %w(default), banner: 'default production'
def check
ENVied.require(*options[:groups])
puts "All variables for group(s) #{options[:groups]} are present and valid"
end
- desc "check:heroku", "Checks whether a Heroku config contains the defined variables"
+ desc "check:heroku", "Checks whether a Heroku config contains required variables"
long_desc <<-LONG
Checks the config of your Heroku app against the local Envfile.
The Heroku config should be piped to this task: