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,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `gem,rbenv`
4
+
5
+ # ## wile gemcheck ##
6
+ # Checks for missing gems in the current Ruby version that are found installed
7
+ # in other versions on the system using `rbenv`.
8
+ # Usage:
9
+ # wile gemcheck [--all] # checks for missing gems
10
+ module Wile
11
+ # This file is loaded upon a :gemcheck task request.
12
+ class Tasks
13
+ GEMCHECK_USAGE = [
14
+ 'Takes no arguments with optional all flag.',
15
+ 0,
16
+ Set['all']
17
+ ].freeze
18
+
19
+ # :reek:UtilityFunction
20
+ def gemcheck(options)
21
+ Usage.new(options, *GEMCHECK_USAGE)
22
+ GemChecker.new(options).run
23
+ end
24
+ end
25
+
26
+ # Compares installed gems across rbenv Ruby versions and installs missing.
27
+ # rubocop:disable-next Style/ClassAndModuleChildren
28
+ class Tasks::GemChecker
29
+ def self.rbenv_versions_prefix
30
+ prefix = File.join(Utilities.rbenv_root, 'versions')
31
+ gemcmd = `rbenv which gem 2>/dev/null`.strip
32
+ raise "Unexpected gem command: #{gemcmd}" unless
33
+ File.directory?(prefix) && gemcmd.start_with?(prefix)
34
+
35
+ prefix
36
+ end
37
+
38
+ def initialize(options)
39
+ @options = options
40
+ @prefix = self.class.rbenv_versions_prefix
41
+ end
42
+
43
+ def self.gem_majors(str)
44
+ return unless str&.start_with?('(') && str.end_with?(')')
45
+
46
+ str[1..-2].split(',').filter_map do |item|
47
+ ver = item.sub('default:', '').strip.split.first
48
+ Gem::Version.new(ver).segments.first if Gem::Version.correct?(ver)
49
+ end.uniq.sort
50
+ end
51
+
52
+ def self.pair_majors(name, majors, current)
53
+ (majors - current.fetch(name, [])).map { [name, it] }
54
+ end
55
+
56
+ def self.missing_gems(gems, current)
57
+ gems.flat_map { |name, majors| pair_majors(name, majors, current) }
58
+ end
59
+
60
+ def self.record_missing(missing, version, items)
61
+ items.each { |key| missing[key] << version }
62
+ end
63
+
64
+ def self.missing(inventory)
65
+ current = inventory.fetch(RUBY_VERSION, {})
66
+ res = Hash.new { |hash, key| hash[key] = [] }
67
+ inventory.except(RUBY_VERSION).each_with_object(res) do |(ver, gems), out|
68
+ record_missing(out, ver, missing_gems(gems, current))
69
+ end
70
+ end
71
+
72
+ def self.collect_gems(gemcmd)
73
+ `#{gemcmd} list`.lines(chomp: true).each_with_object({}) do |line, gems|
74
+ name, vers = line.split(' ', 2)
75
+ majors = gem_majors(vers)
76
+ gems[name] = majors if majors
77
+ end
78
+ end
79
+
80
+ def self.report(missing, searched)
81
+ puts "Current Ruby version: #{RUBY_VERSION}".gray
82
+ puts "Searching versions: #{searched.join(', ')}".gray
83
+ puts 'Gems missing in current found in other versions:'.blue
84
+ missing.sort.each do |(name, major), versions|
85
+ puts " #{name} (~> #{major}): #{versions.join(', ')}"
86
+ end
87
+ end
88
+
89
+ def self.install_gem(name, major)
90
+ req = "~> #{major}"
91
+ return if Utilities.gem_installed?(name, version: req)
92
+
93
+ Utilities.run('gem', 'install', name, '-v', req) do |code, msg|
94
+ raise "#{Sysexits.label(code)}: #{msg}"
95
+ end
96
+ end
97
+
98
+ def run
99
+ inventory = build_inventory
100
+ missing = self.class.missing(inventory)
101
+ return puts 'OK'.green if missing.empty?
102
+
103
+ prompt_and_install(missing, inventory.keys - [RUBY_VERSION])
104
+ end
105
+
106
+ def self.previous_version(versions, current = RUBY_VERSION)
107
+ cur = Gem::Version.new(current)
108
+ older = versions.select do |ver|
109
+ Gem::Version.correct?(ver) && Gem::Version.new(ver) < cur
110
+ end
111
+ older.max_by { Gem::Version.new(it) }
112
+ end
113
+
114
+ private
115
+
116
+ def prompt_and_install(missing, searched, kls = self.class)
117
+ kls.report(missing, searched)
118
+ Utilities.confirm?('Would you like to install them all?') ||
119
+ raise('NO: Aborted.')
120
+ missing.each_key { |name, major| kls.install_gem(name, major) }
121
+ puts 'OK'.green
122
+ end
123
+
124
+ def build_inventory
125
+ target_versions.each_with_object({}) do |ver, inventory|
126
+ gemcmd = File.join(@prefix, ver, 'bin/gem')
127
+ if File.executable?(gemcmd)
128
+ inventory[ver] = self.class.collect_gems(gemcmd)
129
+ end
130
+ end
131
+ end
132
+
133
+ def target_versions
134
+ versions = `rbenv versions --bare --skip-aliases`.lines(chomp: true)
135
+ return (versions + [RUBY_VERSION]).uniq if @options.all?
136
+
137
+ prev = self.class.previous_version(versions)
138
+ [RUBY_VERSION, prev].compact.uniq
139
+ end
140
+ end
141
+ Tasks.private_constant :GemChecker
142
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile gemfile ##
4
+ # Generates project Gemfile from dependencies.
5
+ # Options:
6
+ # --dump prints Gemfile to stdout instead of writing
7
+ # Usage:
8
+ # wile gemfile [--dump] # generate Gemfile from dependencies
9
+ module Wile
10
+ # This file is loaded upon a :gemfile task request.
11
+ class Tasks
12
+ GEMFILE_USAGE = [
13
+ 'Takes no arguments with optional dump flag.',
14
+ 0, Set['dump']
15
+ ].freeze
16
+
17
+ def gemfile(options, gemspec = nil, file = 'Gemfile')
18
+ Utilities.project_root? do |missing|
19
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
20
+ end
21
+ Usage.new(options, *GEMFILE_USAGE)
22
+ gemspec ||= Gemspec.new
23
+ GemfileWriter.new(gemspec, file, options).write
24
+ end
25
+ end
26
+
27
+ # Builds and writes a project Gemfile from gemspec dependencies.
28
+ # rubocop:disable-next Style/ClassAndModuleChildren
29
+ class Tasks::GemfileWriter
30
+ def initialize(gemspec = Gemspec.new, file = 'Gemfile', options = nil)
31
+ @gemspec = gemspec
32
+ @file = file
33
+ @options = options
34
+ end
35
+
36
+ def write
37
+ @options&.dump? ? puts(content) : File.write(@file, content)
38
+ end
39
+
40
+ def self.format_gems(gems)
41
+ gems.map { "gem '#{it.name}'" }.uniq
42
+ end
43
+
44
+ private
45
+
46
+ def content
47
+ kls = self.class
48
+ run = kls.format_gems(@gemspec.rungems)
49
+ dev = kls.format_gems(@gemspec.devgems) - run
50
+ [
51
+ "source 'https://rubygems.org'",
52
+ '## runtime ##',
53
+ *run.sort,
54
+ '## development ##',
55
+ *dev.sort
56
+ ].join("\n") << "\n"
57
+ end
58
+ end
59
+ Tasks.private_constant :GemfileWriter
60
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile help ##
4
+ # Usage:
5
+ # wile help [<task>+] # show task's help
6
+ module Wile
7
+ # This file is loaded upon a :help task request.
8
+ class Tasks
9
+ HELP_USAGE = ['Takes one or more tasks.', Set[]].freeze
10
+
11
+ def help(options)
12
+ usage = Usage.new(options, *HELP_USAGE)
13
+ tasks = usage.args&.map do |tsk|
14
+ find(tsk) || warn("Missing task: #{tsk}".yellow)
15
+ end&.compact || %i[help list]
16
+ usage.error!('No tasks matched.') if tasks.empty?
17
+
18
+ display_help(tasks)
19
+ end
20
+
21
+ def display_help(tasks)
22
+ puts
23
+ tasks.each do |task|
24
+ puts Help[task]
25
+ puts
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile info ##
4
+ # Show as much info as found in gemspec.
5
+ # Usage:
6
+ # wile info # show project info
7
+ module Wile
8
+ # This file is loaded upon a :info task request.
9
+ class Tasks
10
+ INFO_USAGE = ['Takes no arguments.', 0, Set[]].freeze
11
+
12
+ def info(options, info = Info.info)
13
+ Utilities.project_root? do |missing|
14
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
15
+ end
16
+ Usage.new(options, *INFO_USAGE)
17
+ InfoDisplay.new(info).display
18
+ end
19
+ end
20
+
21
+ # Displays project metadata, README description, and gemspec sections.
22
+ # rubocop:disable-next Style/ClassAndModuleChildren
23
+ class Tasks::InfoDisplay
24
+ def initialize(info = Info.info)
25
+ @info = info
26
+ end
27
+
28
+ def self.gem_label(gem)
29
+ name = gem.name
30
+ ver = gem.version
31
+ ver ? "#{name}(#{ver})" : name
32
+ end
33
+
34
+ def display
35
+ puts_header
36
+ puts_readme
37
+ puts_gemspec
38
+ end
39
+
40
+ private
41
+
42
+ def puts_gems(heading, gems)
43
+ puts_section(heading, gems.map { self.class.gem_label(it) })
44
+ end
45
+
46
+ def puts_section(heading, items)
47
+ puts "#{heading.blue}\n#{items.map { "* #{it}" }.join("\n")}"
48
+ end
49
+
50
+ def puts_gemspec
51
+ gemspec = Gemspec.new(@info)
52
+ puts_section('## Files', gemspec.files)
53
+ puts_section('## Executables', gemspec.executables)
54
+ puts_gems('## Runtime gems', gemspec.rungems)
55
+ puts_gems('## Development gems', gemspec.devgems)
56
+ end
57
+
58
+ def puts_header
59
+ puts <<~INFO
60
+ # #{@info.project.blue.bold}
61
+ + Version: #{@info.version}
62
+ + Author: #{@info.username}
63
+ INFO
64
+ end
65
+
66
+ def puts_readme
67
+ readme = Readme.new(@info)
68
+ puts <<~README
69
+ #{'## Description'.blue}
70
+ #{readme.description.light_black}
71
+ README
72
+ rescue StandardError
73
+ nil
74
+ end
75
+ end
76
+ Tasks.private_constant :InfoDisplay
77
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile install ##
4
+ # Builds and installs current project locally,
5
+ # uninstalling the version first if already installed.
6
+ # Refuses to build unless git status is clean, unless forced.
7
+ # Usage:
8
+ # wile install [--force] # install current local project
9
+ module Wile
10
+ # This file is loaded upon a :install task request.
11
+ class Tasks
12
+ INSTALL_USAGE = ['Takes no arguments with optional force flag.',
13
+ 0, Set['force']].freeze
14
+
15
+ def install(options, gmu = GemUtils.new, git = Git)
16
+ Utilities.project_root? do |missing|
17
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
18
+ end
19
+ Usage.new(options, *INSTALL_USAGE)
20
+ Installer.new(options, gmu, git).install
21
+ end
22
+ end
23
+
24
+ # Builds and installs the current project gem locally.
25
+ # rubocop:disable-next Style/ClassAndModuleChildren
26
+ class Tasks::Installer
27
+ def initialize(options, gmu = GemUtils.new, git = Git)
28
+ @options = options
29
+ @gmu = gmu
30
+ @git = git
31
+ end
32
+
33
+ def install
34
+ verify unless @options.force?
35
+ reinstall
36
+ end
37
+
38
+ private
39
+
40
+ def verify
41
+ @git.clean!
42
+ @gmu.clean!
43
+ @gmu.ready!
44
+ end
45
+
46
+ def reinstall
47
+ @gmu.build!
48
+ @gmu.uninstall! if @gmu.installed?
49
+ @gmu.install! && @gmu.rm_pkg
50
+ end
51
+ end
52
+ Tasks.private_constant :Installer
53
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # wile: os `diff`
4
+
5
+ # ## wile lexicon ##
6
+ # Usage:
7
+ # wile lexicon [--check] [--yes] # view changes and update lexicon
8
+ module Wile
9
+ # This file is loaded upon a :lexicon task request.
10
+ class Tasks
11
+ LEXICON_USAGE = ['Takes no arguments.',
12
+ 0, Set['check', 'yes']].freeze
13
+
14
+ def lexicon(options)
15
+ Utilities.project_root? do |missing|
16
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
17
+ end
18
+ Usage.new(options, *LEXICON_USAGE)
19
+ LexiconUpdater.new(options).run
20
+ end
21
+ end
22
+
23
+ # Checks and updates the project .lexicon file.
24
+ # rubocop:disable-next Style/ClassAndModuleChildren
25
+ class Tasks::LexiconUpdater
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, '.lexicon', 'tmp/.lexicon')
39
+ end
40
+
41
+ private
42
+
43
+ def ok?
44
+ return true if system 'test/tc_lexicon --verbose=silent'
45
+
46
+ self.class.diff
47
+ return false unless update?
48
+
49
+ FileUtils.cp 'tmp/.lexicon', '.lexicon'
50
+ true
51
+ end
52
+
53
+ def update?
54
+ !@options.check? &&
55
+ (@options.yes? || Utilities.confirm?('Update lexicon?'))
56
+ end
57
+ end
58
+ Tasks.private_constant :LexiconUpdater
59
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile list ##
4
+ # Available formats:
5
+ # * USAGE default
6
+ # * DICTIONARY
7
+ # * NAME
8
+ # * CODE
9
+ # Usage:
10
+ # wile list [<match>+] [--format=WORD] # list tasks(by match)
11
+ module Wile
12
+ # This file is loaded upon a :list task request.
13
+ # :reek:InstanceVariableAssumption
14
+ class Tasks
15
+ LIST_USAGE = [
16
+ 'Optionally takes one or more tasks with optional format flag.',
17
+ Set['format']
18
+ ].freeze
19
+
20
+ # :reek:FeatureEnvy
21
+ def list(options, tasks = @tasks)
22
+ usage = Usage.new(options, *LIST_USAGE)
23
+ format = options.format || 'USAGE'
24
+ unless TaskLister::FORMATS.key?(format.upcase)
25
+ usage.error!("Unrecognized format '#{format}'.")
26
+ end
27
+
28
+ TaskLister.new(tasks, usage.args, format).display
29
+ end
30
+ end
31
+
32
+ # Formats and displays matching Wile tasks.
33
+ # rubocop:disable-next Style/ClassAndModuleChildren
34
+ class Tasks::TaskLister
35
+ FORMATS = {
36
+ 'USAGE' => :puts_usage,
37
+ 'DICTIONARY' => :puts_dictionary,
38
+ 'NAME' => :puts_name,
39
+ 'CODE' => :puts_code
40
+ }.freeze
41
+
42
+ def initialize(tasks, args = nil, format = 'USAGE')
43
+ @tasks = tasks
44
+ @args = args
45
+ @format = format
46
+ end
47
+
48
+ def self.parse_usage(task)
49
+ usage, comment = Help.usage(task).split(/\s*#\s*/, 2)
50
+ cmd, name, args = usage.split(/\s+/, 3)
51
+ [cmd, name, args, comment]
52
+ end
53
+
54
+ def display
55
+ matched = matched_tasks
56
+ raise 'STOP: No task matched' if matched.empty?
57
+
58
+ display_tasks(matched, FORMATS.fetch(@format.upcase))
59
+ end
60
+
61
+ private
62
+
63
+ def puts_dictionary(task)
64
+ _cmd, name, _args, comment = self.class.parse_usage(task)
65
+ puts "+ #{name}: #{comment || '-'}"
66
+ end
67
+
68
+ def puts_usage(task)
69
+ cmd, name, args, comment = self.class.parse_usage(task)
70
+ puts(comment ? "# #{comment.capitalize}:".gray : '# ---'.gray)
71
+ puts [" #{cmd}", name.blue.bold, args].compact.join(' ')
72
+ end
73
+
74
+ def matched_tasks
75
+ @args ? @tasks.select { match?(it) } : @tasks
76
+ end
77
+
78
+ def display_tasks(tasks, formatter)
79
+ puts
80
+ tasks.each { send(formatter, it) }
81
+ puts
82
+ end
83
+
84
+ def match?(task)
85
+ @args.any? { task.match?(it) }
86
+ end
87
+
88
+ def puts_code(task)
89
+ puts Help.usage(task)
90
+ end
91
+
92
+ def puts_name(task)
93
+ puts task
94
+ end
95
+ end
96
+ Tasks.private_constant :TaskLister
97
+ end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile methods ##
4
+ # Classify methods in your code:
5
+ # * Undefined: methods that are not defined in your code
6
+ # * Implicit: constructors that are called but not defined
7
+ # * Unused: methods that are defined but not used
8
+ # * Independent: methods that do not depend on other methods
9
+ # * Isolate: methods that are not used and do not depend on other methods
10
+ # * Shared: methods that are used by other files
11
+ # * Reused: method names that are used by multiple classes
12
+ # Usage:
13
+ # wile methods [match+] [--name=list-name] # classify methods in your code
14
+ module Wile
15
+ # This file is loaded upon a :methods task request.
16
+ class Tasks
17
+ METHODS_USAGE = ['Optionally takes one or more arguments.',
18
+ Set['name']].freeze
19
+
20
+ def methods(options)
21
+ Utilities.project_root? do |missing|
22
+ raise "NOINPUT: Missing root files: #{missing.join(', ')}"
23
+ end
24
+ matches = Usage.new(options, *METHODS_USAGE).args&.map { Regexp.new(it) }
25
+ DisplayLists.new(matches, select: options.name).display
26
+ end
27
+ end
28
+
29
+ # Displays categorized method lists.
30
+ # rubocop:disable-next Style/ClassAndModuleChildren
31
+ class Tasks::DisplayLists
32
+ using WileRefinements
33
+
34
+ LISTS = %i[
35
+ undefined implicit unused independent isolate shared reused
36
+ ].freeze
37
+
38
+ def initialize(matches = nil, select: nil, methods: Methods.new)
39
+ @matches = matches
40
+ @select = select&.downcase
41
+ @methods = methods
42
+ end
43
+
44
+ def display
45
+ puts "# Matching: #{@matches.map(&:inspect).join(', ')}".blue if @matches
46
+ puts
47
+ LISTS.each { send(it) if selected?(it) }
48
+ end
49
+
50
+ def self.label_undefined(mth)
51
+ return "#{mth} ☰".magenta if mth.standard_library? # UTF-8
52
+ return "#{mth} ◇".cyan if mth.object_method? # UTF-8
53
+
54
+ mth
55
+ end
56
+
57
+ private
58
+
59
+ def selected?(name)
60
+ !@select || name.match?(@select)
61
+ end
62
+
63
+ # category: lists
64
+
65
+ def isolate
66
+ list = @methods.methods
67
+ .select do |name, info|
68
+ match?(name) && info.dependencies.empty? &&
69
+ info.dependants.empty?
70
+ end
71
+ .keys.sort
72
+ display_list(list, '## Isolate ##'.blue)
73
+ end
74
+
75
+ def shared
76
+ list = @methods.methods
77
+ .select do |name, info|
78
+ match?(name) &&
79
+ info.dependants.any? { it != info.filename }
80
+ end
81
+ .keys.sort
82
+ display_list(list, '## Shared ##'.blue)
83
+ end
84
+
85
+ def undefined
86
+ list = @methods.undefined_methods.select { match?(it) }.sort
87
+ list.map! { self.class.label_undefined(it) }
88
+ display_list(list, '## Undefined ##'.blue)
89
+ end
90
+
91
+ def unused
92
+ list = @methods.methods
93
+ .select do |name, info|
94
+ match?(name) && info.dependants.empty?
95
+ end
96
+ .keys.sort
97
+ display_list(list, '## Unused ##'.blue)
98
+ end
99
+
100
+ def independent
101
+ list = @methods.methods
102
+ .select do |name, info|
103
+ match?(name) && info.dependencies.empty?
104
+ end
105
+ .keys.sort
106
+ display_list(list, '## Independent ##'.blue)
107
+ end
108
+
109
+ def implicit
110
+ list = @methods.implicit_methods.select { match?(it) }.sort
111
+ display_list(list, '## Implicit ##'.blue)
112
+ end
113
+
114
+ def reused
115
+ reused = name2scope.select! do |name, scopes|
116
+ scopes.size > 1 and name != 'initialize' and match?(name)
117
+ end
118
+ display_reused(reused) unless reused.empty?
119
+ end
120
+
121
+ # category: helper
122
+
123
+ def match?(name)
124
+ !@matches || @matches.any? { it.match?(name) }
125
+ end
126
+
127
+ def name2scope
128
+ @methods.methods.each_key.with_object({}) do |mth, scopes|
129
+ name, dot, scope = mth.split(/([.#])/).reverse
130
+ (scopes[name] ||= []) << "#{scope}#{dot}"
131
+ end
132
+ end
133
+
134
+ # category: display
135
+
136
+ def display_list(list, heading = nil)
137
+ return if list.empty?
138
+
139
+ puts heading if heading
140
+ list.display
141
+ puts
142
+ end
143
+
144
+ def display_reused(reused)
145
+ puts '## Reused ##'.blue
146
+ reused.each do |name, scopes|
147
+ puts "#{name.bold}:"
148
+ scopes.display
149
+ end
150
+ puts
151
+ end
152
+ end
153
+ Tasks.private_constant :DisplayLists
154
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ## wile mkdir ##
4
+ # Usage:
5
+ # wile mkdir <dirname> # creates project dirname
6
+ module Wile
7
+ # This file is loaded upon a :mkdir task request.
8
+ class Tasks
9
+ MKDIR_USAGE = ['Takes one argument.', 1, /^[\w-]+$/, Set[]].freeze
10
+
11
+ def mkdir(options)
12
+ dirname, = Usage.new(options, *MKDIR_USAGE).args
13
+ raise "#{dirname} exists!" if File.exist? dirname
14
+
15
+ info = Info.new(dirname:)
16
+ Cache.new(info).make
17
+ end
18
+ end
19
+ end