cl-magic 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 504fca48eea3cb6eca83e8025a98e4f3187f19286b81134b42b53a0a639f2b9b
4
- data.tar.gz: 1269ba9642497c4e7541598d3ba180a09b2e5c033627ae9e60cbd545ba3f4e91
3
+ metadata.gz: 80e53f5ff775b7ea5408b5d2e897ff5b5aa660c3e4bac1fcb2665299b8720d58
4
+ data.tar.gz: 3548fc6ff4d1521bf7ce556e7308cc3c91a75ec79e0617c913ead953fc10348f
5
5
  SHA512:
6
- metadata.gz: b56850adb7d7182d6a72777236902b7b961493f3780c209675c268381c4ccfc78a339ea740f38ed9dd16c2a96f8c102efa24ea3527435699830219b7a5b9e8c9
7
- data.tar.gz: a83324b6a355286f9ad2cfaf7b034ca93b710f2706da1fb4e1b61722575a6477e42763d669b082bc72dc308fa5c78195cedaa64c755f9ef4d250f98b36e443b0
6
+ metadata.gz: 74e1d78d0a26c2cfab9c2ada3bb4ae2785494697845460beada56310f1759c0c1d3aaf4834956c030b9c7c15a13edd6a8100f99285bae4bd9699729e2973e848
7
+ data.tar.gz: e7c3f76abb93e22048895e7b451c835c8048a6548a929db52c6c2ab7b9b10f6fddabe41f9641d9b09a7a39642a4e1f4461dab33f7f2352e68e9ef4b6d8a420ce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cl-magic (0.3.0)
4
+ cl-magic (0.3.1)
5
5
  optparse-subcommand
6
6
  pastel
7
7
  tty-command
data/lib/cl/magic/cl-auth CHANGED
@@ -62,14 +62,6 @@ github_cli_banner = <<DOC
62
62
 
63
63
  DOC
64
64
 
65
- aws_okta_banner = <<DOC
66
-
67
- Authenticate with https://github.com/segmentio/aws-okta
68
-
69
- Usage: #{@cl_cmd_name} aws-okta [options]
70
-
71
- DOC
72
-
73
65
  global = OptionParser.new do |g|
74
66
  g.banner = global_banner
75
67
  add_help_and_verbose(g)
@@ -84,11 +76,6 @@ global = OptionParser.new do |g|
84
76
  options[:action] = :github_cli
85
77
  end
86
78
 
87
- g.subcommand 'aws-okta' do |s|
88
- s.banner = aws_okta_banner
89
- options[:action] = :aws_okta
90
- end
91
-
92
79
  end
93
80
 
94
81
  #
data/lib/cl/magic/cl-dk CHANGED
@@ -2,10 +2,12 @@
2
2
  require 'yaml'
3
3
  require 'json'
4
4
  require 'tty-command'
5
+ require 'tty-prompt'
5
6
  require 'tempfile'
6
7
 
7
8
  require 'cl/magic/common/common_options.rb'
8
9
  require 'cl/magic/common/logging.rb'
10
+ require 'cl/magic/common/parse_and_pick.rb'
9
11
 
10
12
  @logger = get_logger()
11
13
 
@@ -18,23 +20,50 @@ def get_base_compose_hash()
18
20
  return YAML.load(`#{cmd}`)
19
21
  end
20
22
 
23
+ def get_save_parts_filepath()
24
+ return File.join(@working_dir, ".cl-dk-parts.yml")
25
+ end
26
+
27
+ # world
28
+
21
29
  def get_repo_basename()
22
30
  command = "cd #{@working_dir} && basename $(git remote get-url origin 2> /dev/null) .git"
23
31
  return TTY::Command.new(:printer => :null).run(command).out.gsub('.git', '').strip.chomp
24
32
  end
25
33
 
26
- def get_dk_world_project_path()
27
- repo_basename = get_repo_basename()
28
- return "dk-world/#{repo_basename}" if repo_basename
29
- return nil
34
+ def get_world_settings_filepath()
35
+ return File.join(".cl-dk-world.yml")
30
36
  end
