squared 0.7.10 → 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.
@@ -36,9 +36,9 @@ module Squared
36
36
  root-user-action=b t|target=p upgrade-strategy=b].freeze,
37
37
  install_a: %w[no-index pre prefer-binary all-releases=b extra-index-url=q f|find-links=q i|index-url=q
38
38
  no-binary=q only-binary=q only-final=b].freeze,
39
- install_b: %w[check-build-dependencies no-build-isolation no-clean no-deps require-hashes use-pep517
40
- build-constraint=p c|constraint=p group=q progress-bar=b r|requirement=p
41
- requirements-from-script=p src=p].freeze,
39
+ install_b: %w[build-constraint check-build-dependencies no-build-isolation no-clean no-deps require-hashes
40
+ use-pep517 c|constraint=p group=q progress-bar=b r|requirement=p requirements-from-script=p
41
+ src=p].freeze,
42
42
  install_c: %w[C|config-settings=q e|editable=v].freeze,
43
43
  install_d: %w[ignore-requires-python uploaded-prior-to=q].freeze,
44
44
  hash: %w[a|algorithm].freeze,
@@ -105,7 +105,7 @@ module Squared
105
105
  end
106
106
 
107
107
  def bannerargs
108
- %i[version dependfile venv].freeze
108
+ %i[version dependfile venv editable].freeze
109
109
  end
110
110
 
111
111
  def venv?
@@ -181,8 +181,8 @@ module Squared
181
181
  format_desc action, nil, "script+|#{indexchar}index+|#,pattern*"
182
182
  task action, [:command] do |_, args|
183
183
  found = 0
184
- %w[tool.poetry tool.pdm project].each_with_index do |table, i|
185
- next if (list = read_pyproject("#{table}.scripts")).empty?
184
+ %w[tool.poetry.scripts tool.pdm.scripts project.scripts].each_with_index do |table, i|
185
+ next if (list = read_pyproject(table)).empty?
186
186
 
187
187
  if args.command == '#'
188
188
  format_list(list, "run[#{indexchar}N]", 'scripts', grep: args.extras, from: pyprojectfile)
@@ -208,7 +208,7 @@ module Squared
208
208
  log.warn "run script #{n} of #{list.size}".subhint('out of range')
209
209
  end
210
210
  else
211
- case (i > 1 && poetry? ? 0 : i)
211
+ case i
212
212
  when 0
213
213
  found |= 1
214
214
  run(session_output('poetry', 'run', val), from: :run)
@@ -216,7 +216,7 @@ module Squared
216
216
  found |= 1
217
217
  run(pdm_session('run', val), from: :run)
218
218
  else
219
- raise "script: #{val}" if exception?
219
+ raise message('script', val) if exception?
220
220
 
221
221
  found |= 2
222
222
  log.warn "run script \"#{val}\"".subhint('not indexed')
@@ -265,10 +265,10 @@ module Squared
265
265
 
266
266
  format_desc action, flag, 'c/reate?,d/epend?,opts*'
267
267
  task flag do |_, args|
268
- args = args.to_a
269
- rm_rf(venv, verbose: true)
270
- venv_init if has_value!(args, 'c', 'create')
271
- depend :force, args if has_value!(args, 'd', 'depend')
268
+ opts = args.to_a
269
+ rm_rf(venv, verbose: !silent?)
270
+ venv_init if has_value!(opts, 'c', 'create')
271
+ depend :force, opts if has_value!(opts, 'd', 'depend')
272
272
  end
273
273
  when :exec
274
274
  format_desc action, flag, 'command,args*'
@@ -297,7 +297,7 @@ module Squared
297
297
  install flag, ['upgrade', *args.to_a, 'pip']
298
298
  end
299
299
  when :freeze
300
- format_desc action, flag, "file?=#{DEP_PYTHON[4]},u/ninstall?,opts*"
300
+ format_desc action, flag, "file?=#{DEP_PYTHON[4]},u/uninstall,opts*"
301
301
  task flag do |_, args|
302
302
  opts = args.to_a
303
303
  if has_value!(opts, 'u', 'uninstall')
@@ -312,7 +312,7 @@ module Squared
312
312
  end
