squared 0.4.17 → 0.4.18

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.
@@ -94,7 +94,7 @@ module Squared
94
94
  PATH.freeze
95
95
  ARG.freeze
96
96
  VAR.each_value(&:freeze)
97
- VAR[:theme].each_value(&:freeze)
97
+ VAR[:theme].each_value { |val| val.freeze.each_value(&:freeze) }
98
98
  VAR.freeze
99
99
  end
100
100
 
@@ -141,11 +141,11 @@ module Squared
141
141
  def apply_style(data, key, args, empty: true)
142
142
  return if data.is_a?(::Symbol) && (data = __get__(:theme)[data]).nil?
143
143
 
144
- set = ->(k, v) { data[k] = check_style(v, empty: empty) }
144
+ set = ->(k, v) { data[k.to_sym] = check_style(v, empty: empty) }
145
145
  if key.is_a?(::Hash)
146
146
  key.each { |k, v| set.call(k, v || args) }
147
147
  else
148
- set.call(key.to_sym, args)
148
+ set.call(key, args)
149
149
  end
150
150
  end
151
151
 
@@ -194,7 +194,7 @@ module Squared
194
194
  end
195
195
  end
196
196
 
197
- def puts_oe(*args, pipe: 1)
197
+ def log_console(*args, pipe: 1)
198
198
  return if args.first == false && args.size == 1
199
199
 
200
200
  if pipe.is_a?(Pathname)
@@ -211,6 +211,8 @@ module Squared
211
211
  (pipe == 2 ? $stderr : $stdout).puts(*args)
212
212
  end
213
213
 
214
+ alias puts_oe log_console
215
+
214
216
  module_function
215
217
 
216
218
  def message(*args, hint: nil, empty: false, space: ARG[:SPACE])
@@ -42,7 +42,7 @@ module Squared
42
42
  list.each do |val|
43
43
  next if grep&.none? { |pat| pat.match?(line) }
44
44
 
45
- items << val.chomp
45
+ items << val.to_s.chomp
46
46
  puts "#{items.size.to_s.rjust(2)}. #{val}"
47
47
  end
48
48
  max = items.size
@@ -92,10 +92,16 @@ module Squared
92
92
  ret.join(join.is_a?(::String) ? join : ' ')
93
93
  end
94
94
 
95
- def fill_option(val, double: false)
95
+ def shell_bin(name, env: true)
96
+ key = name.upcase
97
+ shell_quote((env && ENV["PATH_#{key}"]) || PATH[key] || PATH[key.to_sym] || name,
98
+ option: false, force: false)
99
+ end
100
+
101
+ def fill_option(val, **kwargs)
96
102
  return "-#{val}" if val.match?(/\A(?:[a-z]\d*|\d)\z/i)
97
103
 
98
- shell_escape(val.start_with?('-') ? val : "--#{val}", double: double)
104
+ shell_escape(val.start_with?('-') ? val : "--#{val}", **kwargs)
99
105
  end
100
106
 
101
107
  def quote_option(flag, val, option: true, double: false, merge: false)
@@ -24,7 +24,7 @@ module Squared
24
24
  else
25
25
  return Kernel.send(name, *args, **kwargs)
26
26
  end
27
- return ret if ret || !e
27
+ return ret unless e && !ret && name == :system
28
28
 
29
29
  raise $?.to_s
30
30
  end
@@ -94,10 +94,10 @@ module Squared
94
94
  def build
95
95
  return unless enabled?
96
96
 
97
- namespace(ns = task_name(name)) do
97
+ namespace task_name(name) do |ns|
98
98
  @mime.each do |type, items|
99
99
  items.each do |command, file, opts|
100
- next if Rake::Task.task_defined?("#{ns}:#{command}:#{type}")
100
+ next if Rake::Task.task_defined?("#{ns.scope.path}:#{command}:#{type}")
101
101
 
102
102
  namespace command do
103
103
  unless (data = @@mime_obj[type])
@@ -196,7 +196,7 @@ module Squared
196
196
  private
197
197
 
198
198
  def puts(*args)
199
- puts_oe(*args, pipe: pipe)
199
+ log_console(*args, pipe: pipe)
200
200
  end
201
201
 
202
202
  def log
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.4.17'
4
+ VERSION = '0.4.18'
5
5
  end
@@ -95,9 +95,15 @@ module Squared
95
95
  @kind = Support.hashlist
96
96
  @extensions = []
97
97
  @envname = env_key(@main).freeze
