minfra-cli 1.13.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -2
  3. data/.rubocop.yml +31 -0
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +13 -1
  7. data/exe/minfra +1 -3
  8. data/lib/deep_merge.rb +35 -36
  9. data/lib/hash.rb +19 -18
  10. data/lib/minfra/cli/ask.rb +18 -16
  11. data/lib/minfra/cli/cli_starter.rb +173 -0
  12. data/lib/minfra/cli/command.rb +4 -1
  13. data/lib/minfra/cli/commands/dev.rb +26 -15
  14. data/lib/minfra/cli/commands/kube.rb +97 -88
  15. data/lib/minfra/cli/commands/plugin.rb +9 -8
  16. data/lib/minfra/cli/commands/project/branch.rb +7 -5
  17. data/lib/minfra/cli/commands/project/tag.rb +7 -6
  18. data/lib/minfra/cli/commands/project.rb +40 -40
  19. data/lib/minfra/cli/commands/setup.rb +18 -18
  20. data/lib/minfra/cli/commands/stack/app_template.rb +10 -13
  21. data/lib/minfra/cli/commands/stack/client_template.rb +10 -8
  22. data/lib/minfra/cli/commands/stack/kube_stack_template.rb +49 -51
  23. data/lib/minfra/cli/commands/stack.rb +55 -46
  24. data/lib/minfra/cli/commands/tag.rb +9 -8
  25. data/lib/minfra/cli/common.rb +7 -10
  26. data/lib/minfra/cli/config.rb +36 -63
  27. data/lib/minfra/cli/core_ext.rb +7 -0
  28. data/lib/minfra/cli/document.rb +5 -2
  29. data/lib/minfra/cli/env.rb +24 -0
  30. data/lib/minfra/cli/errors.rb +10 -0
  31. data/lib/minfra/cli/helm_runner.rb +3 -1
  32. data/lib/minfra/cli/hiera_looker.rb +54 -0
  33. data/lib/minfra/cli/hook.rb +36 -24
  34. data/lib/minfra/cli/kubectl_runner.rb +3 -1
  35. data/lib/minfra/cli/logging.rb +5 -1
  36. data/lib/minfra/cli/main_command.rb +2 -1
  37. data/lib/minfra/cli/plugin.rb +74 -0
  38. data/lib/minfra/cli/plugins.rb +18 -87
  39. data/lib/minfra/cli/runner.rb +23 -23
  40. data/lib/minfra/cli/templater.rb +17 -17
  41. data/lib/minfra/cli/version.rb +3 -1
  42. data/lib/minfra/cli.rb +20 -114
  43. data/lib/orchparty/ast.rb +13 -14
  44. data/lib/orchparty/cli.rb +35 -33
  45. data/lib/orchparty/context.rb +15 -15
  46. data/lib/orchparty/dsl_parser.rb +7 -11
  47. data/lib/orchparty/dsl_parser_kubernetes.rb +46 -56
  48. data/lib/orchparty/plugin.rb +10 -9
  49. data/lib/orchparty/plugins/env.rb +14 -13
  50. data/lib/orchparty/transformations/all.rb +3 -1
  51. data/lib/orchparty/transformations/mixin.rb +24 -24
  52. data/lib/orchparty/transformations/remove_internal.rb +3 -2
  53. data/lib/orchparty/transformations/sort.rb +2 -1
  54. data/lib/orchparty/transformations/variable.rb +6 -5
  55. data/lib/orchparty/transformations.rb +2 -0
  56. data/lib/orchparty/version.rb +3 -1
  57. data/lib/orchparty.rb +14 -14
  58. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbedced0f2e6a1c68ae0cce34908a34e3d8b5a9cbdf7aa2d083b4ece6216d4a6
4
- data.tar.gz: e4ba9f69335fc8292f701d258e2f958746979ece4c9b40a0092ba6d58f5518c7
3
+ metadata.gz: a3935821334bdae6ba17cf1073ab2f45e0dcae4587bb1483d833bd1fb6106672
4
+ data.tar.gz: 99c16f2c6eb5debdeb83e1c25356cae7c1c2e2b48d58805897c50b20968d608e
5
5
  SHA512:
