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
data/lib/wile/run.rb ADDED
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ using WileRefinements
6
+
7
+ PASCAL_KEY = ->(str) { str.pascal_case.to_sym }
8
+
9
+ def self.autoloads
10
+ Dir.glob("#{__dir__}/autoloads/*.rb")
11
+ .map { File.basename(it, '.rb') }
12
+ .each { autoload PASCAL_KEY[it], File.join(__dir__, "autoloads/#{it}") }
13
+ end
14
+
15
+ # The Run class is responsible for executing the Wile application.
16
+ # :reek:UncommunicativeVariableName e is standard
17
+ class Run
18
+ include Sysexits
19
+
20
+ def self.load_task(task)
21
+ if File.file?("#{CUSTOM}/#{task}.rb")
22
+ require File.expand_path("#{CUSTOM}/#{task}.rb")
23
+ else
24
+ require_relative "tasks/#{task}"
25
+ end
26
+ end
27
+
28
+ def initialize(options)
29
+ @options = options
30
+ @error = nil
31
+ require_relative 'requires'
32
+ Wile.autoloads
33
+ @tasks = Wile::Tasks.new
34
+ run
35
+ rescue StandardError, ScriptError => e
36
+ @error = e
37
+ handle_error
38
+ end
39
+
40
+ private
41
+
42
+ def run
43
+ return dispatch_no_task unless (name = @options.task)
44
+
45
+ @options.to_h.store('task', task = @tasks.find(name))
46
+ # The 'list:' prefix tells UsageError to prepend Help[:list] usage.
47
+ raise UsageError, "list: No tasks matched '#{name}'" unless task
48
+
49
+ Run.load_task(task)
50
+ @tasks.method(task).call(@options)
51
+ end
52
+
53
+ def dispatch_no_task
54
+ options_empty? ? man : OptionsDictionary.new(@options)
55
+ end
56
+
57
+ def options_empty?
58
+ keys = @options.to_h.keys
59
+ (keys.grep(String) - %w[task args]).empty?
60
+ end
61
+
62
+ def man
63
+ path = File.join(Wile::ROOT, 'man/wile.1')
64
+ if $stdout.tty? && File.file?(path)
65
+ exec('man', '-l', path)
66
+ else
67
+ path = File.join(Wile::ROOT, 'man/wile.md')
68
+ puts File.read(path) if File.exist?(path)
69
+ end
70
+ end
71
+
72
+ def handle_error
73
+ case @error
74
+ when Errno::EPIPE
75
+ # Downstream reader closed output pipe early, e.g. piping to head.
76
+ exit EX_OK
77
+ when UsageError
78
+ handle_usage_error
79
+ when RuntimeError
80
+ handle_runtime_error
81
+ else
82
+ handle_software_error
83
+ end
84
+ end
85
+
86
+ def handle_runtime_error
87
+ code, msg = Sysexits.code_msg(@error.message)
88
+ warn msg.red unless msg.empty?
89
+ exit code
90
+ end
91
+
92
+ def handle_usage_error
93
+ msg = @error.message
94
+ lines = msg.lines.map(&:chomp)
95
+ lines = lines[...-1].map(&:blue) << lines[-1]&.red
96
+ warn lines.compact.join("\n")
97
+ exit EX_USAGE
98
+ end
99
+
100
+ def handle_software_error
101
+ if (backtrace = @error.backtrace)
102
+ warn backtrace[0..3].reverse.join("\n").blue
103
+ end
104
+ warn @error.message.red
105
+ exit EX_SOFTWARE
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wile namespace.
4
+ module Wile
5
+ # BSD sysexits(3) exit status codes.
6
+ # :reek:TooManyConstants
7
+ module Sysexits
8
+ EX_OK = 0 # success
9
+ EX_FAIL = 1 # test|task failed
10
+ EX_NO = 2 # request was rejected|declined
11
+ EX_STOP = 2 # requests a stop
12
+ EX_USAGE = 64 # command used incorrectly
13
+ EX_DATAERR = 65 # input data incorrect
14
+ EX_NOINPUT = 66 # input file missing or unreadable
15
+ EX_NOUSER = 67 # reserved: user unknown
16
+ EX_NOHOST = 68 # reserved: host unknown
17
+ EX_UNAVAILABLE = 69 # required command, gem, or service unavailable
18
+ EX_SOFTWARE = 70 # internal software error
19
+ EX_OSERR = 71 # system call or subprocess error
20
+ EX_OSFILE = 72 # system or template file missing|corrupt
21
+ EX_CANTCREAT = 73 # output file cannot be created
22
+ EX_IOERR = 74 # input|output error
23
+ EX_TEMPFAIL = 75 # temporary failure; retry may succeed
24
+ EX_PROTOCOL = 76 # remote protocol error
25
+ EX_NOPERM = 77 # permission denied
26
+ EX_CONFIG = 78 # configuration or project state error
27
+
28
+ EX_CODES = constants.to_h do |const|
29
+ [const.to_s.delete_prefix('EX_'), const_get(const)]
30
+ end.freeze
31
+
32
+ def self.code_msg(message)
33
+ text = message.to_s
34
+ label, msg = text.split(':', 2)
35
+ code = msg && EX_CODES[label]
36
+ code ? [code, msg.lstrip] : [EX_FAIL, text]
37
+ end
38
+
39
+ def self.label(code)
40
+ EX_CODES.key(code) || 'FAIL'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile build ##
4
+ # Builds the gem pkg.
5
+ # Will refuse(unless forced) if git status is not clean.
6
+ # Usage:
7
+ # wile build [--force] # build gem pkg
8
+ module Wile
9
+ # This file is loaded upon a :build task request.
10
+ class Tasks
11
+ BUILD_USAGE = ['Takes no arguments with optional force flag.',
12
+ 0, Set['force']].freeze
13
+
14
+ def build(options, gmu = GemUtils.new, git = Git)
15
+ Utilities.project_root? do |missing|
16
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
17
+ end
18
+ Usage.new(options, *BUILD_USAGE)
19
+ Builder.new(options, gmu, git).build
20
+ end
21
+ end
22
+
23
+ # Verifies project state and builds the gem package.
24
+ # rubocop:disable-next Style/ClassAndModuleChildren
25
+ class Tasks::Builder
26
+ def initialize(options, gmu = GemUtils.new, git = Git)
27
+ @options = options
28
+ @gmu = gmu
29
+ @git = git
30
+ end
31
+
32
+ def build
33
+ verify unless @options.force?
34
+ @gmu.build!
35
+ end
36
+
37
+ private
38
+
39
+ def verify
40
+ @git.clean!
41
+ @gmu.clean!
42
+ @gmu.ready!
43
+ end
44
+ end
45
+ Tasks.private_constant :Builder
46
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile bump ##
4
+ # Bumps the project version (major, minor, or date-stamped build) across
5
+ # .version, lib/<project>.rb, README.md, and <project>.gemspec.
6
+ # Usage:
7
+ # wile bump [major|minor|build] # bump the version number
8
+ module Wile
9
+ # This file is loaded upon a :bump task request.
10
+ class Tasks
11
+ BUMP_USAGE = ['Optionally takes one argument (major|minor|build).',
12
+ (..1), /^(major|minor|build)$/, Set[]].freeze
13
+
14
+ def bump(options, info = Info.info)
15
+ Utilities.project_root? do |missing|
16
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
17
+ end
18
+ type, = Usage.new(options, *BUMP_USAGE).args
19
+ Bumper.new(info, type).bump
20
+ end
21
+ end
22
+
23
+ # Computes and writes bumped project versions.
24
+ # rubocop:disable-next Style/ClassAndModuleChildren
25
+ class Tasks::Bumper
26
+ using WileRefinements
27
+
28
+ BUMPS = {
29
+ 'major' => ->(maj, _min) { [maj + 1, 0] },
30
+ 'minor' => ->(maj, min) { [maj, min + 1] }
31
+ }.freeze
32
+ private_constant :BUMPS
33
+
34
+ def initialize(info = Info.info, type = nil)
35
+ @info = info
36
+ @type = type
37
+ end
38
+
39
+ def self.bumped(version, type = nil, now = Time.now)
40
+ major, minor, = version.split('.').map(&:to_i)
41
+ major, minor = BUMPS[type].call(major, minor) if BUMPS.key?(type)
42
+ "#{major}.#{minor}.#{now.strftime('%y%m%d')}"
43
+ end
44
+
45
+ def bump
46
+ write_version(self.class.bumped(@info.version, @type, @info.now))
47
+ end
48
+
49
+ private
50
+
51
+ def write_version(version)
52
+ dir = @info.dirname
53
+ File.write(File.join(dir, '.version'), "#{version}\n")
54
+ [@info.project_rb, @info.readme, @info.gemspec].each do |file|
55
+ path = File.join(dir, file)
56
+ File.sub!(path, /\d+\.\d+\.\d+/, version) if File.exist?(path)
57
+ end
58
+ end
59
+ end
60
+ Tasks.private_constant :Bumper
61
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `diff`
4
+
5
+ # ## wile compare ##
6
+ # Compares project files with template.
7
+ # Usage:
8
+ # wile compare [<match>+] # compares project with template
9
+ module Wile
10
+ # This file is loaded upon a :compare task request.
11
+ class Tasks
12
+ COMPARE_USAGE = [
13
+ 'Optionally takes one or more file matchers.', Set[]
14
+ ].freeze
15
+
16
+ def compare(options)
17
+ Utilities.project_root? do |missing|
18
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
19
+ end
20
+ match = Usage.new(options, *COMPARE_USAGE).args
21
+ Comparer.new(match).run
22
+ end
23
+ end
24
+
25
+ # Compares project files against the Wile template cache.
26
+ # rubocop:disable-next Style/ClassAndModuleChildren
27
+ class Tasks::Comparer
28
+ using WileRefinements
29
+ using UtilitiesRefinements
30
+
31
+ # Files expected to be customized by the user (shown in blue when modified).
32
+ # Other modified files are shown in red as candidates to keep updated with
33
+ # the Wile template. Discrepancies are informational, not errors; it is up
34
+ # to the user to decide what to update, so the exit status remains zero.
35
+ EXPECTED_CHANGES = [
36
+ /README\.md/,
37
+ /^(\.ruby-version|\.version|\.irbrc|\.config\.fish)/,
38
+ %r{^(lib/|bin/|\.bin/|\.git/|man/|#{Regexp.escape(CUSTOM)}/)},
39
+ /^(Gemfile|TODO\.md|CREDITS\.md|History\.txt)/,
40
+ /^(\.gemignore|\.gitignore|\.wileignore)/,
41
+ /^(\.dictionary|\.lexicon)/,
42
+ /^(\.rubocop.*\.yml|\.reek.*\.yml|cucumber\.yml)/,
43
+ %r{^features/(support/env|step_definitions/command_steps)\.rb$}
44
+ ].freeze
45
+ private_constant :EXPECTED_CHANGES
46
+
47
+ def initialize(match = nil, info = Info.info)
48
+ @match = match
49
+ @info = info
50
+ @opt, @out = diff_flags
51
+ end
52
+
53
+ def self.missing_files(keys, found)
54
+ (keys - found).reject { it.start_with?("#{CUSTOM}/") }
55
+ end
56
+
57
+ def run
58
+ p2c, missing = p2c_and_missing
59
+ p2c.keys.weird_filename!
60
+ display_missing(missing) unless missing.empty?
61
+ display_found(filter_p2c(p2c))
62
+ end
63
+
64
+ private
65
+
66
+ def p2c_and_missing
67
+ p2c, pfiles = Cache.new.as { [it.p2c_hash, it.pfiles] }
68
+ found = (keys = p2c.keys) & pfiles
69
+ [p2c.slice(*found), self.class.missing_files(keys, found)]
70
+ end
71
+
72
+ def diff_flags
73
+ return ['-sq', '>/dev/null'] unless @match
74
+
75
+ color = String.disable_colorization ? '' : '--color=always'
76
+ [color, '']
77
+ end
78
+
79
+ def display_missing(missing)
80
+ puts '# Missing:'.red
81
+ missing.display
82
+ puts
83
+ end
84
+
85
+ def filter_p2c(p2c)
86
+ raise 'No files found.' if p2c.empty?
87
+
88
+ @match ? select_matches(p2c) : p2c
89
+ end
90
+
91
+ def display_found(p2c)
92
+ puts '# Found:'.blue
93
+ p2c.each { |pfile, cfile| display_entry(pfile, cfile) }
94
+ end
95
+
96
+ def match?(pfile)
97
+ @match.any? { pfile.match?(it) }
98
+ end
99
+
100
+ def select_matches(p2c)
101
+ matched = p2c.select { |pfile, _| match?(pfile) }
102
+ raise "No match: #{@match.join(', ')}" if matched.empty?
103
+
104
+ matched
105
+ end
106
+
107
+ def display_entry(pfile, cfile)
108
+ output = diff(File.join(@info.cache, cfile), pfile)
109
+ colorized_puts(pfile)
110
+ puts " |#{output.lines.join(' |')}" unless output.empty?
111
+ end
112
+
113
+ def colorized_puts(pfile)
114
+ if $CHILD_STATUS.exitstatus.zero?
115
+ puts "✓ #{pfile}".green # UTF-8
116
+ elsif EXPECTED_CHANGES.any? { it.match?(pfile) }
117
+ puts "Δ #{pfile}".blue # UTF-8
118
+ else
119
+ puts "✗ #{pfile}".red # UTF-8
120
+ end
121
+ end
122
+
123
+ def diff(cfile, pfile)
124
+ return diff_erb(cfile, pfile) if cfile.end_with?('.erb')
125
+
126
+ `diff #{@opt} #{cfile.sw} #{pfile.sw} #{@out}`
127
+ end
128
+
129
+ def diff_erb(erb_file, pfile)
130
+ result = @info.erb_result(erb_file)
131
+ IO.popen("diff #{@opt} - #{pfile.sw} #{@out}", 'w+') do |pipe|
132
+ pipe.puts result
133
+ pipe.close_write
134
+ pipe.read
135
+ end
136
+ end
137
+ end
138
+ Tasks.private_constant :Comparer
139
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile content ##
4
+ # Options:
5
+ # --dump dumps SEXP
6
+ # --raw simple output
7
+ # Usage:
8
+ # wile content <filename>+ [--dump] [--raw] # show file's contents
9
+ module Wile
10
+ # This file is loaded upon a :content task request.
11
+ class Tasks
12
+ CONTENT_USAGE = ['Takes one or more filenames.',
13
+ %r{^[-\w./]+$}, (1..), Set['dump', 'raw']].freeze
14
+
15
+ def content(options)
16
+ usage = Usage.new(options, *CONTENT_USAGE)
17
+ files = content_files(usage, options)
18
+ return content_dump(files) if options.dump?
19
+ raise 'STOP: unresolved calls' if Content.new(files, options).red?
20
+ end
21
+
22
+ private
23
+
24
+ def content_files(usage, options)
25
+ usage.error!('Cannot combine --dump and --raw.') if
26
+ options.dump? && options.raw?
27
+ files = usage.args.select do |filename|
28
+ File.file?(filename) || warn("File not found: #{filename}".red)
29
+ end
30
+ raise 'No files selected.' if files.empty?
31
+
32
+ files
33
+ end
34
+
35
+ # category: dump
36
+
37
+ def content_dump(filenames)
38
+ filenames.each do |filename|
39
+ warn "#{'#'.gray} #{filename.blue.bold}"
40
+ puts CodeContent.ast(filename)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile cp ##
4
+ # Copies template files from cache/ into the current project.
5
+ # The force option will overwrite existing files; trace prints skipped files.
6
+ # Usage:
7
+ # wile cp [<match>] [--force] [--trace] # copy template files into project
8
+ module Wile
9
+ # This file is loaded upon a :cp task request.
10
+ class Tasks
11
+ CP_USAGE = [
12
+ 'Optionally takes one argument and flags: force, trace.',
13
+ (0..1),
14
+ Set['force', 'trace']
15
+ ].freeze
16
+
17
+ def cp(options, cache = nil)
18
+ Utilities.project_root? do |missing|
19
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
20
+ end
21
+ match = Usage.new(options, *CP_USAGE).args&.first
22
+ cache ||= Cache.new(trace: options.trace?)
23
+ Copier.new(cache, match, options).copy
24
+ end
25
+ end
26
+
27
+ # Copies matching template files from cache into the project.
28
+ # rubocop:disable-next Style/ClassAndModuleChildren
29
+ class Tasks::Copier
30
+ def initialize(cache, match, options)
31
+ @cache = cache
32
+ @match = match
33
+ @options = options
34
+ end
35
+
36
+ def copy
37
+ p2c = filtered_p2c
38
+ raise 'no matches found' if p2c.empty?
39
+
40
+ force = @options.force?
41
+ p2c.each { |pfile, cfile| @cache.copy2project(cfile, pfile, force:) }
42
+ end
43
+
44
+ private
45
+
46
+ def filtered_p2c
47
+ p2c = @cache.p2c_hash
48
+ @match ? p2c.select { |pfile, _| pfile.match?(@match) } : p2c
49
+ end
50
+ end
51
+ Tasks.private_constant :Copier
52
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile dependencies ##
4
+ # List ruby and system dependencies.
5
+ # Usage:
6
+ # wile dependencies # list ruby dependencies
7
+ module Wile
8
+ # This file is loaded upon a :dependencies task request.
9
+ class Tasks
10
+ DEPENDENCIES_USAGE = ['Takes no arguments.', 0, Set[]].freeze
11
+
12
+ def dependencies(options, dpc = Dependencies.new)
13
+ Utilities.project_root? do |missing|
14
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
15
+ end
16
+ Usage.new(options, *DEPENDENCIES_USAGE)
17
+ DependencyReport.new(dpc).display
18
+ end
19
+ end
20
+
21
+ # Formats and prints runtime, development, and OS dependency sections.
22
+ # rubocop:disable-next Style/ClassAndModuleChildren
23
+ class Tasks::DependencyReport
24
+ def initialize(dpc = Dependencies.new)
25
+ @dpc = dpc
26
+ end
27
+
28
+ def self.display_entry(info)
29
+ if (name = info.name)
30
+ puts "#{name.ljust(12)} #{info.version || info.type}"
31
+ else
32
+ warn "Missing: #{info.require}".red
33
+ end
34
+ end
35
+
36
+ def display
37
+ sections.each { |title, list| display_section(title, list) }
38
+ end
39
+
40
+ private
41
+
42
+ def display_section(title, list)
43
+ puts title.blue
44
+ list.sort.each { self.class.display_entry(it) }
45
+ end
46
+
47
+ def sections
48
+ run, dev, ros, dos = @dpc.dependencies
49
+ {
50
+ '## runtime ##' => @dpc.geminfo(run),
51
+ '## development ##' => @dpc.geminfo(dev),
52
+ '## system-run ##' => @dpc.osinfo(ros),
53
+ '## system-dev ##' => @dpc.osinfo(dos)
54
+ }
55
+ end
56
+ end
57
+ Tasks.private_constant :DependencyReport
58
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `diff`
4
+
5
+ # ## wile dictionary ##
6
+ # Usage:
7
+ # wile dictionary [--check] [--yes] # view changes and update dictionary
8
+ module Wile
9
+ # This file is loaded upon a :dictionary task request.
10
+ class Tasks
11
+ DICTIONARY_USAGE = ['Takes no arguments.',
12
+ 0, Set['check', 'yes']].freeze
13
+
14
+ def dictionary(options)
15
+ Utilities.project_root? do |missing|
16
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
17
+ end
18
+ Usage.new(options, *DICTIONARY_USAGE)
19
+ DictionaryUpdater.new(options).run
20
+ end
21
+ end
22
+
23
+ # Checks and updates the project .dictionary file.
24
+ # rubocop:disable-next Style/ClassAndModuleChildren
25
+ class Tasks::DictionaryUpdater
26
+ def initialize(options)
27
+ @options = options
28
+ end
29
+
30
+ def run
31
+ return puts 'OK'.green if ok?
32
+
33
+ raise 'Fail'
34
+ end
35
+
36
+ def self.diff
37
+ opts = String.disable_colorization ? [] : ['--color']
38
+ system('diff', *opts, '.dictionary', 'tmp/.dictionary')
39
+ end
40
+
41
+ private
42
+
43
+ def ok?
44
+ return true if system 'test/tc_dictionary --verbose=silent'
45
+
46
+ self.class.diff
47
+ return false unless update?
48
+
49
+ FileUtils.cp 'tmp/.dictionary', '.dictionary'
50
+ true
51
+ end
52
+
53
+ def update?
54
+ !@options.check? &&
55
+ (@options.yes? || Utilities.confirm?('Update dictionary?'))
56
+ end
57
+ end
58
+ Tasks.private_constant :DictionaryUpdater
59
+ end