313
313
  file = pip(flag, opts: opts, banner: requirement.nil?, requirement: requirement)
314
314
  puts File.read(file) unless silent?
315
- if requirement && confirm_basic('Uninstall?', file, prefix: 'pip')
315
+ if requirement && confirm_basic('Uninstall?', file)
316
316
  pip(:uninstall, opts: ['y', "r=#{shell_quote(file)}"])
317
317
  end
318
318
  end
@@ -391,7 +391,7 @@ module Squared
391
391
  else 'outdir?,srcdir?'
392
392
  end)
393
393
  task flag do |_, args|
394
- build! flag, args.to_a
394
+ build_ flag, args.to_a
395
395
  end
396
396
  break if be
397
397
  when 'publish'
@@ -438,9 +438,9 @@ module Squared
438
438
  if flag
439
439
  cmd << case flag
440
440
  when :requirement, :target
441
- quote_option(flag, basepath(target))
441
+ quote_option flag, basepath(target)
442
442
  else
443
- shell_option(flag)
443
+ shell_option flag
444
444
  end
445
445
  op = append_pip flag, opts, pipopts(:install)
446
446
  op.clear
@@ -482,7 +482,7 @@ module Squared
482
482
  :patch
483
483
  end
484
484
  end
485
- '--not-required' if option('not-required', notequals: '0')
485
+ '--not-required' if option('not-required', notequals: '0') && !env('PYTHON_DEFAULT')
486
486
  end
487
487
  cmd << '--local' if option('l', 'local')
488
488
  append_global
@@ -607,22 +607,23 @@ module Squared
607
607
  project: self, strict: strict?, single: singleopt(flag))
608
608
  else
609
609
  op = append_pip(flag, opts, pipopts(:install), target: pip_session('install'))
610
- case flag
611
- when :editable
612
- op << quote_option('e', op.pop || editable || '.')
613
- op.clear
614
- when :user, :upgrade
615
- op.concat(packages)
616
- raise_error ArgumentError, 'no packages listed', hint: flag if op.empty?
617
- op << "--#{flag}"
618
- op.append
619
- python_session('-m pip', *op.to_a.drop(1)) if workspace.windows?
620
- end
610
+ end
611
+ case flag
612
+ when :editable
613
+ op << quote_option('e', op.pop || editable || '.')
614
+ op.clear
615
+ when :user, :upgrade
616
+ op.concat(packages)
617
+ raise ArgumentError, message('no packages listed', hint: flag) if op.empty?
618
+
619
+ op << "--#{flag}"
620
+ op.append
621
+ python_session('-m pip', *op.to_a.drop(1)) if workspace.windows?
621
622
  end
622
623
  run(banner: banner, from: :install)
623
624
  end
624
625
 
625
- def build!(flag, opts = [], outdir: nil, srcdir: nil)
626
+ def build_(flag, opts = [], outdir: nil, srcdir: nil)
626
627
  list = case flag
627
628
  when :poetry
628
629
  cmd = poetry_session 'build'
@@ -685,7 +686,6 @@ module Squared
685
686
  run(from: from)
686
687
  end
687
688
  end
688
- alias build_ build!
689
689
 
690
690
  def publish(flag, opts = [], test: false)
691
691
  list = case flag
@@ -706,12 +706,9 @@ module Squared
706
706
  dist = lambda do
707
707
  dir = basepath 'dist'
708
708
  return dir if dir.directory? && !dir.empty?
709
+ raise message('no source to publish', hint: dir) if dir.exist?
709
710
 
710
- if dir.exist?
711
- raise_error 'no source to publish', hint: dir
712
- else
713
- raise_error Errno::ENOENT, dir, hint: 'publish'
714
- end
711
+ raise Errno::ENOENT, message(dir, hint: 'publish')
715
712
  end
716
713
  if test
717
714
  if op.arg?('r', flag == :hatch ? 'repo' : 'repository')
@@ -772,7 +769,7 @@ module Squared
772
769
  when :install, :uninstall
773
770
  op << '.' if installable? && !op.arg?('r', 'requirement')
774
771
  else
775
- raise_error ArgumentError, 'no packages listed', hint: flag
772
+ raise ArgumentError, message('no packages listed', hint: flag)
776
773
  end