6
- metadata.gz: 0b96daa8347897a59df15922108a1f148fea5ab5cf6549781c4647f381bad36c78bcf5d3836dbc8e6bda1832c453f7bf7a0640f308245574aae29a43bd7e6380
7
- data.tar.gz: 0f599e97da1714cb30acff69e689762440560d3f6e8f8c3a876dfdddfe754ce29875516a558750f942d48248554572b9557c62ea909958fa096c3d1f31f92329
6
+ metadata.gz: 0fcb53d62afde75285eb6e7f5d9fd29eeb196cd2872f29be992272e2584e508486bf645f6b1a5f180af965817a3de7e8b07e6115add457b6d6d49c29d7fcf4fb
7
+ data.tar.gz: e05c55fc240b2e40c6b9c5796988cc42522f0c7c64c9bf4927f9206601ccd0da174f9338c302dfc91964db0b4639242f4b1a64a11d227eae7348ac8df70a1873
@@ -9,7 +9,6 @@ name: Ruby
9
9
 
10
10
  on:
11
11
  push:
12
- branches: [ $default-branch ]
13
12
  pull_request:
14
13
  branches: [ $default-branch ]
15
14
 
@@ -22,7 +21,7 @@ jobs:
22
21
  runs-on: ubuntu-latest
23
22
  strategy:
24
23
  matrix:
25
- ruby-version: ['2.6', '2.7', '3.0']
24
+ ruby-version: ['3.1','3.2']
26
25
 
27
26
  steps:
28
27
  - uses: actions/checkout@v3
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 3.1
4
+ NewCops: enable
5
+ Exclude:
6
+ - '/**/schema.rb'
7
+ Layout/LineLength:
8
+ Max: 200
9
+ Metrics/AbcSize:
10
+ Enabled: false
11
+
12
+ # disabling it our stack.rb files have big blocks
13
+ Metrics/BlockLength:
14
+ Enabled: false
15
+ Metrics/MethodLength:
16
+ Max: 25
17
+ Style/Documentation:
18
+ Enabled: false
19
+ Style/OpenStructUse:
20
+ Enabled: false
21
+ # we use extensive blocks for openings and closing connections, give us more room (3 -> 5)
22
+ Metrics/BlockNesting:
23
+ Max: 5
24
+
25
+ # we have params like "op","in", ... but not shorter than that please
26
+ Naming/MethodParameterName:
27
+ MinNameLength: 2
28
+
29
+ # we have full controll over versions, we don't need this check
30
+ Gemspec/RequiredRubyVersion:
31
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 2.0.0
2
+ Incompatibility
3
+ * dropping ruby < 3.1 support
4
+ * config: NO support for "environment" specific overrides in configs, use hiera
5
+ * only allow to deploy stacks which are in env.roles, env.stacks or project:default_stacks
6
+ * Minfra::Cli.env not supported
7
+
8
+ Refactorings/Features
9
+ * refactoring Cli to CliStarter
10
+ * refactoring Cli to HierLooker
11
+ * support for argv_file to run commands from a file
12
+ * tests: more of them
13
+ * new command: dev envs
14
+ * new Kernel method: minfra_cli which is the CliStarter Object
15
+
1
16
  # 1.13.3
2
17
  * BUG: fixing 'labelÄ
3
18
  # 1.13.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minfra-cli (1.12.0)
4
+ minfra-cli (2.0.0)
5
5
  activesupport (= 7.0.7.2)
6
6
  erubis (~> 2.7)
7
7
  hashie (~> 3.5)
data/README.md CHANGED
@@ -3,7 +3,19 @@
3
3
  Is a KIND (k8s in docker) based development environment.
4
4
 
5
5
 
6
- ## Setup
6
+ ## Setup/Configuration/Global options
7
+
8
+
9
+ | Description | Environment variable | Project key | Global commandline arguments | Hiera key |
10
+ | --- | --- | --- | --- | --- |
11
+ | | MINFRA_NAME | name | | |
12
+ | | MINFRA_PATH | | --minfra_path [PATH TO MINFRA_PROJECT] | |
13
+ | | MINFRA_ENVIRONMENT | | -e [ENV] | |
14
+ | | MINFRA_ARGV_FILE | | --minfra_argv_file [PATH TO A CSV FILE FILE] | |
15
+ | | MINFRA_LOGGING_LEVEL | minfra.logging_level | | |
16
+ | | | minfra.hiera.env_path | | |
17
+ | | | default_stacks | | env.stacks | env.roles |
18
+
7
19
 
