squared 0.7.6 → 0.8.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.
@@ -61,7 +61,8 @@ module Squared
61
61
  stop: %w[s|signal=b t|timeout=i].freeze,
62
62
  restart: %w[s|signal=b t|timeout=i].freeze,
63
63
  kill: %w[s|signal=b].freeze,
64
- stats: %w[a|all no-stream no-trunc format|q].freeze
64
+ stats: %w[a|all no-stream no-trunc format|q].freeze,
65
+ attach: %w[no-stdin detach-keys=q sig-proxy=!?].freeze
65
66
  }.freeze,
66
67
  image: {
67
68
  ls: %w[a|all digests no-trunc q|quiet tree f|filter=q format=q].freeze,
@@ -114,8 +115,8 @@ module Squared
114
115
  'compose' => %i[build create publish run exec up down service].freeze,
115
116
  'bake' => %i[build compose check].freeze,
116
117
  'image' => %i[ls rm pull push tag save].freeze,
117
- 'container' => %i[run create exec update commit inspect diff start stop restart pause unpause top stats kill
118
- rm].freeze,
118
+ 'container' => %i[attach commit create diff exec inspect kill pause restart rm run start stats stop top
119
+ unpause update].freeze,
119
120
  'network' => %i[connect disconnect create].freeze,
120
121
  'ls' => nil
121
122
  })
@@ -165,7 +166,7 @@ module Squared
165
166
  when 'compose'
166
167
  'ps'
167
168
  else
168
- raise_error ArgumentError, 'unrecognized command', hint: command
169
+ raise ArgumentError, message('unrecognized command', hint: command)
169
170
  end
170
171
  cmd << '-a' if has_value!(args, 'a', 'all') && command != 'network'
171
172
  data = VAL_DOCKER[:ls][command.to_sym]
@@ -226,19 +227,20 @@ module Squared
226
227
  format_desc action, flag, "service/:,command#{'?' unless flag == :exec}/::,args*,opts*"
227
228
  task flag, [:service] do |_, args|
228
229
  service = param_guard(action, flag, args: args, key: :service)
229
- compose!(flag, args.extras, service: service)
230
+ compose_(flag, args.extras, service: service)
230
231
  end
231
232
  when :service
232
233
  cmds = %w[down kill pause restart rm start stop top unpause watch].freeze
233
234
  format_desc(action, flag, cmds, arg: nil, after: 'name+|:')
234
235
  task flag, [:command] do |_, args|
235
- command = param_guard(action, flag, args: args, key: :command)
236
- raise_error ArgumentError, 'unrecognized command', hint: command unless cmds.include?(command)
236
+ cmd = param_guard(action, flag, args: args, key: :command)
237
+ raise ArgumentError, message('unrecognized command', hint: cmd) unless cmds.include?(cmd)
238
+
237
239
  service = args.extras
238
240
  if service.first == ':'
239
- choice_command flag, command
241
+ choice_command flag, cmd
240
242
  else
241
- compose!(flag, [command], service: service.empty? || service)
243
+ compose_(flag, [cmd], service: service.empty? || service)
242
244
  end
243
245
  end
244
246
  when :publish
@@ -246,12 +248,12 @@ module Squared
246
248
 
247
249
  format_desc action, flag, 'tag?,repository?,opts*'
248
250
  task flag, [:tag] do |_, args|
249
- compose! flag, args.to_a
251
+ compose_ flag, args.to_a
250
252
  end
251
253
  else
252
254
  format_desc action, flag, 'opts*,service*|:'
253
255
  task flag do |_, args|
254
- compose!(flag, args.to_a, multiple: true)
256
+ compose_(flag, args.to_a, multiple: true)
255
257
  end
256
258
  end
257
259
  when 'container'
@@ -419,16 +421,22 @@ module Squared
419
421
  when :bake
420
422
  append_file(0, index: 3) unless from || op.arg?('f', 'file') || !anypath?(*COMPOSEFILE)
421
423
  unless op.empty?
