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.
- checksums.yaml +7 -0
- data/.version +1 -0
- data/CREDITS.md +20 -0
- data/README.md +253 -0
- data/bin/wile +102 -0
- data/cache/.bin/pane +99 -0
- data/cache/.bin/panes +54 -0
- data/cache/.config.fish +2 -0
- data/cache/.dictionary +0 -0
- data/cache/.gemignore +16 -0
- data/cache/.gitignore +9 -0
- data/cache/.greeting.erb +1 -0
- data/cache/.irbrc +30 -0
- data/cache/.lexicon +0 -0
- data/cache/.prompt.erb +1 -0
- data/cache/.reek-strict.yml +1 -0
- data/cache/.reek.yml +1 -0
- data/cache/.rubocop-strict.yml +4 -0
- data/cache/.rubocop.yml +4 -0
- data/cache/.ruby-version-floor +1 -0
- data/cache/.ruby-version.erb +1 -0
- data/cache/.solargraph.yml +21 -0
- data/cache/.title.erb +1 -0
- data/cache/.version +1 -0
- data/cache/.wile/example.rb +56 -0
- data/cache/.wileignore +3 -0
- data/cache/CREDITS.md +10 -0
- data/cache/Gemfile +5 -0
- data/cache/Gemfile.lock +1 -0
- data/cache/History.txt +0 -0
- data/cache/README.md.erb +54 -0
- data/cache/TODO.md +3 -0
- data/cache/bin/project.erb +12 -0
- data/cache/cucumber.yml +1 -0
- data/cache/examples/README.md +3 -0
- data/cache/features/help.feature.erb +30 -0
- data/cache/features/step_definitions/command_steps.rb +171 -0
- data/cache/features/support/env.rb +11 -0
- data/cache/features/version.feature.erb +19 -0
- data/cache/git/hooks/pre-commit +93 -0
- data/cache/lib/project.rb.erb +4 -0
- data/cache/man/project.md.erb +24 -0
- data/cache/pkg/README.md +3 -0
- data/cache/test/cons.gz +0 -0
- data/cache/test/tc_comments +216 -0
- data/cache/test/tc_cucumber_slow +67 -0
- data/cache/test/tc_dependency_scrapes +126 -0
- data/cache/test/tc_dictionary +51 -0
- data/cache/test/tc_encoding +53 -0
- data/cache/test/tc_lexicon +34 -0
- data/cache/test/tc_lib_tests +37 -0
- data/cache/test/tc_lints +71 -0
- data/cache/test/tc_readme_rocket_check +128 -0
- data/cache/test/tc_reek +20 -0
- data/cache/test/tc_rubocop +20 -0
- data/cache/test/tc_ruby_syntax +28 -0
- data/cache/test/tc_tags +32 -0
- data/cache/test/tc_tasks_test +31 -0
- data/cache/test/tc_version +97 -0
- data/cache/test/tc_weird_filenames +23 -0
- data/cache/test/test_helper.rb +230 -0
- data/cache/tmp/README.md +8 -0
- data/data/command_version.tsv +281 -0
- data/dependencies.txt +70 -0
- data/lib/wile/autoloads/cache.rb +123 -0
- data/lib/wile/autoloads/code_content.rb +225 -0
- data/lib/wile/autoloads/code_data.rb +153 -0
- data/lib/wile/autoloads/code_data_function.rb +79 -0
- data/lib/wile/autoloads/code_data_valuation.rb +60 -0
- data/lib/wile/autoloads/code_stats.rb +185 -0
- data/lib/wile/autoloads/command_version.rb +119 -0
- data/lib/wile/autoloads/content.rb +196 -0
- data/lib/wile/autoloads/dependencies.rb +170 -0
- data/lib/wile/autoloads/gem_utils.rb +69 -0
- data/lib/wile/autoloads/gemspec.rb +163 -0
- data/lib/wile/autoloads/git.rb +59 -0
- data/lib/wile/autoloads/info.rb +91 -0
- data/lib/wile/autoloads/manpage.rb +44 -0
- data/lib/wile/autoloads/methods.rb +130 -0
- data/lib/wile/autoloads/nvim_files.rb +54 -0
- data/lib/wile/autoloads/options_dictionary.rb +345 -0
- data/lib/wile/autoloads/order_optimizer.rb +185 -0
- data/lib/wile/autoloads/project.rb +60 -0
- data/lib/wile/autoloads/readme.rb +137 -0
- data/lib/wile/autoloads/receivers.rb +101 -0
- data/lib/wile/autoloads/responds.rb +36 -0
- data/lib/wile/autoloads/test.rb +78 -0
- data/lib/wile/autoloads/thread_pool.rb +64 -0
- data/lib/wile/help.rb +41 -0
- data/lib/wile/requires.rb +7 -0
- data/lib/wile/run.rb +108 -0
- data/lib/wile/sysexits.rb +43 -0
- data/lib/wile/tasks/build.rb +46 -0
- data/lib/wile/tasks/bump.rb +61 -0
- data/lib/wile/tasks/compare.rb +139 -0
- data/lib/wile/tasks/content.rb +44 -0
- data/lib/wile/tasks/cp.rb +52 -0
- data/lib/wile/tasks/dependencies.rb +58 -0
- data/lib/wile/tasks/dictionary.rb +59 -0
- data/lib/wile/tasks/gemcheck.rb +142 -0
- data/lib/wile/tasks/gemfile.rb +60 -0
- data/lib/wile/tasks/help.rb +29 -0
- data/lib/wile/tasks/info.rb +77 -0
- data/lib/wile/tasks/install.rb +53 -0
- data/lib/wile/tasks/lexicon.rb +59 -0
- data/lib/wile/tasks/list.rb +97 -0
- data/lib/wile/tasks/methods.rb +154 -0
- data/lib/wile/tasks/mkdir.rb +19 -0
- data/lib/wile/tasks/note.rb +49 -0
- data/lib/wile/tasks/nvim.rb +60 -0
- data/lib/wile/tasks/order.rb +93 -0
- data/lib/wile/tasks/oscheck.rb +49 -0
- data/lib/wile/tasks/publish.rb +67 -0
- data/lib/wile/tasks/receivers.rb +34 -0
- data/lib/wile/tasks/review.rb +157 -0
- data/lib/wile/tasks/ruby.rb +38 -0
- data/lib/wile/tasks/tc.rb +114 -0
- data/lib/wile/tasks/test.rb +57 -0
- data/lib/wile/tasks/todo.rb +55 -0
- data/lib/wile/tasks/update.rb +67 -0
- data/lib/wile/tasks.rb +34 -0
- data/lib/wile/usage.rb +56 -0
- data/lib/wile/usage_error.rb +18 -0
- data/lib/wile/utilities.rb +283 -0
- data/lib/wile/utilities_refinements.rb +41 -0
- data/lib/wile/wile_refinements.rb +137 -0
- data/lib/wile.rb +39 -0
- data/man/wile.1 +1121 -0
- data/man/wile.md +786 -0
- data/pkg/README.md +3 -0
- metadata +399 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile note ##
|
|
4
|
+
# Puts each NOTE line.
|
|
5
|
+
# Usage:
|
|
6
|
+
# wile note [<match>+] # scrape ruby files for NOTE comments
|
|
7
|
+
module Wile
|
|
8
|
+
# This file is loaded upon a :note task request.
|
|
9
|
+
class Tasks
|
|
10
|
+
NOTE_USAGE = ['Optionally takes one or more arguments.', Set[]].freeze
|
|
11
|
+
|
|
12
|
+
def note(options)
|
|
13
|
+
Utilities.project_root? do |missing|
|
|
14
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
15
|
+
end
|
|
16
|
+
match = Usage.new(options, *NOTE_USAGE).args
|
|
17
|
+
NoteLister.new(match).display
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Greps project Ruby files for NOTE comments.
|
|
22
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
23
|
+
class Tasks::NoteLister
|
|
24
|
+
using UtilitiesRefinements
|
|
25
|
+
|
|
26
|
+
def initialize(match = nil)
|
|
27
|
+
@match = match
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.display_file(filename)
|
|
31
|
+
lines = File.foreach(filename).grep(/#\s*NOTE/)
|
|
32
|
+
puts filename.blue, lines unless lines.empty?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def display
|
|
36
|
+
selected_files.each { self.class.display_file(it) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def selected_files
|
|
42
|
+
files = Project.rbfiles.weird_filename!
|
|
43
|
+
return files.reject { it.start_with?('features/fixtures/') } unless @match
|
|
44
|
+
|
|
45
|
+
files.grep(Regexp.union(@match.map { Regexp.new(it) }))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
Tasks.private_constant :NoteLister
|
|
49
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile nvim ##
|
|
4
|
+
# Opens project standard files in Neovim.
|
|
5
|
+
# Options:
|
|
6
|
+
# --list # list files instead of launching Neovim
|
|
7
|
+
# Usage:
|
|
8
|
+
# wile nvim [<match>+] [--list] # spawn nvim with(matching) files
|
|
9
|
+
module Wile
|
|
10
|
+
# This file is loaded upon a :nvim task request.
|
|
11
|
+
class Tasks
|
|
12
|
+
NVIM_USAGE = ['Optionally takes one or more arguments ' \
|
|
13
|
+
'with optional list flag.',
|
|
14
|
+
Set['list']].freeze
|
|
15
|
+
|
|
16
|
+
def nvim(options)
|
|
17
|
+
Utilities.project_root? do |missing|
|
|
18
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
19
|
+
end
|
|
20
|
+
match = Usage.new(options, *NVIM_USAGE).args
|
|
21
|
+
NvimLauncher.new(match, options).run
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Lists or opens matching project files in Neovim.
|
|
26
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
27
|
+
class Tasks::NvimLauncher
|
|
28
|
+
def initialize(match, options)
|
|
29
|
+
@match = match
|
|
30
|
+
@options = options
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def run
|
|
34
|
+
files = selected_files
|
|
35
|
+
return puts files if @options.list?
|
|
36
|
+
|
|
37
|
+
launch(files)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def selected_files
|
|
43
|
+
files = NvimFiles.new.nvim_files
|
|
44
|
+
return files unless @match
|
|
45
|
+
|
|
46
|
+
files.grep(Regexp.union(@match.map { Regexp.new(it) }))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def launch(files)
|
|
50
|
+
if files.empty?
|
|
51
|
+
raise "No files matched: #{@match.join(', ')}" if @match
|
|
52
|
+
|
|
53
|
+
raise 'No files found.'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
exec('nvim', *files)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
Tasks.private_constant :NvimLauncher
|
|
60
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile order ##
|
|
4
|
+
# Suggests an order to your methods.
|
|
5
|
+
# Sort types:
|
|
6
|
+
# * bcmv: best combination move
|
|
7
|
+
# * nswp: neighbor swap
|
|
8
|
+
# * cswp: combination swap
|
|
9
|
+
# * bnswp: best neighbor swap
|
|
10
|
+
# * bcswp: best combination swap
|
|
11
|
+
# * bprm: best permutation
|
|
12
|
+
# Specials:
|
|
13
|
+
# * dump: prints the data in JSON format
|
|
14
|
+
# * index: prints the name.dependency index
|
|
15
|
+
# * isolate: prints the isolated methods
|
|
16
|
+
# * total: prints the total valuation
|
|
17
|
+
# * qc: checks integrity of the data
|
|
18
|
+
# Usage:
|
|
19
|
+
# wile order <filename> [<sort-type|specials>] # suggest a methods order
|
|
20
|
+
module Wile
|
|
21
|
+
# This file is loaded upon a :order task request.
|
|
22
|
+
class Tasks
|
|
23
|
+
ORDER_USAGE = ['Takes one or two arguments.', (1..2), Set[]].freeze
|
|
24
|
+
|
|
25
|
+
def order(options)
|
|
26
|
+
filename, sort = Usage.new(options, *ORDER_USAGE).args
|
|
27
|
+
raise "does not exist: #{filename}" unless File.exist?(filename)
|
|
28
|
+
|
|
29
|
+
OrderRunner.new(filename, sort&.to_sym || :bcmv).run
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Runs method-order optimization or CodeDataFunction subcommands.
|
|
34
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
35
|
+
class Tasks::OrderRunner
|
|
36
|
+
SPECIALS = %i[dump index isolate total qc].freeze
|
|
37
|
+
MODES = (OrderOptimizer::SORTS + SPECIALS).freeze
|
|
38
|
+
|
|
39
|
+
def initialize(filename, sort = :bcmv)
|
|
40
|
+
raise "invalid sort: #{sort}" unless MODES.include?(sort)
|
|
41
|
+
|
|
42
|
+
@data = CodeData.new(filename)
|
|
43
|
+
@sort = sort
|
|
44
|
+
@names = @data.names
|
|
45
|
+
@optimized = nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def run
|
|
49
|
+
return run_subcommand if SPECIALS.include?(@sort)
|
|
50
|
+
|
|
51
|
+
optimize
|
|
52
|
+
report
|
|
53
|
+
raise unless @optimized == @names
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.delta(from, dest)
|
|
57
|
+
arrow = from < dest ? '↓' : '↑' # UTF-8
|
|
58
|
+
"#{arrow}#{(from - dest).abs}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def run_subcommand
|
|
64
|
+
CodeDataFunction.method(@sort).call(@data)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def optimize
|
|
68
|
+
valuation = CodeDataValuation.new(@data)
|
|
69
|
+
opt = OrderOptimizer.new(@names.dup, sort: @sort) { valuation.total(it) }
|
|
70
|
+
opt.optimize
|
|
71
|
+
@optimized = opt.to_a
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def report
|
|
75
|
+
@optimized.each_with_index { |name, idx| report_line(name, idx) }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def format_move(name, old, idx)
|
|
79
|
+
kls = self.class
|
|
80
|
+
moved = kls.delta(@names.index(name), idx)
|
|
81
|
+
shifted = kls.delta(idx, @optimized.index(old))
|
|
82
|
+
"#{name.red}\t#{moved}\t#{old} #{shifted}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def report_line(name, idx)
|
|
86
|
+
old = @names[idx]
|
|
87
|
+
return puts name.green if name == old
|
|
88
|
+
|
|
89
|
+
puts format_move(name, old, idx)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
Tasks.private_constant :OrderRunner
|
|
93
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile oscheck ##
|
|
4
|
+
# Checks for system commands and reports their installed versions.
|
|
5
|
+
# By default, only displays found commands.
|
|
6
|
+
# Options:
|
|
7
|
+
# --all # report all commands including missing ones (exits 2 on missing)
|
|
8
|
+
# Usage:
|
|
9
|
+
# wile oscheck [--all] # check system command versions
|
|
10
|
+
module Wile
|
|
11
|
+
# This file is loaded upon a :oscheck task request.
|
|
12
|
+
class Tasks
|
|
13
|
+
OSCHECK_USAGE = [
|
|
14
|
+
'Takes no arguments with optional all flag.',
|
|
15
|
+
0,
|
|
16
|
+
Set['all']
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
OSCHECK_WIDTH = 39
|
|
20
|
+
|
|
21
|
+
def oscheck(options)
|
|
22
|
+
Usage.new(options, *OSCHECK_USAGE)
|
|
23
|
+
raise 'STOP: commands not found' if oscheck_do(options.all?)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def oscheck_do(all)
|
|
29
|
+
cmd_ver = CommandVersion.new
|
|
30
|
+
cmd_ver.commands.reject { command_found?(it, cmd_ver) }.tap do |missing|
|
|
31
|
+
missing.each { show(it, '-', :red) } if all
|
|
32
|
+
end.any? && all
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def command_found?(cmd, cmd_ver)
|
|
36
|
+
return false unless (ver = cmd_ver[cmd])
|
|
37
|
+
|
|
38
|
+
show(cmd, ver, :green)
|
|
39
|
+
true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# category: helpers
|
|
43
|
+
|
|
44
|
+
def show(cmd, ver, col = :green)
|
|
45
|
+
print "#{cmd.colorize(col)}:".ljust(OSCHECK_WIDTH)
|
|
46
|
+
puts ver
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile publish ##
|
|
4
|
+
# Verifies version, git state, gemspec freshness, and tests, then builds and
|
|
5
|
+
# pushes the gem to RubyGems, archives it to pkg/ and History.txt, and
|
|
6
|
+
# commits, tags, and pushes with --follow-tags.
|
|
7
|
+
# Usage:
|
|
8
|
+
# wile publish <version> # publish a new version
|
|
9
|
+
module Wile
|
|
10
|
+
# This file is loaded upon a :publish task request.
|
|
11
|
+
class Tasks
|
|
12
|
+
PUBLISH_USAGE = ['Takes one argument.',
|
|
13
|
+
1, /^\d+\.\d+\.\d+$/, Set[]].freeze
|
|
14
|
+
|
|
15
|
+
def publish(options)
|
|
16
|
+
Utilities.project_root? do |missing|
|
|
17
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
18
|
+
end
|
|
19
|
+
version, = Usage.new(options, *PUBLISH_USAGE).args
|
|
20
|
+
Publisher.new(version).publish
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Orchestrates gem publication, archiving, and git tagging.
|
|
25
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
26
|
+
class Tasks::Publisher
|
|
27
|
+
def initialize(version, gmu = GemUtils.new)
|
|
28
|
+
@version = version
|
|
29
|
+
@gmu = gmu
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def publish
|
|
33
|
+
verify_version
|
|
34
|
+
verify_ready
|
|
35
|
+
publish_and_archive
|
|
36
|
+
commit_and_tag
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def verify_version
|
|
42
|
+
Info.info.verify_version! @version
|
|
43
|
+
Git.verify_unpublished! @version
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def publish_and_archive
|
|
47
|
+
pkg = @gmu.build!
|
|
48
|
+
@gmu.push! pkg
|
|
49
|
+
Project.archive pkg
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def verify_ready
|
|
53
|
+
Git.clean!
|
|
54
|
+
@gmu.clean!
|
|
55
|
+
@gmu.ready!
|
|
56
|
+
Test.test!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def commit_and_tag
|
|
60
|
+
Git.add! 'History.txt'
|
|
61
|
+
Git.commit! @version, no_verify: true
|
|
62
|
+
Git.tag! @version
|
|
63
|
+
Git.push!
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
Tasks.private_constant :Publisher
|
|
67
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile receivers ##
|
|
4
|
+
# Lists variable and constant names assigned to known Ruby types in lib/**/*.rb.
|
|
5
|
+
# Usage:
|
|
6
|
+
# wile receivers # list variable and constant names by receiver type
|
|
7
|
+
module Wile
|
|
8
|
+
# This file is loaded upon a :receivers task request.
|
|
9
|
+
class Tasks
|
|
10
|
+
using WileRefinements
|
|
11
|
+
|
|
12
|
+
RECEIVERS_USAGE = ['Takes no arguments.', 0, Set[]].freeze
|
|
13
|
+
|
|
14
|
+
# :reek:UtilityFunction
|
|
15
|
+
def receivers(options)
|
|
16
|
+
Utilities.project_root? do |missing|
|
|
17
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
18
|
+
end
|
|
19
|
+
Usage.new(options, *RECEIVERS_USAGE)
|
|
20
|
+
Receivers.new.scan.each { |type, list| display_receivers(type, list) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# :reek:UtilityFunction
|
|
26
|
+
def display_receivers(type, list)
|
|
27
|
+
return if list.empty?
|
|
28
|
+
|
|
29
|
+
puts "## #{type} ##".blue
|
|
30
|
+
list.display
|
|
31
|
+
puts
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# wile: require 'reek,rubocop'
|
|
4
|
+
# wile: os `clear,reek,rubocop,wile`
|
|
5
|
+
|
|
6
|
+
# ## wile review ##
|
|
7
|
+
# Interactively reviews project files using content, order, reek, and rubocop.
|
|
8
|
+
# With --all, auto-advances through passing files and stops only on issues.
|
|
9
|
+
# CSV is a comma separated list: content,order,reek,rubocop
|
|
10
|
+
# Usage:
|
|
11
|
+
# wile review [<target>] [--all] [--strict] [--only=CSV] # runs review
|
|
12
|
+
module Wile
|
|
13
|
+
# This file is loaded upon a :review task request.
|
|
14
|
+
class Tasks
|
|
15
|
+
REVIEW_USAGE = [
|
|
16
|
+
'May take one target with optional all/strict/only flags.',
|
|
17
|
+
(0..1), Set['all', 'strict', 'only']
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
def review(options, target: nil)
|
|
21
|
+
Utilities.project_root? do |missing|
|
|
22
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
23
|
+
end
|
|
24
|
+
target ||= Usage.new(options, *REVIEW_USAGE).args&.first
|
|
25
|
+
Review.new(options, Review.review_files(target)).run
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# This class is used to run review.
|
|
30
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
31
|
+
class Tasks::Review
|
|
32
|
+
using UtilitiesRefinements
|
|
33
|
+
|
|
34
|
+
AVAILABLE_CHECKS = %i[content order reek rubocop].freeze
|
|
35
|
+
|
|
36
|
+
def self.review_files(target)
|
|
37
|
+
all_files = NvimFiles.new.nvim_files.select { it.start_with?('lib/') }
|
|
38
|
+
return all_files unless target
|
|
39
|
+
return [target] if File.file?(target)
|
|
40
|
+
|
|
41
|
+
match_target(all_files, target)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.match_target(all_files, target)
|
|
45
|
+
matched = if File.directory?(target)
|
|
46
|
+
Dir.glob(File.join(target, '**/*.rb'))
|
|
47
|
+
else
|
|
48
|
+
all_files.grep(/#{target}/)
|
|
49
|
+
end
|
|
50
|
+
raise "no match for #{target}" if matched.empty?
|
|
51
|
+
|
|
52
|
+
matched
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def initialize(options, files)
|
|
56
|
+
@files = files
|
|
57
|
+
@files.weird_filename!
|
|
58
|
+
raise 'No files to review' if @files.empty?
|
|
59
|
+
|
|
60
|
+
@index = 0
|
|
61
|
+
@options = options
|
|
62
|
+
@checks = self.class.parse_checks(options.only)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.parse_checks(only)
|
|
66
|
+
return AVAILABLE_CHECKS unless only
|
|
67
|
+
|
|
68
|
+
checks = Array(only).join(',').split(',').map(&:to_sym).uniq
|
|
69
|
+
bad = checks - AVAILABLE_CHECKS
|
|
70
|
+
bad.empty? ? checks : raise("Unknown checks: #{bad.join(',')}")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def run
|
|
74
|
+
catch(:quit) { loop { review_do } }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def index(match)
|
|
80
|
+
@files.index { |entry| entry.match?(match) } or
|
|
81
|
+
raise "no match for #{match}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def review_response_cases(response, size = @files.size)
|
|
85
|
+
case response
|
|
86
|
+
when 'q', 'Q' then throw(:quit)
|
|
87
|
+
when '', 'n', 'N' then @index = (@index + 1) % size
|
|
88
|
+
when 'p', 'P' then @index = (@index - 1) % size
|
|
89
|
+
when 'r', 'R' then nil
|
|
90
|
+
else
|
|
91
|
+
@index = index(response)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def review_failed
|
|
96
|
+
@checks.reject { send(it) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def review_do
|
|
100
|
+
system('clear')
|
|
101
|
+
puts "#{@index + 1}. #{file}".blue.bold
|
|
102
|
+
review_next review_failed
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# :reek:UncommunicativeVariableName e is standard
|
|
106
|
+
def review_next(failed)
|
|
107
|
+
review_response_cases review_choice(failed)
|
|
108
|
+
rescue StandardError => e
|
|
109
|
+
puts e.message.red
|
|
110
|
+
retry
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def auto_next
|
|
114
|
+
@index + 1 < @files.size ? 'n' : 'q'
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def review_choice(failed)
|
|
118
|
+
return auto_next if @options.all? && failed.empty?
|
|
119
|
+
|
|
120
|
+
puts "\nFailed: #{failed.join(', ')}".red if failed.any?
|
|
121
|
+
prompt_choice
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def prompt_choice
|
|
125
|
+
print 'Next(Enter) Quit(q) Redo(r) Previous(p) or file match: '.yellow
|
|
126
|
+
$stdin.gets&.strip || 'q'
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def content
|
|
130
|
+
puts "\n# Content".blue
|
|
131
|
+
system("wile content #{file.sw}")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def file
|
|
135
|
+
@files[@index]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def reek
|
|
139
|
+
puts "\n# Reek".blue
|
|
140
|
+
cfg = @options.strict? ? '--config .reek-strict.yml' : ''
|
|
141
|
+
system("reek --no-documentation #{cfg} #{file.sw}")
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def rubocop
|
|
145
|
+
puts "\n# Rubocop".blue
|
|
146
|
+
cfg = @options.strict? ? '--config .rubocop-strict.yml' : ''
|
|
147
|
+
system("rubocop #{cfg} #{file.sw}")
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def order
|
|
151
|
+
puts "\n# Order".blue
|
|
152
|
+
sw = file.sw
|
|
153
|
+
system("wile order #{sw}") && system("wile order #{sw} bprm")
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
Tasks.private_constant :Review
|
|
157
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile ruby ##
|
|
4
|
+
# List ruby files in the project.
|
|
5
|
+
# Usage:
|
|
6
|
+
# wile ruby [<match>+] # lists ruby files
|
|
7
|
+
module Wile
|
|
8
|
+
# This file is loaded upon a :ruby task request.
|
|
9
|
+
class Tasks
|
|
10
|
+
RUBY_USAGE = [
|
|
11
|
+
'Optionally takes file matchers.',
|
|
12
|
+
Set[]
|
|
13
|
+
].freeze
|
|
14
|
+
|
|
15
|
+
def ruby(options)
|
|
16
|
+
Utilities.project_root? do |missing|
|
|
17
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
18
|
+
end
|
|
19
|
+
match = Usage.new(options, *RUBY_USAGE).args || []
|
|
20
|
+
RubyLister.new(match).list
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Lists and filters project Ruby files.
|
|
25
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
26
|
+
class Tasks::RubyLister
|
|
27
|
+
def initialize(match = [])
|
|
28
|
+
@match = match
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def list
|
|
32
|
+
Project.rbfiles.sort.each do |file|
|
|
33
|
+
puts file if @match.empty? || @match.any? { file.match?(it) }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
Tasks.private_constant :RubyLister
|
|
38
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ## wile tc ##
|
|
4
|
+
# Lists custom unit tests in project, or wile template gates.
|
|
5
|
+
# Scopes:
|
|
6
|
+
# * project Custom project unit tests (default)
|
|
7
|
+
# * wile Wile template quality gates
|
|
8
|
+
# * all Both project and Wile tests
|
|
9
|
+
# Options:
|
|
10
|
+
# --raw Suppress headers and spaces
|
|
11
|
+
# Usage:
|
|
12
|
+
# wile tc [<scope>] [<match>+] [--raw] # lists unit tests
|
|
13
|
+
module Wile
|
|
14
|
+
# This file is loaded upon a :tc task request.
|
|
15
|
+
class Tasks
|
|
16
|
+
TC_USAGE = [
|
|
17
|
+
'Optionally takes scope (project, wile, all), matchers, and --raw.',
|
|
18
|
+
Set['raw']
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
def tc(options)
|
|
22
|
+
Utilities.project_root? do |missing|
|
|
23
|
+
raise "NOINPUT: Missing root files: #{missing.join(', ')}"
|
|
24
|
+
end
|
|
25
|
+
args = Usage.new(options, *TC_USAGE).args || []
|
|
26
|
+
TestLister.new(args, options).display
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Lists project unit tests and Wile template quality gates.
|
|
31
|
+
# rubocop:disable-next Style/ClassAndModuleChildren
|
|
32
|
+
class Tasks::TestLister
|
|
33
|
+
SCOPES = %w[project wile all].freeze
|
|
34
|
+
|
|
35
|
+
def initialize(args, options)
|
|
36
|
+
@match = args.dup
|
|
37
|
+
@scope = SCOPES.include?(@match.first) ? @match.shift.to_sym : :project
|
|
38
|
+
@options = options
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.lib_to_tc(path)
|
|
42
|
+
seg = path.split('/')[1..]
|
|
43
|
+
seg.delete('autoloads')
|
|
44
|
+
name = (seg.length == 1 ? seg[0] : seg[1..].join('_')).chomp('.rb')
|
|
45
|
+
"test/tc_ut_#{name}"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.ranked_tests
|
|
49
|
+
NvimFiles.new.nvim_files.grep(%r{^lib/}).flat_map do |file|
|
|
50
|
+
tc = lib_to_tc(file)
|
|
51
|
+
[tc, "#{tc}_slow"]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.order_custom(custom)
|
|
56
|
+
ordered = ranked_tests.select { custom.include?(it) }
|
|
57
|
+
ordered + (custom - ordered).sort
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def display
|
|
61
|
+
project, wile = load_groups
|
|
62
|
+
case @scope
|
|
63
|
+
when :project then display_group(project, 'custom')
|
|
64
|
+
when :wile then display_group(wile, 'Wile template')
|
|
65
|
+
when :all then display_all(project, wile)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def load_groups
|
|
72
|
+
cached = Cache.new.p2c_hash.keys.grep(%r{^test/tc_})
|
|
73
|
+
existing = Dir.glob('test/tc_*')
|
|
74
|
+
project = self.class.order_custom(existing - cached)
|
|
75
|
+
wile = (cached & existing).sort
|
|
76
|
+
[filter_matching(project), filter_matching(wile)]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def display_group(tests, label)
|
|
80
|
+
return display_none("#{label} test/tc_*") if tests.empty?
|
|
81
|
+
|
|
82
|
+
puts tests
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def filter_matching(tests)
|
|
86
|
+
@match.empty? ? tests : tests.select { match?(it) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def match?(test)
|
|
90
|
+
@match.any? { test.match?(it) }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def display_none(label)
|
|
94
|
+
msg = if @match.empty? then "No #{label}"
|
|
95
|
+
else "No tests matched: #{@match.join(', ')}"
|
|
96
|
+
end
|
|
97
|
+
warn msg.red
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def display_all(project, wile)
|
|
101
|
+
return display_none('test/tc_*') if project.empty? && wile.empty?
|
|
102
|
+
return puts(project, wile) if @options.raw?
|
|
103
|
+
|
|
104
|
+
show_section('# Project:'.blue, project)
|
|
105
|
+
puts if project.any? && wile.any?
|
|
106
|
+
show_section('# Wile:'.blue, wile)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def show_section(heading, tests)
|
|
110
|
+
puts heading, tests if tests.any?
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
Tasks.private_constant :TestLister
|
|
114
|
+
end
|