8
20
  ## Expected hiera data
9
21
 
data/exe/minfra CHANGED
@@ -3,6 +3,4 @@
3
3
  $LOAD_PATH << File.expand_path('../lib', __dir__)
4
4
  require 'minfra/cli'
5
5
 
6
- Minfra::Cli.init(ARGV)
7
- Minfra::Cli.run
8
-
6
+ exit Minfra::Cli.exec(ARGV)
data/lib/deep_merge.rb CHANGED
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hashie
2
4
  module Extensions
3
5
  module DeepMergeConcat
4
-
5
6
  def transform_values
6
7
  result = self.class.new
7
8
  each do |key, value|
@@ -31,82 +32,83 @@ module Hashie
31
32
  self
32
33
  end
33
34
 
34
- def deep_sort_by_key_and_sort_array(exclusions = [], &block)
35
- self.keys.sort(&block).reduce({}) do |seed, key|
35
+ def deep_sort_by_key_and_sort_array(exclusions = [], &)
36
+ keys.sort(&).each_with_object({}) do |key, seed|
36
37
  seed[key] = self[key]
37
- unless exclusions.include?(key.to_s)
38
- if seed[key].is_a?(Hash)
39
- seed[key] = seed[key].deep_sort_by_key_and_sort_array(exclusions, &block)
40
- elsif seed[key].is_a?(Hashie::Array)
41
- seed[key] = seed[key].sort(&block)
42
- end
38
+ next if exclusions.include?(key.to_s)
39
+
40
+ case seed[key]
41
+ when Hash
42
+ seed[key] = seed[key].deep_sort_by_key_and_sort_array(exclusions, &)
43
+ when Hashie::Array
44
+ seed[key] = seed[key].sort(&)
43
45
  end
44
- seed
45
46
  end
46
47
  end
47
48
 
48
49
  # Returns a new hash with +self+ and +other_hash+ merged recursively.
49
- def deep_sort(&block)
50
+ def deep_sort(&)
50
51
  copy = dup
51
52
  copy.extend(Hashie::Extensions::DeepMergeConcat) unless copy.respond_to?(:deep_sort!)
52
- copy.deep_sort!(&block)
53
+ copy.deep_sort!(&)
53
54
  end
54
55
 
55
56
  # Returns a new hash with +self+ and +other_hash+ merged recursively.
56
57
  # Modifies the receiver in place.
57
- def deep_sort!(&block)
58
- _recursive_sort(self, &block)
58
+ def deep_sort!(&)
59
+ _recursive_sort(self, &)
59
60
  self
60
61
  end
61
62
 
62
63
  # Returns a new hash with +self+ and +other_hash+ merged recursively.
63
- def deep_merge_concat(other_hash, &block)
64
+ def deep_merge_concat(other_hash, &)
64
65
  copy = dup
65
66
  copy.extend(Hashie::Extensions::DeepMergeConcat) unless copy.respond_to?(:deep_merge_concat!)
66
- copy.deep_merge_concat!(other_hash, &block)
67
+ copy.deep_merge_concat!(other_hash, &)
67
68
  end
68
69
 
69
70
  # Returns a new hash with +self+ and +other_hash+ merged recursively.
70
71
  # Modifies the receiver in place.
71
- def deep_merge_concat!(other_hash, &block)
72
+ def deep_merge_concat!(other_hash, &)
72
73
  return self unless other_hash.is_a?(::Hash)
73
- _recursive_merge_concat(self, other_hash, &block)
74
+
75
+ _recursive_merge_concat(self, other_hash, &)
74
76
  self
75
77
  end
76
78
 
77
- def deep_transform_values(&block)
78
- _deep_transform_values_in_object(self, &block)
79
+ def deep_transform_values(&)
80
+ _deep_transform_values_in_object(self, &)
79
81
  end
80
82
 
81
- def deep_transform_values!(&block)
82
- _deep_transform_values_in_object!(self, &block)
83
+ def deep_transform_values!(&)
84
+ _deep_transform_values_in_object!(self, &)
83
85
  end