422
- context = op.pop if Dir.exist?(op.last) && projectpath?(op.last)
424
+ if !context && op.size > 1 && exist?(op.last, type: 'd')
425
+ pat = /\btarget\s+"#{Regexp.escape(op.last)}"/
426
+ context = op.pop if op.values_of('f', 'file').none? { |f| basepath!(f)&.read&.match?(pat) }
427
+ end
428
+ if context
429
+ context = basepath context
430
+ op.each { |name| op.add_option('set', "#{name}.context=#{context}", escape: false) }
431
+ end
423
432
  op.append(escape: true, strip: /^:/, clear: true)
424
- contextdir context if context
425
433
  end
426
434
  end
427
435
  op.clear(pass: false)
428
436
  run(from: from || symjoin('buildx', flag))
429
437
  end
430
438
 
431
- def compose!(flag, opts = [], id: nil, service: nil, multiple: false)
439
+ def compose_(flag, opts = [], id: nil, service: nil, multiple: false)
432
440
  from = symjoin 'compose', flag
433
441
  if flag == :service
434
442
  command = opts.first
@@ -465,7 +473,8 @@ module Squared
465
473
  op.concat(service) if service
466
474
  op.append(delim: true, escape: true, strip: /^:/)
467
475
  else
468
- raise_error ArgumentError, 'no service was selected', hint: flag unless service
476
+ raise ArgumentError, message('no service was selected', hint: flag) unless service
477
+
469
478
  append_command(flag, service, op.extras, prompt: '::')
470
479
  end
471
480
  end
@@ -495,7 +504,7 @@ module Squared
495
504
  when 'bind', 'volume', 'image', 'tmpfs'
496
505
  type = v
497
506
  else
498
- raise_error TypeError, "unknown: #{v || "''"}", hint: flag
507
+ raise TypeError, message('unknown', v || "''", hint: flag)
499
508
  end
500
509
  elsif all.include?(k)
501
510
  unless type
@@ -511,7 +520,8 @@ module Squared
511
520
  out << k
512
521
  next
513
522
  when 'source', 'src', 'destination', 'dst', 'target', 'volume-subpath', 'image-path'
514
- raise_error ArgumentError, "#{k}: no path value", hint: flag unless v
523
+ raise ArgumentError, message('no path value', k, hint: flag) unless v
524
+
515
525
  v = basepath v
516
526
  v = shell_quote(v, option: false, force: false) if q == ''
517
527
  end
@@ -520,18 +530,20 @@ module Squared
520
530
  log_message('unrecognized option', subject: from, hint: k)
521
531
  end
522
532
  end
523
- raise_error TypeError, 'none specified', hint: flag unless type
533
+ raise TypeError, message('none specified', hint: flag) unless type
534
+
524
535
  cmd << "--mount type=#{type},#{args.join(',')}"
525
536
  end
526
537
  end
527
538
  append_command(flag, id || tagmain, op.extras)
528
539
  when :update
529
- raise_error ArgumentError, 'missing container', hint: flag if op.empty?
540
+ raise ArgumentError, message('missing container', hint: flag) if op.empty?
541
+
530
542
  op.append(escape: true, strip: /^:/)
531
543
  when :commit
532
544
  latest = op.shift || tagmain
533
545
  cmd << id << latest
534
- raise_error ArgumentError, "unrecognized args: #{op.join(', ')}", hint: flag unless op.empty?
546
+ raise ArgumentError, message('unrecognized args', op.join(', '), hint: flag) unless op.empty?
535
547
  return unless confirm_command(cmd.to_s, title: from, target: id, as: latest)
536
548
 
537
549
  registry = option('registry') || @registry
@@ -552,7 +564,9 @@ module Squared
552
564
  if op.empty?
553
565
  ps, status, no = filter_ps flag, from
554
566
  cmd << '--no-stream' if flag == :stats