31
37
 
32
- def get_save_parts_filepath()
33
- return File.join(@working_dir, ".cl-dk-parts.yml")
38
+ def get_world_settings_hash()
39
+ filepath = get_world_settings_filepath()
40
+ return File.exist?(filepath) ? YAML.load_file(filepath) : {}
41
+ end
42
+
43
+ def get_world_path_from_settings()
44
+ world_settings = get_world_settings_hash()
45
+ if world_settings.key?(:world_path) and world_settings.key?(:context)
46
+ return File.join(world_settings[:world_path], world_settings[:context])
47
+ end
48
+ return ""
49
+ end
50
+
51
+ def save_world_settings(world_settings_hash)
52
+ filepath = get_world_settings_filepath()
53
+ tempfile = File.new(filepath, 'w')
54
+ tempfile.write(world_settings_hash.to_yaml)
55
+ tempfile.close
56
+ end
57
+
58
+ def get_world_project_path()
59
+ repo_basename = get_repo_basename()
60
+ world_path = get_world_path_from_settings()
61
+ return File.join(world_path, repo_basename) if world_path and repo_basename
62
+ return nil
34
63
  end
35
64
 
36
65
  #
37
- # Print Help Methods
66
+ # Help Methods
38
67
  #
39
68
 
40
69
  def print_dk_help_line(key, help)
@@ -69,26 +98,27 @@ def print_dk_help(dk_parts_hash, dk_make_hash, args)
69
98
  puts "Run docker compose while munging yamls in sophisticated ways."
70
99
  puts ""
71
100
  if get_repo_basename
72
- puts "PROJ INFO:"
101
+ puts "PROJ INFO"
73
102
  puts " - Repo basename: #{get_repo_basename}"
74
- puts " - World filepath: #{File.join(@working_dir, get_dk_world_project_path())}"
103
+ puts " - World filepath: #{get_world_project_path()}"
75
104
  puts ""
76
105
  end
77
- puts "PROJ PARTS:"
106
+ puts "PROJ PARTS"
78
107
  dk_parts_hash.keys.each do |key|
79
108
  print_dk_help_line(key, dk_parts_hash[key].fetch('help'))
80
109
  end
81
110
  puts ""
82
111
  puts "YML TOKENS"
83
- puts " - <dk-remove>"
84
- puts " - <dk-replace>"
85
- puts " - <dk-project-path>"
86
- puts " - <dk-world-path>"
87
- puts " - <dk-working-path>"
112
+ puts " - <dk-remove> removes section of yaml"
113
+ puts " - <dk-replace> replaces values in a yaml array"
114
+ puts " - <dk-world-path> absolute filepath to world directory"
115
+ puts " - <dk-project-path> absolute filepath to world/project directory"
116
+ puts " - <dk-working-path> absolute filepath to location dk command was run from"
88
117
  puts ""
89
- puts "ADDITIONAL TURNKEY COMMANDS:"
90
- puts " - dk make"
91
- puts " - dk save-parts"
118
+ puts "ADDITIONAL TURNKEY COMMANDS"
119
+ puts " - dk set-world sets the location of the world directory"
120
+ puts " - dk make turnkey commands for a project"
121
+ puts " - dk save-parts save parts so they are automatically applied to commands"
92
122
  puts ""
93
123
  puts "-------------------------"
94
124
  end
@@ -113,6 +143,14 @@ def print_make_help(dk_parts_hash, dk_make_hash)
113
143
  puts ""
114
144
  end
115
145
 
146
+ def print_set_world_help()
147
+ puts ""
148
+ puts "Usage: dk set-world PATH"
149
+ puts ""
150
+ puts "Set the folder that contains dk-world configuration"
151
+ puts ""
152
+ end
153
+
116
154
  def print_save_parts_help(dk_parts_hash)