84
86
 
85
87
  private
86
88
 
87
- def _deep_transform_values_in_object(object, &block)
89
+ def _deep_transform_values_in_object(object, &)
88
90
  case object
89
91
  when Hash
90
92
  object.each_with_object({}) do |arg, result|
91
93
  key = arg.first
92
94
  value = arg.last
93
- result[key] = _deep_transform_values_in_object(value, &block)
95
+ result[key] = _deep_transform_values_in_object(value, &)
94
96
  end
95
97
  when Array
96
- object.map {|e| _deep_transform_values_in_object(e, &block) }
98
+ object.map { |e| _deep_transform_values_in_object(e, &) }
97
99
  else
98
100
  yield(object)
99
101
  end
100
102
  end
101
103
 
102
- def _deep_transform_values_in_object!(object, &block)
104
+ def _deep_transform_values_in_object!(object, &)
103
105
  case object
104
106
  when Hash
105
107
  object.each do |key, value|
106
- object[key] = _deep_transform_values_in_object!(value, &block)
108
+ object[key] = _deep_transform_values_in_object!(value, &)
107
109
  end
108
110
  when Array
109
- object.map! {|e| _deep_transform_values_in_object!(e, &block) }
111
+ object.map! { |e| _deep_transform_values_in_object!(e, &) }
110
112
  else
111
113
  yield(object)
112
114
  end
@@ -115,31 +117,28 @@ module Hashie
115
117
  def _recursive_sort(object, &block)
116
118
  case object
117
119
  when Hash
118
- object = Orchparty::AST::Node.new(object.sort {|a, b| block.call(a[0], b[0]) }.to_h)
120
+ object = Orchparty::AST::Node.new(object.sort { |a, b| block.call(a[0], b[0]) }.to_h)
119
121
  object.each do |key, value|
120
122
  object[key] = _recursive_sort(value, &block)
121
123
  end
122
124
  object
123
125
  when Array
124
- object.map! {|e| _recursive_sort(e, &block) }.sort(&block)
126
+ object.map! { |e| _recursive_sort(e, &block) }.sort(&block)
125
127
  else
126
128
  yield(object)
127
129
  end
128
130
  end
129
131
 
130
-
131
132
  def _recursive_merge_concat(hash, other_hash, &block)
132
133
  other_hash.each do |k, v|
133
134
  hash[k] = if hash.key?(k) && hash[k].is_a?(::Hash) && v.is_a?(::Hash)
134
135
  _recursive_merge(hash[k], v, &block)
135
136
  elsif hash.key?(k) && hash[k].is_a?(::Array) && v.is_a?(::Array)
136
137
  hash[k].concat(v).uniq
138
+ elsif hash.key?(k) && block_given?
139
+ block.call(k, hash[k], v)
137
140
  else
138
- if hash.key?(k) && block_given?
139
- block.call(k, hash[k], v)
140
- else
141
- v.respond_to?(:deep_dup) ? v.deep_dup : v
142
- end
141
+ v.respond_to?(:deep_dup) ? v.deep_dup : v
143
142
  end
144
143
  end
145
144
  hash
data/lib/hash.rb CHANGED
@@ -1,28 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class HashUtils
2
- def self.transform_hash(original, options={}, &block)
3
- original.inject({}){|result, (key,value)|
4
- value = if (options[:deep] && Hash === value)
4
+ def self.transform_hash(original, options = {}, &block)
5
+ original.each_with_object({}) do |(key, value), result|
6
+ value = if options[:deep] && value.is_a?(Hash)
5
7
  transform_hash(value, options, &block)
6
- else
7
- if Array === value
8
- value.map{|v|
9
- if Hash === v
10
- transform_hash(v, options, &block)
11
- else
12
- v
13
- end}
14
- else
15
- value
8
+ elsif value.is_a?(Array)
9
+ value.map do |v|
10
+ if v.is_a?(Hash)
11
+ transform_hash(v, options, &block)
12
+ else
13
+ v
14
+ end
16
15
  end
16
+ else
17
+ value
17
18
  end
18
- block.call(result,key,value)
19
- result
20
- }
19
+ block.call(result, key, value)
20
+ end
21
21
  end
22
+
22
23
  # Convert keys to strings, recursively