777
774
  elsif flag == :install
778
775
  op.append_any
@@ -795,27 +792,32 @@ module Squared
795
792
  .clear
796
793
  when :cache
797
794
  op.concat(args)
798
- raise_error 'no subcommand', hint: flag if op.empty?
795
+ raise message('no subcommand', hint: flag) if op.empty?
796
+
799
797
  op << (action = op.shift)
800
798
  case action
801
- when 'dir', 'info', 'purge' then nil
799
+ when 'dir', 'info', 'purge'
800
+ nil
802
801
  when 'list', 'remove'
803
802
  op.add_first(quote: true)
804
803
  else
805
- raise_error ArgumentError, "unrecognized args: #{action}", hint: flag
804
+ raise ArgumentError, message('unrecognized args', action, hint: flag)
806
805
  end
807
806
  op.clear
808
807
  when :config
809
808
  op.concat(args)
810
- raise_error 'no subcommand', hint: flag if op.empty?
811
- op << (action = op.shift)
809
+ raise message('no subcommand', hint: flag) if op.empty?
810
+
811
+ action = op.shift
812
+ op << action
812
813
  case action
813
- when 'list', 'edit', 'debug' then nil
814
+ when 'list', 'edit', 'debug'
815
+ nil
814
816
  when 'get', 'unset', 'set'
815
817
  op.add_first
816
818
  op.add_first(quote: true, expect: true) if action == 'set'
817
819
  else
818
- raise_error ArgumentError, "unrecognized args: #{action}", hint: flag
820
+ raise ArgumentError, message('unrecognized args', action, hint: flag)
819
821
  end
820
822
  op.clear
821
823
  when :hash
@@ -852,7 +854,7 @@ module Squared
852
854
  def variable_set(key, *args, **, &blk)
853
855
  if block_given?
854
856
  case key
855
- when :dependfile, :editable, :venv
857
+ when :dependfile, :venv
856
858
  args = block_args args, &blk
857
859
  end
858
860
  end
@@ -869,8 +871,6 @@ module Squared
869
871
  log.warn "variable_set: @dependfile=#{val}".subhint('not supported')
870
872
  end
871
873
  end
872
- when :editable
873
- editable_set args.first
874
874
  when :venv
875
875
  @venv = (basepath(*args) unless args.empty? || args.first.nil?)
876
876
  else
@@ -1024,7 +1024,7 @@ module Squared
1024
1024
 
1025
1025
  if found