117
155
  puts ""
118
156
  puts "Usage: dk [DK_PARTS] save-parts"
@@ -169,7 +207,7 @@ def dk_merge_and_remove(compose_hash, yml_hash)
169
207
  end
170
208
 
171
209
  def merge_world_files(compose_hash, show_help=false)
172
- dk_proj_path = get_dk_world_project_path()
210
+ dk_proj_path = get_world_project_path()
173
211
  if dk_proj_path
174
212
  print_dk_help_line("dk-project-path", "#{dk_proj_path}") if show_help
175
213
 
@@ -178,8 +216,8 @@ def merge_world_files(compose_hash, show_help=false)
178
216
 
179
217
  # read file and replace
180
218
  contents = File.read(filepath)
181
- contents.gsub!('<dk-world-path>', File.join(Dir.pwd, "dk-world"))
182
- contents.gsub!('<dk-project-path>', File.join(Dir.pwd, dk_proj_path))
219
+ contents.gsub!('<dk-world-path>', get_world_path_from_settings())
220
+ contents.gsub!('<dk-project-path>', dk_proj_path)
183
221
  contents.gsub!('<dk-working-path>', @working_dir)
184
222
 
185
223
  # yml merge
@@ -276,6 +314,51 @@ def run_dk(compose_args)
276
314
  exec(cmd)
277
315
  end
278
316
 
317
+ #
318
+ # Run: SET WORLD
319
+ #
320
+
321
+ def run_dk_set_world()
322
+ world_settings = get_world_settings_hash()
323
+
324
+ # world path
325
+ world_path = ARGV[1]
326
+ if world_path.nil?
327
+ print_set_world_help
328
+ exit
329
+ else
330
+ world_path = File.expand_path(File.join(@working_dir, world_path))
331
+ end
332
+
333
+ if TTY::Prompt.new.yes?("Set world to: #{world_path}?")
334
+ world_settings[:world_path] = world_path
335
+ save_world_settings(world_settings)
336
+ run_dk_set_context()
337
+ else
338
+ exit
339
+ end
340
+
341
+ end
342
+
343
+ def run_dk_set_context()
344
+ world_settings = get_world_settings_hash()
345
+ unless world_settings[:world_path] and File.directory?(world_settings[:world_path])
346
+ @logger.error "no world path set."
347
+ exit 1
348
+ end
349
+
350
+ # read folder from world path (aka. context)
351
+ all_dir = Dir.chdir(world_settings[:world_path]) do
352
+ Dir.glob('*').select { |f| File.directory? f and f != "common" }
353
+ end
354
+ selected_dir = pick_single_result(all_dir.collect {|f| [f]}, "select context").first
355
+ world_settings[:context] = selected_dir
356
+ save_world_settings(world_settings)
357
+
358
+ @logger.puts "world set!"
359
+ exit
360
+ end
361
+
279
362
  #
280
363
  # Run: SAVE PARTS
281
364
  #
@@ -285,6 +368,7 @@ def run_dk_save_parts(compose_args, dk_parts_hash, selected_part_keys)
285
368
  if selected_part_keys.any?
286
369
  tempfile = File.new(filepath, 'w')
287
370
  tempfile.write(selected_part_keys.to_yaml) # write it to the tempfile
371
+ tempfile.close
288
372
  else
289
373
  if File.exist?(filepath)
290
374
  File.delete(filepath)
@@ -374,6 +458,14 @@ end
374
458
 
375
459
  @working_dir = ENV['CL_WORKING_DIR'] # passed through cl-magic to here
376
460
 
461
+ # sub-command
462
+ case ARGV.first
463
+ when "set-world"
464
+ run_dk_set_world()
465
+ when "set-context"
466
+ run_dk_set_context()
467
+ end
468
+
377
469
  # get compose settings
378
470
  compose_hash = get_base_compose_hash()
379
471
  if compose_hash
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cl
4
4
  module Magic
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cl-magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Najd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-13 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake