squared 0.4.14 → 0.5.0

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.
@@ -21,8 +21,7 @@ module Squared
21
21
  compose: {
22
22
  common: %w[all-resources compatibility dry-run ansi|b env-file=p f|file=p parallel=b profile=b progress=b
23
23
  project-directory=p p|project-name=e].freeze,
24
- build: %w[check no-cache pull push with-dependencies q|quiet build-arg=qq builder=b m|memory=b
25
- ssh=qq].freeze,
24
+ build: %w[no-cache pull push with-dependencies q|quiet build-arg=qq builder=b m|memory=b ssh=qq].freeze,
26
25
  exec: %w[dry-run privileged d|detach e|env=qq index=i T|no-TTY=b? user=e w|workdir=q].freeze,
27
26
  run: %w[build dry-run no-deps quiet-pull remove-orphans rm P|service-ports use-aliases cap-add=b cap-drop=b
28
27
  d|detach entrypoint=q e|env=qq i|interactive=b? l|label=q name=b T|no-TTY=b? p|publish=e pull=b
@@ -112,6 +111,7 @@ module Squared
112
111
  @mounts = mounts
113
112
  @secrets = secrets
114
113
  @registry = tagjoin registry, kwargs[:username]
114
+ @file = nil
115
115
  initialize_ref Docker.ref
116
116
  initialize_logger(**kwargs)
117
117
  initialize_env(**kwargs)
@@ -160,7 +160,7 @@ module Squared
160
160
  compose! flag, args.to_a
161
161
  end
162
162
  when :exec, :run
163
- format_desc action, flag, "service,command#{flag == :exec ? '' : '?'}|:,args*,opts*"
163
+ format_desc action, flag, "service,command#{flag == :exec ? '' : '?'},args*,opts*"
164
164
  task flag, [:service] do |_, args|
165
165
  service = param_guard(action, flag, args: args, key: :service)
166
166
  compose!(flag, args.extras, service: service)
@@ -198,8 +198,8 @@ module Squared
198
198
  when :push
199
199
  format_desc action, flag, 'tag,registry/username?,opts*'
200
200
  task flag, [:tag] do |_, args|
201
- tag = param_guard(action, flag, args: args, key: :tag)
202
- image(flag, args.extras, id: tag)
201
+ id = param_guard(action, flag, args: args, key: :tag)
202
+ image(flag, args.extras, id: id)
203
203
  end
204
204
  else
205
205
  format_desc(action, flag, case flag
@@ -267,10 +267,8 @@ module Squared
267
267
  end
268
268
 
269
269
  [args, flags].each_with_index do |target, index|
270
- if target.is_a?(String)
271
- ret << target
272
- elsif (target = append_any(target, target: []))
273
- ret.merge(target.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
270
+ if (data = append_any(target, target: []))
271
+ ret.merge(data.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
274
272
  end
275
273
  end
276
274
  case from
@@ -280,12 +278,12 @@ module Squared
280
278
  ret << quote_option('secret', @secrets, double: true)
281
279
  when Hash
282
280
  append = lambda do |type|
283
- Array(@secrets[type]).each { |arg| ret << quote_option('secret', "type=#{type},#{arg}", double: true) }
281
+ as_a(@secrets[type]).each { |arg| ret << quote_option('secret', "type=#{type},#{arg}", double: true) }
284
282
  end
285
283
  append.call(:file)
286
284
  append.call(:env)
287
285
  else
288
- Array(@secrets).each { |arg| ret << quote_option('secret', arg) }
286
+ as_a(@secrets).each { |arg| ret << quote_option('secret', arg) }
289
287
  end
290
288
  if (val = option('tag', ignore: false))
291
289
  append_tag val
@@ -294,8 +292,8 @@ module Squared
294
292
  end
295
293
  append_context
296
294
  when :bake, :compose
297
- if (val = option(from == :bake ? 'target' : 'service', ignore: false))
298
- ret.merge(split_escape(val).map! { |s| shell_escape(s) })
295
+ option(from == :bake ? 'target' : 'service', ignore: false) do |a|
296
+ ret.merge(split_escape(a).map! { |b| shell_escape(b) })
299
297
  end
300
298
  end
301
299
  ret
@@ -313,7 +311,7 @@ module Squared
313
311
  when :bake
314
312
  unless op.empty?
315
313
  args = op.dup
316
- op.reset
314
+ op.extras.clear
317
315
  if Dir.exist?(args.last)
318
316
  if projectpath?(val = args.pop)
319
317
  context = val
@@ -360,11 +358,11 @@ module Squared
360
358
  both = run[:bind] + run[:tmpfs]
361
359
  diff = run[:bind].reject { |val| run[:tmpfs].include?(val) }
362
360
  delim = Regexp.new(",\\s*(?=#{both.join('|')})")
363
- Array(@mounts).each do |val|
361
+ as_a(@mounts).each do |val|
364
362
  args = []
365
363
  tmpfs = true
366
364
  val.split(delim).each do |opt|
367
- k, v, q = split_option(opt)
365
+ k, v, q = split_option opt
368
366
  next unless both.include?(k)
369
367
 
370
368
  if k == 'type'
@@ -504,7 +502,7 @@ module Squared
504
502
  raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint: from) unless id && op.empty?
505
503
  raise_error('username/registry not provided', hint: from) unless registry
506
504
  registry.chomp!('/')
507
- uri = shell_quote("#{registry}/#{id}")
505
+ uri = shell_quote "#{registry}/#{id}"
508
506
  op << uri
509
507
  img = docker_output 'image', 'tag', id, uri
510
508
  return unless confirm_command(img.to_s, cmd.to_s, target: id, as: registry, title: from)
@@ -566,9 +564,7 @@ module Squared
566
564
  end
567
565
 
568
566
  def append_command(flag, val, list, target: @session, from: nil)
569
- if list.delete(':')
570
- list << readline('Enter command [args]', force: true)
571
- elsif (args = env('DOCKER_ARGS'))
567
+ if (args = env('DOCKER_ARGS'))
572
568
  list << args
573
569
  end
574
570
  case flag
@@ -591,7 +587,7 @@ module Squared
591
587
  def append_file(type, target: @session)
592
588
  return unless type == 2 || type == 4 || @file.is_a?(Array)
593
589
 
594
- files = Array(@file).map { |val| quote_option('file', path + val) }
590
+ files = as_a(@file).map { |val| quote_option('file', path + val) }
595
591
  if target.is_a?(Set)
596
592
  target.merge(files)
597
593
  else
@@ -607,18 +603,20 @@ module Squared
607
603
  end
608
604
 
609
605
  def append_tag(val, target: @session)
610
- ver = option('version', target: target, ignore: false)
611
- list = case val
612
- when String
613
- val.split(',')
614
- when Array
615
- val
616
- else
617
- []
618
- end
619
- list.each do |s|
620
- s = "#{s.sub(/:latest$/, '')}:#{ver}" if ver && (!s.include?(':') || s.end_with?(':latest'))
621
- target << basic_option('tag', tagname(s))
606
+ case val
607
+ when String
608
+ val.split(',')
609
+ when Array
610
+ val
611
+ else
612
+ []
613
+ end.yield_self do |list|
614
+ ver = option('version', target: target, ignore: false)
615
+ list.each do |s|
616
+ s = "#{s}:#{ver}" if ver && (!s.include?(':') || s.delete_suffix!(':latest'))
617
+ target << basic_option('tag', tagname(s))
618
+ end
619
+ target
622
620
  end
623
621
  end
624
622
 
@@ -665,7 +663,7 @@ module Squared
665
663
  cols.each do |key|
666
664
  next if (key == 'Tag' && !dd) || (key == 'Size' && data[key] == '0B')
667
665
 
668
- puts "#{g + f} #{key}: #{Array(data[key]).join(', ')}" unless data[key].to_s.empty?
666
+ puts "#{g + f} #{key}: #{as_a(data[key]).join(', ')}" unless data[key].to_s.empty?
669
667
  end
670
668
  w = 9 + flag.to_s.size + 4 + ee.size
671
669
  puts g + sub_style(ARG[:BORDER][6] + (ARG[:BORDER][1] * w), styles: theme[:inline])
@@ -758,7 +756,7 @@ module Squared
758
756
  [parse.call(out)]
759
757
  end)
760
758
  cmd << args
761
- print_success if success?(run(cmd)) && ctx.match?(/\A(?:network|tag|save)/)
759
+ print_success if success?(run(cmd)) && ctx.start_with?(/(?:network|tag|save)/)
762
760
  end
763
761
  end
764
762
 
@@ -788,9 +786,10 @@ module Squared
788
786
 
789
787
  def tagname(val)
790
788
  val = val.split(':').map! { |s| charname(s.sub(/^\W+/, '')) }
791
- ret = val.join(':')
792
- ret = val.first if val.size > 1 && ret.size > 128
793
- ret[0..127]
789
+ val.join(':').yield_self do |s|
790
+ s = val.first if val.size > 1 && s.size > 128
791
+ s[0..127]
792
+ end
794
793
  end
795
794
 
796
795
  def dnsname(val)