23
24
  def self.deep_stringify_keys(hash)
24
- transform_hash(hash, :deep => true) {|hash, key, value|
25
+ transform_hash(hash, deep: true) do |hash, key, value|
25
26
  hash[key.to_s] = value
26
- }
27
+ end
27
28
  end
28
29
  end
@@ -1,42 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfra
2
4
  module Cli
3
5
  module Ask
4
6
  def self.boolean(question)
5
7
  answered = false
6
8
  until answered
7
- STDOUT.write "#{question} (y/n)"
8
- answer = STDIN.gets.chomp
9
- if ['y', 'n'].include?(answer)
9
+ $stdout.write "#{question} (y/n)"
10
+ answer = $stdin.gets.chomp
11
+ if %w[y n].include?(answer)
10
12
  answered = true
11
13
  else
12
- STDOUT.write("I just understand 'y' and 'n', again: ")
14
+ $stdout.write("I just understand 'y' and 'n', again: ")
13
15
  end
14
16
  end
15
17
  answer == 'y'
16
18
  end
17
19
 
18
- def self.text(question, default=nil)
19
- begin
20
+ def self.text(question, default = nil)
21
+ loop do
20
22
  message = format('%s%s: ', question, default && " (#{default})")
21
- STDOUT.write message
22
- answer = STDIN.gets.chomp
23
+ $stdout.write message
24
+ answer = $stdin.gets.chomp
23
25
  answer = default if answer == ''
24
- end while answer.nil?
26
+ break unless answer.nil?
27
+ end
25
28
  answer
26
29
  end
27
30
 
28
- def self.placeholders(templater,placeholders={})
31
+ def self.placeholders(templater, placeholders = {})
29
32
  templater.check_missing do |name|
30
- placeholders[name]=self.text("I need a value for: #{name}") unless placeholders[name]
33
+ placeholders[name] = text("I need a value for: #{name}") unless placeholders[name]
31
34
  end
32
35
  placeholders
33
36
  end
34
37
 
35
- def self.interactive_template(template_file, out_file, placeholders={})
36
- templater=Templater.new(File.read(template_file))
37
- params=self.placeholders(templater,placeholders)
38
- File.write(out_file,templater.render(params))
39
-
38
+ def self.interactive_template(template_file, out_file, placeholders = {})
39
+ templater = Templater.new(File.read(template_file))
40
+ params = self.placeholders(templater, placeholders)
41
+ File.write(out_file, templater.render(params))
40
42
  end
41
43
  end
