Class: Cindy::CLI
- Inherits:
-
Object
- Object
- Cindy::CLI
- Defined in:
- lib/cindy/cli.rb
Defined Under Namespace
Classes: InvalidArgumentError
Constant Summary collapse
- ARGS_ALIASES =
Hash.new do |h,k| k end.merge!({ 'tpl' => 'template', 'var' => 'variable', 'env' => 'environment' })
Instance Method Summary collapse
- #environments ⇒ Object
-
#initialize ⇒ CLI
constructor
class TooManyArgumentError < ::ArgumentError def initialize super “too many arguments” end end.
-
#parse(args) ⇒ Object
def check_args_count(given, expected, method = :“==”) raise (given > expected ? TooManyArgumentError : TooFewArgumentError).new unless given.send(method, expected) end.
- #templates ⇒ Object
Constructor Details
#initialize ⇒ CLI
class TooManyArgumentError < ::ArgumentError
def initialize
super "too many arguments"
end
end
class TooFewArgumentError < ::ArgumentError
def initialize
super "too few arguments"
end
end
30 31 32 |
# File 'lib/cindy/cli.rb', line 30 def initialize @cindy = Cindy.load ENV['CINDY_CONF'] end |
Instance Method Details
#environments ⇒ Object
34 35 36 |
# File 'lib/cindy/cli.rb', line 34 def environments @cindy.environments.map { |v| v.name.to_s } end |
#parse(args) ⇒ Object
def check_args_count(given, expected, method = :“==”)
raise (given > expected ? TooManyArgumentError : TooFewArgumentError).new unless given.send(method, expected)
end
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cindy/cli.rb', line 46 def parse(args) arg = args.shift case ARGS_ALIASES[arg] when 'reload' # assert 0 == args.length @cindy = Cindy.load ENV['CINDY_CONF'] when 'environment' arg = args.shift case arg when 'list' # assert 0 == args.length @cindy.environments.each do |env| puts "- #{env.name}: #{env.uri}" end end when 'template' arg = args.shift case arg when 'list' # assert 0 == args.length @cindy.templates.each do |tpl| puts "> #{tpl.alias}: #{tpl.file}" end else tplname = arg arg = args.shift case ARGS_ALIASES[arg] when 'environment' # assert args.length >= 2 envname = args.shift arg = args.shift case ARGS_ALIASES[arg] when 'details' # assert 0 == args.length @cindy.template_environment_variables(envname, tplname) when 'deploy', 'print' # assert 0 == args.length @cindy.send(:"template_environment_#{arg}", envname, tplname) else raise InvalidArgumentError.new arg, %w(details deploy print) end else raise InvalidArgumentError.new arg, %w(environment) end end else raise InvalidArgumentError.new arg, %w(reload environment template) end end |
#templates ⇒ Object
38 39 40 |
# File 'lib/cindy/cli.rb', line 38 def templates @cindy.templates.map { |v| v.alias.to_s } end |