555
- list_image(flag, ps, no: no, hint: status, from: from) { |img| run(cmd.temp(img), from: from) }
567
+ list_image(flag, ps, no: no, hint: status, multiple: flag != :attach, from: from) do |img|
568
+ run(cmd.temp(img), from: from)
569
+ end
556
570
  return
557
571
  end
558
572
  op.append(escape: true, strip: /^:/)
@@ -613,7 +627,7 @@ module Squared
613
627
  break
614
628
  end
615
629
  end
616
- raise_error ArgumentError, 'target not specified', hint: flag unless found
630
+ raise ArgumentError, message('target not specified', hint: flag) unless found
617
631
  when :pull
618
632
  if !id
619
633
  id = tagmain
@@ -629,7 +643,8 @@ module Squared
629
643
  id ||= option('tag', ignore: false) || op.shift || tagmain
630
644
  registry ||= option('registry') || op.shift || @registry
631
645
  emptyargs op, flag
632
- raise_error ArgumentError, 'username/registry not specified', hint: flag unless registry
646
+ raise ArgumentError, message('username/registry not specified', hint: flag) unless registry
647
+
633
648
  uri = shell_quote tagjoin(registry, id)
634
649
  op << uri
635
650
  img = docker_output 'image', 'tag', id, uri
@@ -732,7 +747,7 @@ module Squared
732
747
  target << basic_option('name', dnsname("#{name}_%s" % rand_s(6)))
733
748
  end
734
749
  when :exec
735
- raise_error ArgumentError, 'nothing to execute', hint: flag if list.empty?
750
+ raise ArgumentError, message('nothing to execute', hint: flag) if list.empty?
736
751
  end
737
752
  target << val << list.shift
738
753
  target << list.join(' && ') unless list.empty?
@@ -786,7 +801,7 @@ module Squared
786
801
  %w[running paused exited]
787
802
  when :unpause
788
803
  %w[paused]
789
- when :top, :stats, :watch
804
+ when :top, :stats, :watch, :attach
790
805
  %w[running]
791
806
  when :kill
792
807
  no = true
@@ -802,7 +817,8 @@ module Squared
802
817
  [cmd, status, no]
803
818
  end
804
819
 
805
- def list_image(flag, cmd = docker_output('image ls -a'), filter: nil, hint: nil, no: true, from: nil)
820
+ def list_image(flag, cmd = docker_output('image ls -a'), filter: nil, hint: nil, no: true, multiple: true,
821
+ from: nil)
806
822
  pwd_set(from: from) do
807
823
  index = 1
808
824
  all = option('all', prefix: 'docker')
@@ -813,8 +829,8 @@ module Squared
813
829
  elsif filter.match?(/[:_-]$/)
814
830
  /\b#{Regexp.escape(filter)}/
815
831
  else
816
- filter = filter.empty? ? '(?:[:_-]|$)' : "[:_-]#{filter}"
817
- /\b(?:#{dnsname(name)}|#{tagname(project)}|#{tagmain.split(':', 2).first})#{filter}/
832
+ filter = filter.empty? ? '([:_-]|$)' : "[:_-]#{filter}"
833
+ /\b(#{dnsname(name)}|#{tagname(project)}|#{tagmain.split(':', 2).first})#{filter}/
818
834
  end
819
835
  IO.popen(cmd.temp('--format=json')).each do |line|
820
836
  data = JSON.parse(line)
@@ -861,6 +877,7 @@ module Squared
861
877
  puts if printfirst?
862
878
  end
863
879
  yield id
880
+ break unless multiple
864
881
  end
865
882
  list_empty(hint: hint || from) if index == 1 && !y
866
883
  end
@@ -994,7 +1011,7 @@ module Squared
994
1011
  end
995
1012
 
996
1013
  def emptyargs(list, hint = nil)
997
- raise_error ArgumentError, "unrecognized args: #{list.join(', ')}", hint: hint unless list.empty?
1014
+ raise ArgumentError, message('unrecognized args', list.join(', '), hint: hint) unless list.empty?
998
1015
  end
999
1016
 
1000
1017
  def anypath?(*args)