98
- @pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
98
+ @pipe = $DEBUG ? 2 : env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
99
99
  @exception = env_bool exception
100
- @verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
100
+ @verbose = if $VERBOSE.nil?
101
+ false
102
+ elsif verbose.nil?
103
+ @pipe != 0
104
+ else
105
+ env_bool(verbose, verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
106
+ end
101
107
  @warning = @verbose != false
102
108
  @closed = false
103
109
  if common
@@ -423,7 +429,7 @@ module Squared
423
429
  ret << proj if proj
424
430
  end
425
431
  end
426
- return (group || ref ? ret : ret[0]) unless block_given?
432
+ return (group || ref ? ret : ret.first) unless block_given?
427
433
 
428
434
  ret.each(&blk)
429
435
  self
@@ -678,6 +684,10 @@ module Squared
678
684
  { exception: exception, warning: warning }
679
685
  end
680
686
 
687
+ def size
688
+ @project.size
689
+ end
690
+
681
691
  def to_s
682
692
  (home? ? home : root).to_s
683
693
  end
@@ -800,8 +810,8 @@ module Squared
800
810
  format_desc key
801
811
  task key do
802
812
  unless failed.empty? && group.empty?
803
- puts log_message(Logger::ERROR, *(failed + group.map { |val| val.action }.flatten),
804
- subject: 'failed placement', hint: false)
813
+ puts(log_message(Logger::ERROR, *(failed + group.map { |val| val.action }.flatten),
814
+ subject: 'failed placement', hint: false), pipe: 2)
805
815
  end
806
816
  cols = level.flatten(1).map(&:size).max
807
817
  level.each_with_index do |grp, n|
@@ -817,8 +827,8 @@ module Squared
817
827
  end
818
828
  end
819
829
 
820
- def puts(*args)
821
- puts_oe(*args, pipe: pipe)
830
+ def puts(*args, **kwargs)
831
+ log_console(*args, pipe: kwargs[:pipe] || pipe)
822
832
  end
823
833
 
824
834
  def script_command(task, val, group, ref, on, &blk)
@@ -21,7 +21,7 @@ module Squared
21
21
  VAR_SET = %i[parent global script index envname desc dependfile dependindex theme archive env dev prod graph
22
22
  pass only exclude].freeze
23
23
  BLK_SET = %i[run depend doc lint test copy clean].freeze
24
- SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?-?(\S+)?\b/.freeze
24
+ SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?[-.]?(\S+)?\b/.freeze
25
25
  URI_SCHEME = %r{\A([a-z][a-z\d+-.]*)://[^@:\[\]\\^<>|\s]}i.freeze
26
26
  TASK_METADATA = Rake::TaskManager.record_task_metadata
27
27
  private_constant :VAR_SET, :BLK_SET, :SEM_VER, :URI_SCHEME, :TASK_METADATA
@@ -313,7 +313,7 @@ module Squared
313
313
  flags.each do |flag|
314
314
  case action
315
315
  when 'graph'
316
- next unless graph?
316
+ break unless graph?
317
317
 
318
318
  format_desc action, flag, '(-)project*'
319
319
  task flag do |_, args|
@@ -455,13 +455,13 @@ module Squared
455
455
  if args.first.is_a?(Struct)
456
456
  f, blk = args.first.to_a
457
457
  args[0] = instance_eval(&blk) || f
458
- return unless args[0]
458
+ return unless args.first
459
459
  end
460
460
  if args.all? { |val| val.is_a?(Array) }
461
461
  cmd = []
462
462
  var = {}
463
463
  args.each do |val|
464
- next instance_exec(*val[1..-1], &val[0]) if val.first.is_a?(Proc)
464
+ next instance_exec(*val[1..-1], &val.first) if val.first.is_a?(Proc)
465
465
 
466
466
  a, b, c, d, e = val
467
467
  case b
@@ -948,7 +948,7 @@ module Squared
948
948
  def log
949
949
  return @log unless @log.is_a?(Array)
950
950
 
951
- @log = Logger.new(enabled? ? @log[0] : nil, **@log[1])
951
+ @log = Logger.new(enabled? ? @log.first : nil, **@log.last)
952
952
  end
953
953
 
954
954
  def allref
@@ -989,8 +989,8 @@ module Squared
989
989
 
990
990
  private
991
991
 
992
- def puts(*args)
993
- puts_oe(*args, pipe: pipe)
992
+ def puts(*args, **kwargs)
993
+ log_console(*args, pipe: kwargs[:pipe] || pipe)
994
994
  end
995
995
 
996
996
  def run(cmd = @session, var = nil, exception: self.exception, sync: true, from: nil, banner: true, chdir: path,
@@ -999,10 +999,8 @@ module Squared
999
999
  warn log_message(Logger::WARN, 'no command given', subject: project, hint: from || 'unknown', pass: true)
1000
1000
  return
1001
1001
  end
1002
- i = interactive && !(@session && option('y'))
1003
1002
  cmd = cmd.target if cmd.is_a?(OptionPartition)
1004
- cmd = session_done cmd
1005
- if i
1003
+ if interactive && (!@session || !option('y'))
1006
1004
  title, y = case interactive
1007
1005
  when Array
1008
1006
  interactive
@@ -1011,10 +1009,10 @@ module Squared
1011
1009
  else
1012
1010
  ['Run', 'Y']
1013
1011
  end
1014
- unless confirm("#{title}? [#{sub_style(cmd, styles: theme[:inline])}] #{y == 'Y' ? '[Y/n]' : '[y/N]'} ", y)
1015
- exit 1
1016
- end
1012
+ yn = y == 'Y' ? 'Y/n' : 'y/N'
1013
+ exit 1 unless confirm("#{title}? [#{sub_style(cmd.to_s, styles: theme[:inline])}] [#{yn}] ", y)
1017
1014
  end
1015
+ cmd = session_done cmd
1018
1016
  log&.info cmd
1019
1017
  on :first, from
1020
1018
  begin
@@ -1231,12 +1229,12 @@ module Squared
1231
1229
  end
1232
1230
 
1233
1231
  def session(*cmd, prefix: cmd.first, main: true, path: true, options: true)
1234
- prefix = stripext(prefix.to_s).upcase
1235
- if path && (val = ENV["PATH_#{prefix}"] || PATH[prefix] || PATH[prefix.to_sym])
1232
+ prefix = stripext prefix.to_s
1233
+ if path && (val = shell_bin(prefix))
1236
1234
  cmd[0] = shell_quote(val, force: false)
1237
1235
  end
1238
1236
  ret = JoinSet.new(cmd.flatten(1))
1239
- if options && (val = env("#{prefix}_OPTIONS"))
1237
+ if options && (val = env("#{prefix.upcase}_OPTIONS"))
1240
1238
  split_escape(val).each { |opt| ret.last(fill_option(opt), /\A(--?[^ =]+)[ =].+\z/m) }
1241
1239
  end
1242
1240
  main ? @session = ret : ret
@@ -1420,9 +1418,9 @@ module Squared
1420
1418
  unless items.empty?
1421
1419
  pad = items.size.to_s.size
1422
1420
  items.each_with_index do |val, i|
1423
- next unless matchany?(val[0], reg)
1421
+ next unless matchany?(val.first, reg)
1424
1422
 
1425
- out << "#{i.succ.to_s.rjust(pad)}. #{each ? each.call(val) : val[0]}"
1423
+ out << "#{i.succ.to_s.rjust(pad)}. #{each ? each.call(val) : val.first}"
1426
1424
  end
1427
1425
  end
1428
1426
  sub = [headerstyle]
@@ -1779,7 +1777,14 @@ module Squared
1779
1777
  return -1 if b.empty?
1780
1778
  return 1 if a.empty?
1781
1779
 
1782
- a, b = [a.first, b.first].map! { |c| [c[0], c[2], c[4] || '0', c[5] ? '-1' : '0'] }
1780
+ a, b = [a.first, b.first].map! do |c|
1781
+ begin
1782
+ d = Integer(c[5]).to_s
1783
+ rescue StandardError
1784
+ d = c[5] ? '-1' : '0'
1785
+ end
1786
+ [c[0], c[2], c[4] || '0', d]
1787
+ end
1783
1788
  a.each_with_index do |c, index|
1784
1789
  next if c == (d = b[index])
1785
1790
 
@@ -147,7 +147,7 @@ module Squared
147
147
  end
148
148
  end
149
149
  when 'bake'
150
- next unless bake?
150
+ break unless bake?
151
151
 
152
152
  case flag
153
153
  when :build
@@ -168,7 +168,7 @@ module Squared
168
168
  end
169
169
  end
170
170
  when 'compose'
171
- next unless compose?
171
+ break unless compose?
172
172
 
173
173
  case flag
174
174
  when :build, :up