wile 0.9.261203

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.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.version +1 -0
  3. data/CREDITS.md +20 -0
  4. data/README.md +253 -0
  5. data/bin/wile +102 -0
  6. data/cache/.bin/pane +99 -0
  7. data/cache/.bin/panes +54 -0
  8. data/cache/.config.fish +2 -0
  9. data/cache/.dictionary +0 -0
  10. data/cache/.gemignore +16 -0
  11. data/cache/.gitignore +9 -0
  12. data/cache/.greeting.erb +1 -0
  13. data/cache/.irbrc +30 -0
  14. data/cache/.lexicon +0 -0
  15. data/cache/.prompt.erb +1 -0
  16. data/cache/.reek-strict.yml +1 -0
  17. data/cache/.reek.yml +1 -0
  18. data/cache/.rubocop-strict.yml +4 -0
  19. data/cache/.rubocop.yml +4 -0
  20. data/cache/.ruby-version-floor +1 -0
  21. data/cache/.ruby-version.erb +1 -0
  22. data/cache/.solargraph.yml +21 -0
  23. data/cache/.title.erb +1 -0
  24. data/cache/.version +1 -0
  25. data/cache/.wile/example.rb +56 -0
  26. data/cache/.wileignore +3 -0
  27. data/cache/CREDITS.md +10 -0
  28. data/cache/Gemfile +5 -0
  29. data/cache/Gemfile.lock +1 -0
  30. data/cache/History.txt +0 -0
  31. data/cache/README.md.erb +54 -0
  32. data/cache/TODO.md +3 -0
  33. data/cache/bin/project.erb +12 -0
  34. data/cache/cucumber.yml +1 -0
  35. data/cache/examples/README.md +3 -0
  36. data/cache/features/help.feature.erb +30 -0
  37. data/cache/features/step_definitions/command_steps.rb +171 -0
  38. data/cache/features/support/env.rb +11 -0
  39. data/cache/features/version.feature.erb +19 -0
  40. data/cache/git/hooks/pre-commit +93 -0
  41. data/cache/lib/project.rb.erb +4 -0
  42. data/cache/man/project.md.erb +24 -0
  43. data/cache/pkg/README.md +3 -0
  44. data/cache/test/cons.gz +0 -0
  45. data/cache/test/tc_comments +216 -0
  46. data/cache/test/tc_cucumber_slow +67 -0
  47. data/cache/test/tc_dependency_scrapes +126 -0
  48. data/cache/test/tc_dictionary +51 -0
  49. data/cache/test/tc_encoding +53 -0
  50. data/cache/test/tc_lexicon +34 -0
  51. data/cache/test/tc_lib_tests +37 -0
  52. data/cache/test/tc_lints +71 -0
  53. data/cache/test/tc_readme_rocket_check +128 -0
  54. data/cache/test/tc_reek +20 -0
  55. data/cache/test/tc_rubocop +20 -0
  56. data/cache/test/tc_ruby_syntax +28 -0
  57. data/cache/test/tc_tags +32 -0
  58. data/cache/test/tc_tasks_test +31 -0
  59. data/cache/test/tc_version +97 -0
  60. data/cache/test/tc_weird_filenames +23 -0
  61. data/cache/test/test_helper.rb +230 -0
  62. data/cache/tmp/README.md +8 -0
  63. data/data/command_version.tsv +281 -0
  64. data/dependencies.txt +70 -0
  65. data/lib/wile/autoloads/cache.rb +123 -0
  66. data/lib/wile/autoloads/code_content.rb +225 -0
  67. data/lib/wile/autoloads/code_data.rb +153 -0
  68. data/lib/wile/autoloads/code_data_function.rb +79 -0
  69. data/lib/wile/autoloads/code_data_valuation.rb +60 -0
  70. data/lib/wile/autoloads/code_stats.rb +185 -0
  71. data/lib/wile/autoloads/command_version.rb +119 -0
  72. data/lib/wile/autoloads/content.rb +196 -0
  73. data/lib/wile/autoloads/dependencies.rb +170 -0
  74. data/lib/wile/autoloads/gem_utils.rb +69 -0
  75. data/lib/wile/autoloads/gemspec.rb +163 -0
  76. data/lib/wile/autoloads/git.rb +59 -0
  77. data/lib/wile/autoloads/info.rb +91 -0
  78. data/lib/wile/autoloads/manpage.rb +44 -0
  79. data/lib/wile/autoloads/methods.rb +130 -0
  80. data/lib/wile/autoloads/nvim_files.rb +54 -0
  81. data/lib/wile/autoloads/options_dictionary.rb +345 -0
  82. data/lib/wile/autoloads/order_optimizer.rb +185 -0
  83. data/lib/wile/autoloads/project.rb +60 -0
  84. data/lib/wile/autoloads/readme.rb +137 -0
  85. data/lib/wile/autoloads/receivers.rb +101 -0
  86. data/lib/wile/autoloads/responds.rb +36 -0
  87. data/lib/wile/autoloads/test.rb +78 -0
  88. data/lib/wile/autoloads/thread_pool.rb +64 -0
  89. data/lib/wile/help.rb +41 -0
  90. data/lib/wile/requires.rb +7 -0
  91. data/lib/wile/run.rb +108 -0
  92. data/lib/wile/sysexits.rb +43 -0
  93. data/lib/wile/tasks/build.rb +46 -0
  94. data/lib/wile/tasks/bump.rb +61 -0
  95. data/lib/wile/tasks/compare.rb +139 -0
  96. data/lib/wile/tasks/content.rb +44 -0
  97. data/lib/wile/tasks/cp.rb +52 -0
  98. data/lib/wile/tasks/dependencies.rb +58 -0
  99. data/lib/wile/tasks/dictionary.rb +59 -0
  100. data/lib/wile/tasks/gemcheck.rb +142 -0
  101. data/lib/wile/tasks/gemfile.rb +60 -0
  102. data/lib/wile/tasks/help.rb +29 -0
  103. data/lib/wile/tasks/info.rb +77 -0
  104. data/lib/wile/tasks/install.rb +53 -0
  105. data/lib/wile/tasks/lexicon.rb +59 -0
  106. data/lib/wile/tasks/list.rb +97 -0
  107. data/lib/wile/tasks/methods.rb +154 -0
  108. data/lib/wile/tasks/mkdir.rb +19 -0
  109. data/lib/wile/tasks/note.rb +49 -0
  110. data/lib/wile/tasks/nvim.rb +60 -0
  111. data/lib/wile/tasks/order.rb +93 -0
  112. data/lib/wile/tasks/oscheck.rb +49 -0
  113. data/lib/wile/tasks/publish.rb +67 -0
  114. data/lib/wile/tasks/receivers.rb +34 -0
  115. data/lib/wile/tasks/review.rb +157 -0
  116. data/lib/wile/tasks/ruby.rb +38 -0
  117. data/lib/wile/tasks/tc.rb +114 -0
  118. data/lib/wile/tasks/test.rb +57 -0
  119. data/lib/wile/tasks/todo.rb +55 -0
  120. data/lib/wile/tasks/update.rb +67 -0
  121. data/lib/wile/tasks.rb +34 -0
  122. data/lib/wile/usage.rb +56 -0
  123. data/lib/wile/usage_error.rb +18 -0
  124. data/lib/wile/utilities.rb +283 -0
  125. data/lib/wile/utilities_refinements.rb +41 -0
  126. data/lib/wile/wile_refinements.rb +137 -0
  127. data/lib/wile.rb +39 -0
  128. data/man/wile.1 +1121 -0
  129. data/man/wile.md +786 -0
  130. data/pkg/README.md +3 -0
  131. metadata +399 -0
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile test ##
4
+ # Options:
5
+ # --batch Run in non-interactive batch mode
6
+ # --list Lists tests that will run
7
+ # --quiet Fault-only
8
+ # Usage:
9
+ # wile test [<filematch> [<methodmatch>]] [--batch|--list|--quiet] # tc tests
10
+ module Wile
11
+ # This file is loaded upon a :test task request.
12
+ class Tasks
13
+ TEST_USAGE = [
14
+ 'Takes at most two arguments with optional batch/list/quiet flags.',
15
+ (..2), Set['batch', 'list', 'quiet']
16
+ ].freeze
17
+
18
+ def test(options)
19
+ Utilities.project_root? do |missing|
20
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
21
+ end
22
+ args = Usage.new(options, *TEST_USAGE).args
23
+ TestRunner.new(options, *args).run
24
+ end
25
+ end
26
+
27
+ # Runs project test suites and reports elapsed time.
28
+ # rubocop:disable-next Style/ClassAndModuleChildren
29
+ class Tasks::TestRunner
30
+ def initialize(options, filematch = nil, methodmatch = nil)
31
+ @options = options
32
+ @filematch = filematch
33
+ @methodmatch = methodmatch
34
+ end
35
+
36
+ def run
37
+ started = Time.now
38
+ execute
39
+ report(started) unless @options.list?
40
+ end
41
+
42
+ private
43
+
44
+ def report(started)
45
+ puts "Time: #{Time.now - started} seconds"
46
+ puts 'OK'.green
47
+ end
48
+
49
+ def execute
50
+ Test.test!(@filematch, @methodmatch,
51
+ batch: @options.batch?,
52
+ list: @options.list?,
53
+ quiet: @options.quiet?)
54
+ end
55
+ end
56
+ Tasks.private_constant :TestRunner
57
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `colora`
4
+
5
+ # ## wile todo ##
6
+ # Puts TODO.md's bullet lines.
7
+ # If match, greps matching ruby files for TODO's.
8
+ # Usage:
9
+ # wile todo [<match>+] # display TODO.md or scrape TODO comments
10
+ module Wile
11
+ # This file is loaded upon a :todo task request.
12
+ class Tasks
13
+ TODO_USAGE = ['Optionally takes one or more arguments.', Set[]].freeze
14
+
15
+ def todo(options)
16
+ Utilities.project_root? do |missing|
17
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
18
+ end
19
+ match = Usage.new(options, *TODO_USAGE).args
20
+ TodoLister.new(match).display
21
+ end
22
+ end
23
+
24
+ # Displays TODO.md or greps project Ruby files for TODO comments.
25
+ # rubocop:disable-next Style/ClassAndModuleChildren
26
+ class Tasks::TodoLister
27
+ using UtilitiesRefinements
28
+
29
+ def initialize(match = nil)
30
+ @match = match
31
+ end
32
+
33
+ def self.display_file(filename)
34
+ lines = File.foreach(filename).grep(/#\s*TODO/)
35
+ puts filename.blue, lines unless lines.empty?
36
+ end
37
+
38
+ def display
39
+ return system('colora', '--on=^#\\sTODO', '--off=^#', 'TODO.md') if
40
+ File.file?('TODO.md') && !@match
41
+
42
+ selected_files.each { self.class.display_file(it) }
43
+ end
44
+
45
+ private
46
+
47
+ def selected_files
48
+ files = Project.rbfiles.weird_filename!
49
+ return files.reject { it.start_with?('features/fixtures/') } unless @match
50
+
51
+ files.grep(Regexp.union(@match.map { Regexp.new(it) }))
52
+ end
53
+ end
54
+ Tasks.private_constant :TodoLister
55
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile update ##
4
+ # Will update README's version, copyright, and active console blocks.
5
+ # In ```console blocks, a first line matching:
6
+ # $ <project> [<args>] #>>
7
+ # runs ./bin/<project> [<args>] and inserts its output into the block.
8
+ # (Only when bin/<project> exists; only run on projects you trust.)
9
+ # Will also update gemspec and manpage.
10
+ # You can optionally specify which if not all.
11
+ # Git status must be clean, unless forced.
12
+ # Usage:
13
+ # wile update [README|gemspec|man] [--force] # update project files
14
+ module Wile
15
+ # This file is loaded upon a :update task request.
16
+ class Tasks
17
+ UPDATE_USAGE = ['May specify README, gemspec, or man.',
18
+ (..1), /^(README|gemspec|man)$/, Set['force']].freeze
19
+
20
+ def update(options, info = Info.info)
21
+ Utilities.project_root? do |missing|
22
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
23
+ end
24
+ target, = Usage.new(options, *UPDATE_USAGE).args
25
+ Git.clean! unless options.force?
26
+ Updater.new(info, target).update
27
+ end
28
+ end
29
+
30
+ # Updates README, gemspec, and manpage files and reports git diffs.
31
+ # rubocop:disable-next Style/ClassAndModuleChildren
32
+ class Tasks::Updater
33
+ UPDATERS = {
34
+ 'README' => Readme,
35
+ 'gemspec' => Gemspec,
36
+ 'man' => Manpage
37
+ }.freeze
38
+
39
+ def initialize(info = Info.info, target = nil)
40
+ @info = info
41
+ @target = target
42
+ end
43
+
44
+ def update
45
+ targets = Array(UPDATERS.fetch(@target) { UPDATERS.values })
46
+ targets.each { it.new(@info).update! }
47
+ report
48
+ end
49
+
50
+ private
51
+
52
+ def report
53
+ return puts 'up-to-date'.green if Git.clean?
54
+
55
+ paths = diff_targets
56
+ Git.diff(*paths) unless paths.empty?
57
+ puts 'verify updated changes'.red
58
+ end
59
+
60
+ def diff_targets
61
+ paths = { 'README' => @info.readme, 'gemspec' => @info.gemspec,
62
+ 'man' => 'man' }
63
+ Array(paths.fetch(@target) { paths.values }).select { File.exist?(it) }
64
+ end
65
+ end
66
+ Tasks.private_constant :Updater
67
+ end
data/lib/wile/tasks.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ # Tasks class manages the tasks available in the Wile framework.
6
+ class Tasks
7
+ using WileRefinements
8
+
9
+ def initialize
10
+ @tasks = (Dir.glob("#{CUSTOM}/*.rb") + Dir.glob("#{__dir__}/tasks/*.rb"))
11
+ .map { File.basename(it, '.rb').to_sym }.uniq
12
+ end
13
+
14
+ def find(string)
15
+ return nil if string.to_s.length < 2
16
+
17
+ start_with(string) || end_with(string) || includes(string)
18
+ end
19
+
20
+ private
21
+
22
+ def start_with(string)
23
+ @tasks.select { it.start_with? string }.unique
24
+ end
25
+
26
+ def end_with(string)
27
+ @tasks.select { it.end_with? string }.unique
28
+ end
29
+
30
+ def includes(string)
31
+ @tasks.select { it.to_s.include? string }.unique
32
+ end
33
+ end
34
+ end
data/lib/wile/usage.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ # Usage class validates the command-line arguments for a task.
6
+ # :reek:MissingSafeMethod
7
+ class Usage
8
+ attr_reader :args
9
+
10
+ def initialize(options, message, *validators)
11
+ keys = options.to_h.keys
12
+ @args = options.args
13
+ @opts = keys.grep(String).select { it.length > 1 } - %w[task args]
14
+ @task = options.task
15
+ @message = message
16
+ validate!(validators)
17
+ end
18
+
19
+ def error!(message = @message, task: @task)
20
+ raise UsageError, "#{task}: #{message}"
21
+ end
22
+
23
+ private
24
+
25
+ def validate!(validators)
26
+ validators.each do |validator|
27
+ error! unless validator_type_check(validator)
28
+ end
29
+ end
30
+
31
+ VALIDATORS = {
32
+ Range => :in_range?,
33
+ Regexp => :match?,
34
+ Integer => :size_of?,
35
+ Set => :allowed_opt?
36
+ }.freeze
37
+ private_constant :VALIDATORS
38
+
39
+ def validator_type_check(validator)
40
+ _, mth = VALIDATORS.detect { |type, _| validator.is_a? type }
41
+ raise ArgumentError, "invalid validator: #{validator.inspect}" unless mth
42
+
43
+ send(mth, validator)
44
+ end
45
+
46
+ def allowed_opt?(validator) = @opts.all? { validator.include?(it) }
47
+
48
+ def match?(validator) = !@args || @args.all? { validator.match?(it) }
49
+
50
+ def args_size = @args&.size.to_i
51
+
52
+ def in_range?(validator) = validator.include?(args_size)
53
+
54
+ def size_of?(validator) = validator == args_size
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ # UsageError is raised when the usage of a task is incorrect.
6
+ # It provides a message that includes the help information for the task.
7
+ class UsageError < RuntimeError
8
+ def initialize(msg = $ERROR_INFO&.message)
9
+ if msg
10
+ key, message = msg.split(':', 2).map(&:strip)
11
+ if message && (help = Help[key.to_sym])
12
+ msg = help + message
13
+ end
14
+ end
15
+ super
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,283 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `apt-get,dpkg-query,fish,rbenv,sudo,uname`
4
+
5
+ # Wile namespace.
6
+ module Wile
7
+ # Utility functions collected and harmonized from bin/bootstrap_* scripts.
8
+ # :reek:DataClump
9
+ # :reek:NilCheck
10
+ # :reek:TooManyStatements
11
+ # rubocop:disable-next Metrics/ModuleLength
12
+ module Utilities
13
+ using UtilitiesRefinements
14
+ include Sysexits
15
+
16
+ module_function
17
+
18
+ # --- Path & Executable Lookup ---
19
+ # category: lookup
20
+
21
+ def package_installed?(pkg)
22
+ `dpkg-query -W -f='${db:Status-Status}' #{pkg.sw} 2>/dev/null`
23
+ .strip == 'installed'
24
+ end
25
+
26
+ def missing_packages(packages)
27
+ packages.reject { package_installed?(it) }
28
+ end
29
+
30
+ def check_path_notice(dir)
31
+ return if paths.include?(dir)
32
+
33
+ warn "Notice: #{dir} is not currently in your PATH.".yellow
34
+ end
35
+
36
+ def paths
37
+ ENV.fetch('PATH', '').split(File::PATH_SEPARATOR)
38
+ end
39
+
40
+ def check_commands(commands)
41
+ commands.reject do |cmd|
42
+ path = which(cmd)
43
+ puts "#{cmd} found: #{path}".green if path
44
+ path
45
+ end
46
+ end
47
+
48
+ def which(cmd)
49
+ paths.each do |dir|
50
+ bin = File.join(dir, cmd)
51
+ return bin if File.file?(bin) && File.executable?(bin)
52
+ end
53
+ nil
54
+ end
55
+
56
+ def missing_commands(commands)
57
+ commands.reject { command_available?(it) }
58
+ end
59
+
60
+ def verify_utilities!(utilities)
61
+ missing = missing_commands(utilities)
62
+ return if missing.empty?
63
+
64
+ error!(EX_UNAVAILABLE,
65
+ 'Error: Required utilities not found in PATH: ' \
66
+ "#{missing.join(', ')}")
67
+ end
68
+
69
+ def command_available?(cmd)
70
+ !which(cmd).nil?
71
+ end
72
+
73
+ # --- User Prompts & Error Handling ---
74
+ # category: prompts
75
+
76
+ def confirm?(prompt)
77
+ print "#{prompt.yellow} [y/N]: "
78
+ $stdout.flush
79
+ reply = $stdin.gets
80
+ return false unless reply
81
+
82
+ /^[Yy]([Ee][Ss])?$/.match?(reply.strip)
83
+ end
84
+
85
+ def error!(val, msg)
86
+ warn msg.red
87
+ exit val
88
+ end
89
+
90
+ # --- Platform & Environment Checks ---
91
+ # category: environment
92
+
93
+ ROOT_FILES = %w[.version .ruby-version Gemfile].freeze
94
+
95
+ def verify_arch!(arch = 'x86_64')
96
+ detected = `uname -m`.strip
97
+ return if detected == arch
98
+
99
+ error!(EX_UNAVAILABLE,
100
+ "Error: #{arch} architecture required (detected: #{detected}).")
101
+ end
102
+
103
+ def verify_linux!
104
+ os = `uname -s`.strip
105
+ return if os == 'Linux'
106
+
107
+ error!(EX_UNAVAILABLE,
108
+ "Error: Wile is meant to be run on Linux (detected: #{os}).")
109
+ end
110
+
111
+ # :reek:BooleanParameter
112
+ # rubocop:disable-next Metrics/MethodLength
113
+ def verify_rbenv!(require_in_path: false, re_run: nil)
114
+ rbenv = File.expand_path('~/.rbenv/bin/rbenv')
115
+ ready = File.executable?(rbenv) &&
116
+ (!require_in_path || command_available?('rbenv'))
117
+ if ready
118
+ puts "rbenv found: #{`rbenv --version`.strip}".green if require_in_path
119
+ return
120
+ end
121
+
122
+ detail =
123
+ if require_in_path
124
+ 'not found or not initialized in PATH'
125
+ else
126
+ "not found at #{rbenv}"
127
+ end
128
+ re_run_hint = re_run ? ", then re-run:\n #{re_run}" : '.'
129
+ error!(EX_UNAVAILABLE, <<~MSG)
130
+ Error: rbenv #{detail}.
131
+ Run ./bin/bootstrap_ruby_rbenv first#{re_run_hint}
132
+ MSG
133
+ end
134
+
135
+ def verify_ruby_min_version!(min_version = '4.0', re_run: nil, note: nil)
136
+ if version_ok?(RUBY_VERSION, min_version)
137
+ puts "Ruby verified: #{RUBY_DESCRIPTION}".green
138
+ return
139
+ end
140
+
141
+ note = " by #{note}" if note
142
+ re_run_hint = re_run ? ", then re-run:\n #{re_run}" : '.'
143
+ msg = "Error: Ruby >= #{min_version} is required#{note} " \
144
+ "(found: #{RUBY_VERSION}).\n" \
145
+ "Run ./bin/bootstrap_ruby_rbenv first#{re_run_hint}\n"
146
+ error!(EX_UNAVAILABLE, msg)
147
+ end
148
+
149
+ def version_ok?(version, min_version)
150
+ # This is strictly greater than or equal, not a "twiddle-wakka".
151
+ Gem::Version.new(version) >= Gem::Version.new(min_version)
152
+ end
153
+
154
+ def verify_project_root!(root_files = ROOT_FILES)
155
+ project_root?(root_files) do |missing|
156
+ error!(EX_NOINPUT, "Error: #{missing.first} not found -- " \
157
+ "run this from a Wile project's root directory.")
158
+ end
159
+ end
160
+
161
+ def rbenv_root
162
+ `rbenv root 2>/dev/null`.strip
163
+ end
164
+
165
+ # rubocop:disable-next Metrics/MethodLength
166
+ def verify_ruby_project_version!(version_file = '.ruby-version',
167
+ re_run: nil)
168
+ expected = File.read(version_file).strip
169
+ expected_prefix = "#{rbenv_root}/versions/#{expected}/"
170
+ ruby_path = RbConfig.ruby
171
+
172
+ if expected == RUBY_VERSION && ruby_path.start_with?(expected_prefix)
173
+ puts "Ruby verified: #{RUBY_DESCRIPTION} (#{ruby_path})".green
174
+ return
175
+ end
176
+
177
+ re_run_hint = re_run ? ", then re-run:\n #{re_run}" : '.'
178
+ error!(EX_CONFIG, <<~MSG)
179
+ Error: Expected rbenv Ruby #{expected} (from #{version_file}),
180
+ but current ruby is #{RUBY_VERSION} at #{ruby_path}.
181
+
182
+ Ensure ./bin/bootstrap_ruby_rbenv has been run and rbenv shims
183
+ are active in your shell#{re_run_hint}
184
+ MSG
185
+ end
186
+
187
+ def project_root?(root_files = ROOT_FILES)
188
+ missing = missing_root_files(root_files)
189
+ return true if missing.empty?
190
+
191
+ yield missing if block_given?
192
+ false
193
+ end
194
+
195
+ def missing_root_files(root_files = ROOT_FILES)
196
+ root_files.reject { File.file?(it) }
197
+ end
198
+
199
+ # --- Version Probing ---
200
+ # category: probing
201
+
202
+ def fish_version
203
+ return nil unless command_available?('fish')
204
+
205
+ `fish --version 2>/dev/null`[/\d+\.\d+/]
206
+ end
207
+
208
+ def fisher_version
209
+ return nil unless command_available?('fish')
210
+
211
+ `fish -c 'fisher --version' 2>/dev/null`[/\d+\.\d+/]
212
+ end
213
+
214
+ def gem_installed?(gem_name, version: nil, env: {})
215
+ args = ['gem', 'list', '-i', "^#{Regexp.escape(gem_name)}$"]
216
+ args.push('-v', version) if version
217
+ system(env, *args, out: File::NULL, err: File::NULL) # permit
218
+ end
219
+
220
+ # --- Subprocess Execution ---
221
+ # category: execution
222
+
223
+ def run_fish!(cmd)
224
+ return if system('fish', '-c', cmd, in: File::NULL)
225
+
226
+ error!(EX_OSERR, "Error: `fish -c '#{cmd}'` failed.")
227
+ end
228
+
229
+ # :reek:BooleanParameter
230
+ # :reek:ControlParameter
231
+ # :reek:LongParameterList
232
+ # rubocop:disable-next Metrics/ParameterLists
233
+ def run!(*cmd, sysexit: nil, msg: nil, stderr: true, echo: false, env: {})
234
+ run(*cmd, stderr:, echo:, env:) do |inferred, default_msg|
235
+ error!(sysexit || inferred, msg || default_msg)
236
+ end
237
+ end
238
+
239
+ def apt_install!(packages)
240
+ system('sudo', 'apt-get', 'update') ||
241
+ error!(EX_OSERR, 'Error: apt-get update failed.')
242
+ system('sudo', 'apt-get', 'install', '-y', *packages) ||
243
+ error!(EX_OSERR, "Error: apt-get install #{packages.join(' ')} failed.")
244
+ end
245
+
246
+ def infer_sysexit(cmd, res)
247
+ if res.nil?
248
+ exe = cmd.first.to_s.split.first.to_s
249
+ present = File.exist?(exe) || command_available?(exe)
250
+ return present ? EX_NOPERM : EX_UNAVAILABLE
251
+ end
252
+ { 127 => EX_UNAVAILABLE, 126 => EX_NOPERM }
253
+ .fetch($CHILD_STATUS&.exitstatus, EX_OSERR)
254
+ end
255
+
256
+ # :reek:BooleanParameter
257
+ # :reek:ControlParameter
258
+ # :reek:LongParameterList
259
+ # rubocop:disable-next Naming/PredicateMethod
260
+ def run(*cmd, stderr: true, echo: false, env: {})
261
+ warn format_cmd(cmd, env).gray if echo
262
+ opts = stderr ? {} : { err: File::NULL }
263
+ return true if (res = system(env, *cmd, **opts)) # permit
264
+
265
+ if block_given?
266
+ sysexit = infer_sysexit(cmd, res)
267
+ yield sysexit, default_run_msg(cmd, env, sysexit)
268
+ end
269
+ false
270
+ end
271
+
272
+ def format_cmd(cmd, env)
273
+ prefix = env.map { |key, val| "#{key}=#{val.sw} " }.join
274
+ "#{prefix}#{cmd.join(' ')}"
275
+ end
276
+
277
+ def default_run_msg(cmd, env, sysexit)
278
+ code = $CHILD_STATUS&.exitstatus
279
+ info = code ? "exit #{code}" : "sysexit #{sysexit}"
280
+ "Error: '#{format_cmd(cmd, env)}' failed (#{info})."
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ # Refinements for Utilities.
6
+ module UtilitiesRefinements
7
+ ALLOWED = /\A[a-zA-Z0-9._][a-zA-Z0-9._-]*\z/
8
+
9
+ # category: array
10
+
11
+ refine Array do
12
+ # Returns self, the array.
13
+ def weird_filename!
14
+ each(&:weird_filename!)
15
+ end
16
+ end
17
+
18
+ # category: object
19
+
20
+ refine Object do
21
+ def weird_filename!
22
+ raise "Expected a String filename, got #{self.class} instead"
23
+ end
24
+ end
25
+
26
+ # category: string
27
+
28
+ refine String do
29
+ def sw
30
+ Shellwords.escape(self)
31
+ end
32
+
33
+ def weird_filename!
34
+ parts = valid_encoding? ? split('/').reject(&:empty?) : []
35
+ return self if parts.any? && parts.all? { ALLOWED.match?(it) }
36
+
37
+ raise "Weird filename: #{self}"
38
+ end
39
+ end
40
+ end
41
+ end