1026
1026
  line.chomp!($1) if line =~ /(?<=[\d"'{}\[\]]|true|false)(\s*#.*)$/
1027
- break if line.match?(/^\s*\[(?:[\w.\-"' ]+|".+"|'.+')\]\s*$/)
1027
+ break if line.match?(/^\s*\[([\w.\-"' ]+|".+"|'.+')\]\s*$/)
1028
1028
 
1029
1029
  if ch
1030
1030
  val = line.rstrip
@@ -1089,7 +1089,8 @@ module Squared
1089
1089
  /\A(?:v+|q+|b+|V+|O+)\z/
1090
1090
  when :pdm, :poetry
1091
1091
  /\Av+\z/
1092
- when :twine, :meson then nil
1092
+ when :twine, :meson
1093
+ nil
1093
1094
  else
1094
1095
  /\A(?:v+|q+)\z/
1095
1096
  end
@@ -1127,7 +1128,7 @@ module Squared
1127
1128
  end
1128
1129
 
1129
1130
  def variables
1130
- (super + %i[venv editable]).freeze
1131
+ (super + %i[venv]).freeze
1131
1132
  end
1132
1133
 
1133
1134
  def runenv
@@ -382,7 +382,7 @@ module Squared
382
382
  if val.include?('*')
383
383
  out.concat(Dir.glob(val, base: path))
384
384
  elsif !(file = basepath!(val))
385
- print_error(val, hint: 'not found')
385
+ print_error('file not found', hint: val)
386
386
  elsif file.directory?
387
387
  out.concat(file.glob('**/*.rb'))
388
388
  else
@@ -438,17 +438,18 @@ module Squared
438
438
  when 'gem'
439
439
  case flag
440
440
  when :outdated
441
- format_desc action, flag, "semver?=major|minor|patch,#{shortname('i', 's', 'u', 'd')},opts*"
441
+ format_desc action, flag, "semver?=(=)major|minor|patch,#{shortname('i', 's', 'u', 'd')},opts*"
442
442
  task flag, [:semver] do |_, args|
443
- opts = case (semver = args.semver)
444
- when 'major', 'minor', 'patch'
443
+ opts = if args.semver =~ /^(=)?(major|minor|patch)$/i
444
+ equals = !$1.nil?
445
+ semver = $2.downcase
445
446
  args.extras
446
447
  else
447
- semver = nil
448
448
  args.to_a
449
449
  end
450
450
  gem(flag, opts: opts, banner: true, filter: {
451
451
  semver: semver,
452
+ equals: equals,
452
453
  update: has_value!(opts, 'u', 'update'),
453
454
  interactive: has_value!(opts, 'i', 'interactive'),
454
455
  select: has_value!(opts, 's', 'select'),
@@ -506,22 +507,16 @@ module Squared
506
507
  format_desc action, flag, 'f/orce?,l/ocal?,opts*'
507
508
  task flag do |_, args|
508
509
  opts = args.to_a
509
- opts << 'local' if has_value!(opts, 'l', 'local')
510
+ opts << 'local' if has_value!(opts, 'l')
510
511
  opts << 'redownload' if has_value!(opts, 'f', 'force')
511
512
  if (lock = basepath!('Gemfile.lock'))
512
- case (val = ENV['BUNDLE_FROZEN'])
513
- when '0', 'false' then nil
514
- else
515
- if val
516
- print_error("BUNDLE_FROZEN: #{val}", loglevel: Logger::INFO, subject: name, hint: flag)
513
+ config = basepath '.bundle', 'config'
514
+ if config.exist? && config.read.match?(/\bBUNDLE_FROZEN:\s+"true"/)
515
+ if opts.include?('redownload')
516
+ run(bundle_output('config unset frozen'), banner: false)
517
+ else
518
+ print_error('Gemfile.lock is frozen', subject: name, hint: flag)
517
519
  lock = nil
518
- elsif basepath!('.bundle', 'config')&.read&.match?(/\bBUNDLE_FROZEN:\s+"true"/)
519
- if opts.include?('redownload')
520
- run(bundle_output('config unset frozen'), banner: false)
521
- else
522
- print_error('Gemfile.lock is frozen', subject: name, hint: flag)
523
- lock = nil
524
- end
525
520
  end
526
521
  end
527
522
  lock&.delete
@@ -568,7 +563,7 @@ module Squared
568
563
  else
569
564
  %w[## ;]
570
565
  end
571
- msg = if Readline.respond_to?(:readmultiline)
566
+ msg = if Prompt.reline.respond_to?(:readmultiline)
572
567
  'ruby>'
573
568
  else
574
569
  multiline = Array(multiline)
@@ -697,9 +692,9 @@ module Squared
697
692
  .lines
698
693
  .map { |line| line.sub(/#.*$/, '').strip }
699
694
  .reject(&:empty?)
700
- .yield_self do |data|
701
- target = data.find { |line| line.include?(tool) }
702
- target ? [target] : data
695
+ .yield_self do |lines|
696
+ target = lines.find { |line| line.include?(tool) }
697
+ target ? [target] : lines
703
698
  end
704
699
  .join(', ')
705
700
  end
@@ -733,7 +728,7 @@ module Squared
733
728
  out.map!(&:split)
734
729
  pad = as_a(out, :first, :size).max
735
730
  print_item
736
- puts(out.map { |line| '%*s %s' % [pad, line.first, line[1..-1].join(' ')] })
731
+ puts(out.map { |line| '%*s %s' % [pad, line.first, line.drop(1).join(' ')] })
737
732
  end
738
733
  end
739
734
  when :reshim
@@ -781,7 +776,8 @@ module Squared
781
776
  next if val == '0' || val == 'false'
782
777
 
783
778
  run(bundle_output('binstubs --all', case val
784
- when '1', 'true' then nil
779
+ when '1', 'true'
780
+ nil
785
781
  else
786
782
  if val.start_with?('~')
787
783
  val = File.join(Dir.home, val == '~' ? '.bundle' : val[1..-1])
@@ -1072,7 +1068,7 @@ module Squared
1072
1068
  buffer = []
1073
1069
  filter = kwargs.fetch(:filter, {})
1074
1070
  semver = filter[:semver]
1075
- dryrun = filter[:dryrun] || dryrun?(prefix: 'gem')
1071
+ equals = filter[:equals]
1076
1072
  update = if sync && filter[:select]
1077
1073
  semver ||= 'major'
1078
1074
  items = []
@@ -1149,6 +1145,8 @@ module Squared
1149
1145
  when 2
1150
1146
  case semver
1151
1147
  when 'major', 'minor'
1148
+ next if equals && semver == 'major'
1149
+
1152
1150
  update&.push(a)
1153
1151
  when 'patch'
1154
1152
  next
@@ -1162,6 +1160,8 @@ module Squared
1162
1160
  else
1163
1161
  case semver
1164
1162
  when 'major', 'minor', 'patch'
1163
+ next if equals && semver != 'patch'
1164
+
1165
1165
  update&.push(a)
1166
1166
  end
1167
1167
  unless stdin?
@@ -1225,7 +1225,7 @@ module Squared
1225
1225
  'user-install'
1226
1226
  end
1227
1227
  end
1228
- if dryrun
1228
+ if filter[:dryrun]
1229
1229
  print_run gem_output('update -f', *update.quote!(escape: true)), false
1230
1230
  else
1231
1231
  gem(:update, *update, opts: opts)
@@ -1260,26 +1260,36 @@ module Squared
1260
1260
  case flag
1261
1261
  when :build
1262
1262
  if op.empty?
1263
- raise_error Errno::ENOENT, 'gemspec', hint: project unless gemfile
1263
+ raise Errno::ENOENT, message('gemspec', hint: project) unless gemfile
1264
+
1264
1265
  op.add_path(gemfile)
1265
1266
  else
1266
- op.add_first(path: true)
1267
+ op.add_first(path: !op.first.include?('*'), quote: true)
1267
1268
  .clear(pass: false)
1268
1269
  end
1269
1270
  when :push
1270
- if op.empty? || ia
1271
- file = basepath(if !ia && (spec = gemspec)
1271
+ target = gemname
1272
+ if op.empty? || (n = op.index(':'))
1273
+ file = basepath(if !n && (spec = gemspec)
1272
1274
  "#{spec.name}-#{spec.version}.gem"
1273
1275
  else
1274
1276
  choice_index 'Select a file', Dir.glob('*.gem', base: path)
1275
1277
  end)
1278
+ op.add_path(file)
1279
+ elsif (file = op.shift).include?('*')
1280
+ file = '*.gem' if file == '*'
1281
+ target = Dir.glob(file, base: path).join(', ')
1282
+ raise Errno::ENOENT, message(file, hint: flag) if target.empty?
1283
+
1284
+ op.add_quote(file)
1276
1285
  else
1277
- file = basepath(op.shift.yield_self { |val| val.include?('.') ? val : "#{val}.gem" })
1278
- raise_error Errno::ENOENT, file, hint: flag unless file.exist?
1279
- raise_error ArgumentError, "unrecognized args: #{op.join(', ')}", hint: flag unless op.empty?
1286
+ file = basepath(file.include?('.') ? file : "#{file}.gem")
1287
+ raise Errno::ENOENT, message(file, hint: flag) unless file.exist?
1288
+ raise ArgumentError, message('unrecognized args', op.join(', '), hint: flag) unless op.empty?
1289
+
1290
+ op.add_path(file)
1280
1291
  end
1281
- op.add_path(file)
1282
- return run(from: from, interactive: ['Push', 'N', gemname]) unless with || !banner
1292
+ return run(from: from, interactive: ['Push', 'N', target]) unless with || !banner
1283
1293
  when :exec
1284
1294
  min = if op.arg?('g', 'gem')
1285
1295
  1
@@ -1335,7 +1345,8 @@ module Squared
1335
1345
  op.unshift(name)
1336
1346
  end
1337
1347
  end
1338
- raise_error ArgumentError, 'missing gem name', hint: flag if op.empty?
1348
+ raise ArgumentError, message('missing gem name', hint: flag) if op.empty?
1349
+
1339
1350
  if op.arg?('all')
1340
1351
  if flag == :pristine
1341
1352
  append_repeat 'skip', op.extras
@@ -1375,7 +1386,7 @@ module Squared
1375
1386
  op << action
1376
1387
  op.clear
1377
1388
  else
1378
- raise_error ArgumentError, "unrecognized arg: #{action}", hint: flag
1389
+ raise ArgumentError, message('unrecognized command', action, hint: flag)
1379
1390
  end
1380
1391
  end
1381
1392
  when :open, :owner, :unpack, :yank
@@ -1412,7 +1423,7 @@ module Squared
1412
1423
  end
1413
1424
  end
1414
1425
  opts = session_opts(with, args: args, kwargs: kwargs, pass: pass)
1415
- invalid = ->(a) { raise_error ArgumentError, "unrecognized args: #{a.join(', ')}", hint: flag }
1426
+ invalid = ->(a) { raise ArgumentError, message('unrecognized args', a.join(', '), hint: flag) }
1416
1427
  cmd = bundle_session flag
1417
1428
  case flag
1418
1429
  when :cache, :check, :clean, :init, :install, :lock, :pack, :package, :platform
@@ -1737,7 +1748,7 @@ module Squared
1737
1748
  def project
1738
1749
  return @project unless @project.frozen?
1739
1750
 
1740
- @project = ((spec = gemspec) ? spec.name : @project).dup
1751
+ @project = (gemspec&.name || @project).dup
1741
1752
  end
1742
1753
 
1743
1754
  def depend?
@@ -1832,8 +1843,8 @@ module Squared
1832
1843
  private
1833
1844
 
1834
1845
  def run_repl(*args, opts:, banner:, from:, delim: true, **kwargs)
1835
- op = OptionPartition.new(opts, OPT_RUBY[from], session(*bundle_args(from)),
1836
- project: self, strict: strict?, first: [/\.rb$/])
1846
+ op = OptionPartition.new(opts, OPT_RUBY[from], session(*bundle_args(from)), project: self, strict: strict?,
1847
+ first: [/\.rb$/])
1837
1848
  r = []
1838
1849
  r << 'bundler/setup' if !op.arg?('r') && bundle_load
1839
1850
  r.concat(Array(kwargs[:name])) if kwargs[:name]
@@ -1921,7 +1932,8 @@ module Squared
1921
1932
  val = case (val = $2)
1922
1933
  when 'true'
1923
1934
  true
1924
- when '', '[]' then nil
1935
+ when '', '[]'
1936
+ nil
1925
1937
  else
1926
1938
  if val =~ /\A\[:(.+)\]\z/
1927
1939
  $1.split(', :').map { |s| (s[/\A"(.+)"\z/, 1] || s).to_sym }
@@ -1953,10 +1965,6 @@ module Squared
1953
1965
  verbose? ? ['--verbose'] : []
1954
1966
  end
1955
1967
 
1956
- def variables
1957
- (super + %i[autodetect]).freeze
1958
- end
1959
-
1960
1968
  def rakefile
1961
1969
  if @rakefile.nil?
1962
1970
  file = Rake::Application::DEFAULT_RAKEFILES.find { |val| exist?(val) }
@@ -125,8 +125,8 @@ module Squared
125
125
  extras.concat(if n == 0
126
126
  data
127
127
  else
128
- super(data[0, n])
129
- data[n..-1]
128
+ super(data.take(n))
129
+ data.drop(n)
130
130
  end)
131
131
  self
132
132
  else
@@ -20,8 +20,8 @@ module Squared
20
20
  include Shell
21
21
  include Prompt
22
22
 
23
- def append(target, *args, delim: false, escape: false, quote: true, strip: nil, force: true, double: false,
24
- filter: nil, pass: nil, preserve: true, **)
23
+ def append(target, *args, delim: false, escape: false, quote: true, strip: nil, double: false, filter: nil,
24
+ pass: nil, **kwargs)
25
25
  return if (ret = args.flatten(1)).empty?
26
26
 
27
27
  target << '--' if delim && !target.include?('--')
@@ -52,7 +52,7 @@ module Squared
52
52
  if !(pa = val.is_a?(Pathname)) && escape
53
53
  shell_escape(val, quote: quote, double: double)
54
54
  elsif quote || pa
55
- shell_quote(val, force: force, double: double, preserve: preserve)
55
+ shell_quote(val, double: double, **kwargs)
56
56
  else
57
57
  val
58
58
  end
@@ -135,7 +135,7 @@ module Squared
135
135
  [name, $3, $2 || (name.size == 1 && $1.empty? ? true : '')]
136
136
  end
137
137
 
138
- def arg?(target, *args, value: false, **)
138
+ def arg?(target, *args, value: false)
139
139
  r, s = args.partition { |val| val.is_a?(Regexp) }
140
140
  r << matchopts(s, value) unless s.empty?
141
141
  a = target.to_a
@@ -315,7 +315,7 @@ module Squared
315
315
  end
316
316
  numtype = [
317
317
  [i, /\A\d+\z/],
318
- [f, /\A\d*(?:\.\d+)?\z/],
318
+ [f, /\A\d*(\.\d+)?\z/],
319
319
  [si, /\A-?\d+\z/]
320
320
  ].freeze
321
321
  numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && v.match?(pat) } }
@@ -609,7 +609,7 @@ module Squared
609
609
  val = OptionPartition.send(:matchopts, val) unless val.is_a?(Regexp)
610
610
  blk = proc { |s| s&.match?(val) }
611
611
  else
612
- raise TypeError, "unknown: #{val}"
612
+ raise TypeError, Common::Format.message('unknown', val, hint: target.first)
613
613
  end
614
614
  end
615
615
  ret = find_all(&blk)
@@ -658,10 +658,7 @@ module Squared
658
658
 
659
659
  def readline(msg, fallback = nil, option: nil, quote: false, force: true, double: false)
660
660
  begin
661
- require 'readline' unless defined?(Readline)
662
- ret = Readline.readline("#{msg}#{force ? ':' : '?'} ", false).strip
663
- rescue LoadError
664
- raise unless (ret = fallback) || !force
661
+ ret = Common::Prompt.reline.readline("#{msg}#{force ? ':' : '?'} ", false).strip
665
662
  rescue Interrupt
666
663
  exit(force ? 1 : 0)
667
664
  else
@@ -7,6 +7,15 @@ module Squared
7
7
  module Utils
8
8
  private
9
9
 
10
+ def symjoin(*args, char: ':')
11
+ args.flatten.join(char).to_sym
12
+ end
13
+
14
+ def collect_hash(data, pass: [])
15
+ data = data.reject { |key,| pass.include?(key) } unless pass.empty?
16
+ data.values.flatten
17
+ end
18
+
10
19
  def rand_s(size)
11
20
  require 'random/formatter'
12
21
  Random.new.alphanumeric(size)
@@ -26,29 +35,13 @@ module Squared
26
35
  end
27
36
  end
28
37
 
29
- def matchmap(list, prefix = nil, negate: false)
30
- ret = negate ? [[], []] : []
31
- list.each do |val|
32
- unless val.is_a?(Regexp)
33
- val = val.dup
34
- n = 1 if negate && val.delete_prefix!('!')
35
- if prefix
36
- a = nil
37
- val.sub!(/\A(\^|\\A)/) do |s|
38
- a = s
39
- nil
40
- end
41
- val = ".*#{val}" unless a
42
- end
43
- end
44
- pat = Regexp.new("#{a}#{prefix}#{val == '*' ? '.+' : val}")
45
- if negate
46
- ret[n || 0] << pat
47
- else
48
- ret << pat
49
- end
38
+ def matchmap(list, prefix: nil)
39
+ list.map do |val|
40
+ next val if val.is_a?(Regexp)
41
+
42
+ val = ".*#{val}" if prefix && !val.sub!(/\A(\^|\\A)/, '')
43
+ Regexp.new("#{prefix}#{val == '*' ? '.+' : val}")
50
44
  end
51
- ret
52
45
  end
53
46
 
54
47
  def matchany?(list, *args, empty: true)