42
44
  end
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minfra
4
+ module Cli
5
+ class CliStarter
6
+ attr_reader :options, :argv, :plugins, :config, :env_name, :base_path, :logger, :hiera, :envs, :env
7
+
8
+ def minfrarc_loaded?
9
+ @minfrarc_loaded
10
+ end
11
+
12
+ def minfrarc_me_loaded?
13
+ @minfrarc_me_loaded
14
+ end
15
+
16
+ def initialize(argv)
17
+ @argv = argv
18
+ @options = {} # base_path, env, argv_file
19
+ @minfrarc_loaded = false
20
+ @minfrarc_me_loaded = false
21
+
22
+ parse_global_options
23
+
24
+ @base_path = Pathname.new(@options[:base_path] || ENV.fetch('MINFRA_PATH', nil)).expand_path
25
+ @env_name = @options[:env] || ENV['MINFRA_ENVIRONMENT'] || 'dev'
26
+ init_config
27
+
28
+ init_logger
29
+
30
+ @logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}")
31
+
32
+ init_minfrarc
33
+ init_envs
34
+ init_hiera
35
+ init_plugins
36
+
37
+ register_subcommands
38
+
39
+ install # don't like this, but some plugins need the lookup....not good
40
+ @plugins.setup
41
+ require_relative 'main_command'
42
+
43
+ setup_subcommands
44
+ end
45
+
46
+ def run
47
+ exit_code = 0
48
+ if @options[:argv_file]
49
+ CSV.foreach(@options[:argv_file]) do |row|
50
+ args = @argv + row
51
+ @logger.debug("Running (#{env_name}): #{args.join(' ')} ")
52
+ begin
53
+ Minfra::Cli::Main.start(args)
54
+ rescue StandardError # esp. Minfra::Cli::Errors::ExitError !
55
+ exit_code = 1
56
+ end
57
+ end
58
+ @logger.debug('Done argv_file loop')
59
+ else
60
+ begin
61
+ Minfra::Cli::Main.start(@argv)
62
+ rescue Minfra::Cli::Errors::ExitError
63
+ exit_code = 1
64
+ end
65
+ end
66
+ exit_code
67
+ end
68
+
69
+ def install
70
+ cli = self
71
+ Kernel.define_method(:minfra_cli) do
72
+ cli
73
+ end
74
+ Kernel.define_method(:l) do |key, default = nil|
75
+ minfra_cli.hiera.l(key, default)
76
+ end
77
+ Kernel.define_method(:l!) do |key, default = nil|
78
+ minfra_cli.hiera.l!(key, default)
79
+ end
80
+ end
81
+ private
82
+
83
+ def root_path
84
+ Pathname.new(File.expand_path(File.join(__FILE__, '../../../..')))
85
+ end
86
+
87
+ # will parse -e, --argv_file, --
88
+ def parse_global_options
89
+ @options = {}
90
+ if (idx = @argv.index('-e'))
91
+ @options[:env] = @argv[idx + 1]
92
+ @argv.delete_at(idx)
93
+ @argv.delete_at(idx)
94
+ end
95
+
96
+ if (idx = argv.index('--minfra_argv_file'))
97
+ @options[:argv_file] = @argv[idx + 1]
98
+ @argv.delete_at(idx)
99
+ @argv.delete_at(idx)
100
+ end
101
+
102
+ if (idx = argv.index('--minfra_path'))
103
+ @options[:base_path] = @argv[idx + 1]
104
+ @argv.delete_at(idx)
105
+ @argv.delete_at(idx)
106
+ end
107
+
108
+ @options
109
+ end
110
+
111
+ def init_minfrarc
112
+ # load minfrarc for configs
113
+ project_minfrarc_path = @config.base_path.join('config', 'minfrarc.rb')
114
+ if project_minfrarc_path.exist?
115
+ require project_minfrarc_path
116
+ @minfrarc_loaded = true
117
+ end
118
+
119
+ # load
120
+ me_minfrarc_path = @config.me_path.join('minfrarc.rb')
121
+ return unless me_minfrarc_path.exist?
122
+
123
+ require @me_minfrarc_path
124
+ @minfrarc_me_loaded = true
125
+ end
126
+
127
+ def init_plugins
128
+ @plugins = Minfra::Cli::Plugins.load(@base_path)
129
+ @plugins.prepare
130
+ end
131
+
132
+ def init_logger
133
+ @logger = Logger.new($stderr)
134
+ @logger.level = ENV['MINFRA_LOGGING_LEVEL'] || @config.project.dig(:minfra, :logging_level) || 'warn'
135
+ Minfra::Cli.logger = @logger
136
+ end
137
+
138
+ def init_config
139
+ @config = Config.new(@base_path, @env_name || 'dev')
140
+ Minfra::Cli.config = @config
141
+ end
142
+
143
+ def init_hiera
144
+ @hiera = @env.hiera
145
+ end
146
+
147
+ def init_envs
148
+ @envs={}
149
+ env_path = config.project.dig(:minfra, :hiera, :env_path) || 'environments'
150
+ root = base_path.join('hiera')
151
+ root.join('hieradata',env_path).glob('*.eyaml').sort.each do |path|
152
+ env_name = path.basename.sub(/(\..+)/,'').to_s
153
+ @envs[env_name]=Env.new(hiera_root: root, hiera_env_path: env_path, name: env_name)
154
+ end
155
+ @env = @envs[@env_name] # set the current env
156
+ end
157
+
158
+ def register_subcommands
159
+ # they will call back Minfra::Cli.register
160
+ root_path.join('lib/minfra/cli/commands').each_child do |command_path|
161
+ require command_path if command_path.to_s.match(/\.rb$/) && !command_path.to_s.match(/\#/)
162
+ end
163
+ end
164
+
165
+ def setup_subcommands
166
+ Minfra::Cli.subcommands.each_value do |sub|
167
+ Minfra::Cli::Main.desc(sub.name, sub.info)
168
+ Minfra::Cli::Main.subcommand(sub.name, sub.command)
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Minfra
2
4
  module Cli
3
5
  class Command < Thor
@@ -5,9 +7,10 @@ module Minfra
5
7
  include Logging
6
8
 
7
9
  private
10
+
8
11
  def minfra_config
9
12
  Minfra::Cli.config
10
- end
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -1,54 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  module Minfra
3
5
  module Cli
4
6
  class Dev < Command
5
-
6
- desc "describe", "get some info about your config (if it's setup)"
7
+ desc 'describe', "get some info about your config (if it's setup)"
7
8
  option :environment, required: false, aliases: ['-e']
8
9
  def describe
9
10
  pp minfra_config.describe(options[:environment])
10
11
  end
11
12
 
12
- desc "create", "create your development cluster"
13
+ desc 'create', 'create your development cluster'
13
14
  def create
14
15
  kube.create
15
16
  end
16
17
 
17
- desc "upgrade", "upgrade kind (moves previous configs and recreates the cluster; use it if you made changes to config/kind.yaml.erb)"
18
+ desc 'upgrade',
19
+ 'upgrade kind (moves previous configs and recreates the cluster; use it if you made changes to config/kind.yaml.erb)'
18
20
  def upgrade
19
- info "Destroying existing dev cluster.."
21
+ info 'Destroying existing dev cluster..'
20
22
  destroy
21
- Runner.run("mv #{minfra_config.base_path.join('me','kind.yaml.erb')} #{minfra_config.base_path.join('me','kind_old_' + Time.now.strftime("%Y_%m_%dT%H_%M_%SZ") + '.yaml.erb')}", print_stdout: true)
22
- Runner.run("mv #{minfra_config.base_path.join('me', 'kube', 'config')} #{minfra_config.base_path.join('me', 'kube', 'config_old_' + Time.now.strftime("%Y_%m_%dT%H_%M_%SZ"))}", print_stdout: true)
23
+ Runner.run(
24
+ "mv #{minfra_config.base_path.join('me',
25
+ 'kind.yaml.erb')} #{minfra_config.base_path.join('me', "kind_old_#{Time.now.strftime('%Y_%m_%dT%H_%M_%SZ')}.yaml.erb")}", print_stdout: true
26
+ )
27
+ Runner.run(
28
+ "mv #{minfra_config.base_path.join('me', 'kube',
29
+ 'config')} #{minfra_config.base_path.join('me', 'kube', "config_old_#{Time.now.strftime('%Y_%m_%dT%H_%M_%SZ')}")}", print_stdout: true
30
+ )
23
31
  Runner.run('yes | minfra setup dev', print_stdout: true) # On an existing cluster this should only ask for recreating the files that we moved previously
24
- info "Creating a new dev cluster.."
32
+ info 'Creating a new dev cluster..'
25
33
  create
26
- info "I am done upgrading the dev cluster! 🎉"
34
+ info 'I am done upgrading the dev cluster! 🎉'
27
35
  end
28
36
 
29
- desc "restart", "restart your development cluster"
37
+ desc 'restart', 'restart your development cluster'
30
38
  def restart
31
39
  kube.restart
32
40
  end
33
41
 
34
- desc "start", "start your development cluster"
42
+ desc 'start', 'start your development cluster'
35
43
  def start
36
44
  restart
37
45
  end
38
46
 
39
- desc "destroy", "tear down your development cluster"
47
+ desc 'destroy', 'tear down your development cluster'
40
48
  def destroy
41
49
  kube.destroy_dev_cluster
42
50
  end
43
51
 
52
+ desc 'envs', 'list all environments'
53
+ def envs
54
+ puts minfra_cli.envs.keys.join(', ')
55
+ end
44
56
  private
45
57
 
46
58
  def kube
47
- @kube ||= Kube.new(options,minfra_config)
59
+ @kube ||= Kube.new(options, minfra_config)
48
60
  end
49
-
50
61
  end
51
62
  end
52
63
  end
53
64
 
54
- Minfra::Cli.register("dev", "Manage your dev cluster.", Minfra::Cli::Dev)
65
+ Minfra::Cli.register('dev', 'Manage your dev cluster.', Minfra::Cli::Dev)