tocer 15.2.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 243224018a4fff16b6b0127a6131ef9ac45268a6eb8324b80093ca401901017b
4
- data.tar.gz: f6c960e90162dc393b6e79f1aef75d87cf861b7aeda7daedd02a5e0dfc6e2b19
3
+ metadata.gz: 832f39f67b1d9fc4b4be22d308e7526cb16e2b7a4f352102e79636fc1e8299c9
4
+ data.tar.gz: 5c7f2a4671d6b2b3f83dad7188d0e75b636911bfb9adc293996c9446d058f5f7
5
5
  SHA512:
6
- metadata.gz: f224aeeca9421ed4b9d0aa9f2a97f172ff10b82051e5aaeb7425bc49259f898aece309080d2996f198907f0dee36b2722738c53d901719df6af6df118d32cec0
7
- data.tar.gz: b9beb16da6edd1c70876e3b8477939f0084ca794566a05d4bc64d4727acddf2c7e252b59cb6183dea12f97159cda930fd7de8439a47ad9762fc8648d32b797d2
6
+ metadata.gz: adbd726db1d8b5dfe370c0436173513189fc730390e2b8dca8dac953aeea15d852425ddb35b7e74b9d7f36fa8ddcf9d501fc8210503538f46b2eaf34145d938a
7
+ data.tar.gz: dc21ad6f148f3d1e9566fd842aeee2d9ce48db4a4a0c94b95f601709a2c9b6a9335563f52d18066c443b15d0dd85e68bc55d3a970e4a2879f492ecd64b3c7784
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -58,15 +58,18 @@ bundle add tocer
58
58
  From the command line, run: `tocer --help`
59
59
 
60
60
  ....
61
- USAGE:
62
- -c, --config ACTION Manage gem configuration: edit or view.
63
- -h, --help Show this message.
64
- -i, --insert [PATH] Insert/update table of contents. Default: ".".
65
- -v, --version Show gem version.
66
-
67
- OPTIONS:
68
- --includes [a,b,c] Add include patterns. Default: ["README.md"].
69
- --label [LABEL] Add label. Default: "## Table of Contents".
61
+ USAGE
62
+ tocer [OPTIONS]
63
+ tocer COMMAND [OPTIONS]
64
+
65
+ OPTIONS
66
+ -v, --version Show version.
67
+ -h, --help [COMMAND] Show this message.
68
+
69
+ COMMANDS
70
+ config Manage configuration.
71
+ Path is dynamic per current directory.
72
+ upsert Update/insert table of contents.
70
73
  ....
71
74
 
72
75
  To generate the table of contents at a specific position within your Markdown files, add the
@@ -93,10 +96,10 @@ The default configuration is as follows:
93
96
 
94
97
  [source,yaml]
95
98
  ----
96
- :label: "## Table of Contents"
97
- :includes:
99
+ label: "## Table of Contents"
100
+ patterns:
98
101
  - "README.md"
99
- :root_dir: "."
102
+ root_dir: "."
100
103
  ----
101
104
 
102
105
  Feel free to take this default configuration, modify, and save as your own custom
@@ -105,7 +108,7 @@ Feel free to take this default configuration, modify, and save as your own custo
105
108
  The `configuration.yml` file can be configured as follows:
106
109
 
107
110
  * `label`: The header label for the table of contents.
108
- * `includes`: The list of included files.
111
+ * `patterns`: The list of included files.
109
112
  * `root_dir`: The root path to use for processing files.
110
113
 
111
114
  There are multiple ways the include list can be defined. Here are some examples:
@@ -113,22 +116,22 @@ There are multiple ways the include list can be defined. Here are some examples:
113
116
  [source,yaml]
114
117
  ----
115
118
  # Use an empty array to ignore all files:
116
- :includes: []
119
+ :patterns: []
117
120
 
118
121
  # Use an array of wildcards for groups of files with similar extensions:
119
- :includes:
122
+ :patterns:
120
123
  - "*.md"
121
124
  - "*.mkd"
122
125
  - "*.markdown"
123
126
 
124
127
  # Use a mix of wild cards and relative names/paths to customized as necessary:
125
- :includes:
128
+ :patterns:
126
129
  - "README.md"
127
130
  - "docs/*.md"
128
131
  - "*.markdown"
129
132
 
130
133
  # Use a recursive glob to traverse and update all sub-directories:
131
- :includes:
134
+ :patterns:
132
135
  - "**/*.md"
133
136
  ----
134
137
 
data/lib/tocer/builder.rb CHANGED
@@ -20,7 +20,7 @@ module Tocer
20
20
 
21
21
  def unbuildable?(lines) = comment_block.empty?(lines) && headers(lines).empty?
22
22
 
23
- def call lines, label: Configuration::Loader.call.label
23
+ def call lines, label: Container[:configuration].label
24
24
  return "" if headers(lines).empty?
25
25
 
26
26
  url_count.clear
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+ require "sod"
5
+
6
+ module Tocer
7
+ module CLI
8
+ module Actions
9
+ # Stores table of contents label.
10
+ class Label < Sod::Action
11
+ include Import[:inputs]
12
+
13
+ using Refinements::Structs
14
+
15
+ description "Set label."
16
+
17
+ on %w[-l --label], argument: "[TEXT]"
18
+
19
+ default { Container[:configuration].label }
20
+
21
+ def call(label = default) = inputs.merge!(label:)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+ require "sod"
5
+
6
+ module Tocer
7
+ module CLI
8
+ module Actions
9
+ # Stores table of contents file patterns.
10
+ class Pattern < Sod::Action
11
+ include Import[:inputs]
12
+
13
+ using Refinements::Structs
14
+
15
+ description "Set file patterns."
16
+
17
+ on %w[-p --patterns], argument: "[a,b,c]"
18
+
19
+ default { Container[:configuration].patterns }
20
+
21
+ def call(patterns = default) = inputs.merge! patterns: Array(patterns)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+ require "sod"
5
+
6
+ module Tocer
7
+ module CLI
8
+ module Actions
9
+ # Stores table of contents root path.
10
+ class Root < Sod::Action
11
+ include Import[:inputs]
12
+
13
+ using Refinements::Structs
14
+
15
+ description "Set root directory."
16
+
17
+ on %w[-r --root], argument: "[PATH]"
18
+
19
+ default { Container[:configuration].root_dir }
20
+
21
+ def call(path = default) = inputs.merge! root_dir: Pathname(path)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "refinements/structs"
5
+ require "sod"
6
+
7
+ module Tocer
8
+ module CLI
9
+ module Commands
10
+ # Stores table of contents root path.
11
+ class Upsert < Sod::Command
12
+ include Import[:inputs, :kernel]
13
+
14
+ handle "upsert"
15
+
16
+ description "Update/insert table of contents."
17
+
18
+ on Actions::Root
19
+ on Actions::Label
20
+ on Actions::Pattern
21
+
22
+ def initialize(runner: Runner.new, **)
23
+ super(**)
24
+ @runner = runner
25
+ end
26
+
27
+ def call = runner.call inputs
28
+
29
+ private
30
+
31
+ attr_reader :runner
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,36 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "core"
3
+ require "sod"
4
4
 
5
5
  module Tocer
6
6
  module CLI
7
7
  # The main Command Line Interface (CLI) object.
8
8
  class Shell
9
- include Actions::Import[:config, :insert, :kernel, :logger, :specification]
9
+ include Import[:defaults_path, :xdg_config, :specification]
10
10
 
11
- def initialize(parser: Parser.new, **)
11
+ def initialize(context: Sod::Context, dsl: Sod, **)
12
12
  super(**)
13
- @parser = parser
13
+ @context = context
14
+ @dsl = dsl
14
15
  end
15
16
 
16
- def call arguments = Core::EMPTY_ARRAY
17
- act_on parser.call(arguments)
18
- rescue OptionParser::ParseError => error
19
- logger.error { error.message }
20
- end
17
+ def call(...) = cli.call(...)
21
18
 
22
19
  private
23
20
 
24
- attr_reader :parser
21
+ attr_reader :context, :dsl
22
+
23
+ def cli
24
+ context = build_context
25
25
 
26
- def act_on configuration
27
- case configuration
28
- in action_config: Symbol => action then config.call action
29
- in action_insert: true then insert.call configuration
30
- in action_version: true then kernel.puts specification.labeled_version
31
- else kernel.puts parser.to_s
26
+ dsl.new :tocer, banner: specification.banner do
27
+ on(Sod::Prefabs::Commands::Config, context:)
28
+ on Commands::Upsert
29
+ on(Sod::Prefabs::Actions::Version, context:)
30
+ on Sod::Prefabs::Actions::Help, self
32
31
  end
33
32
  end
33
+
34
+ def build_context
35
+ context[defaults_path:, xdg_config:, version_label: specification.labeled_version]
36
+ end
34
37
  end
35
38
  end
36
39
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/schema"
4
+ require "etcher"
5
+
6
+ Dry::Schema.load_extensions :monads
7
+
8
+ module Tocer
9
+ module Configuration
10
+ Contract = Dry::Schema.Params do
11
+ required(:label).filled :string
12
+ required(:patterns).array :string
13
+ required(:root_dir).filled Etcher::Types::Pathname
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
- :label: "## Table of Contents"
2
- :includes:
1
+ label: "## Table of Contents"
2
+ patterns:
3
3
  - "README.md"
4
- :root_dir: "."
4
+ root_dir: "."
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tocer
4
+ module Configuration
5
+ # Defines the content of the configuration for use throughout the gem.
6
+ Model = Struct.new :label, :root_dir, :patterns do
7
+ def initialize(**)
8
+ super
9
+ self[:patterns] = Array patterns
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "cogger"
4
4
  require "dry-container"
5
+ require "etcher"
6
+ require "runcom"
5
7
  require "spek"
6
8
 
7
9
  module Tocer
@@ -9,7 +11,19 @@ module Tocer
9
11
  module Container
10
12
  extend Dry::Container::Mixin
11
13
 
12
- register(:configuration) { Configuration::Loader.call }
14
+ register :configuration do
15
+ self[:defaults].add_loader(Etcher::Loaders::YAML.new(self[:xdg_config].active))
16
+ .then { |registry| Etcher.call registry }
17
+ end
18
+
19
+ register :defaults do
20
+ Etcher::Registry.new(contract: Configuration::Contract, model: Configuration::Model)
21
+ .add_loader(Etcher::Loaders::YAML.new(self[:defaults_path]))
22
+ end
23
+
24
+ register(:inputs, memoize: true) { self[:configuration].dup }
25
+ register(:defaults_path) { Pathname(__dir__).join("configuration/defaults.yml") }
26
+ register(:xdg_config) { Runcom::Config.new "tocer/configuration.yml" }
13
27
  register(:specification) { Spek::Loader.call "#{__dir__}/../../tocer.gemspec" }
14
28
  register(:kernel) { Kernel }
15
29
  register(:logger) { Cogger.new formatter: :emoji }
@@ -19,8 +19,8 @@ module Tocer
19
19
  end
20
20
 
21
21
  def call
22
- desc "Insert/Update Table of Contents"
23
- task :toc, %i[label includes] do |_task, arguments|
22
+ desc "Update/Insert Table of Contents"
23
+ task :toc, %i[label patterns] do |_task, arguments|
24
24
  runner.call configuration.merge(arguments.to_h)
25
25
  end
26
26
  end
data/lib/tocer/runner.rb CHANGED
@@ -5,18 +5,23 @@ require "refinements/pathnames"
5
5
  module Tocer
6
6
  # Generates/updates Table of Contents for files in root path.
7
7
  class Runner
8
+ include Import[:kernel]
9
+
8
10
  using Refinements::Pathnames
9
11
 
10
- def initialize writer: Writer.new
12
+ def initialize(writer: Writer.new, **)
13
+ super(**)
11
14
  @writer = writer
12
15
  end
13
16
 
14
- def call configuration = Container[:configuration]
15
- Pathname(configuration.root_dir).files(%({#{configuration.includes.join ","}}))
16
- .each do |path|
17
- yield path if block_given?
18
- writer.call path, label: configuration.label
19
- end
17
+ # :reek:FeatureEnvy
18
+ def call configuration
19
+ configuration.root_dir
20
+ .files(%({#{configuration.patterns.join ","}}))
21
+ .each do |path|
22
+ kernel.puts " #{path}"
23
+ writer.call path, label: configuration.label
24
+ end
20
25
  end
21
26
 
22
27
  private
data/lib/tocer/writer.rb CHANGED
@@ -24,7 +24,7 @@ module Tocer
24
24
  @builder = builder
25
25
  end
26
26
 
27
- def call path, label: Configuration::Loader.call.label
27
+ def call path, label: Container[:configuration].label
28
28
  path.rewrite do |body|
29
29
  lines = body.each_line.to_a
30
30
  builder.prependable?(lines) ? prepend(lines, label) : replace(lines, label)
data/tocer.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "tocer"
5
- spec.version = "15.2.0"
5
+ spec.version = "16.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/tocer"
9
- spec.summary = "A command line interface for generating table of contents for Markdown files."
9
+ spec.summary = "A command line interface for generating Markdown table of contents."
10
10
  spec.license = "Hippocratic-2.1"
11
11
 
12
12
  spec.metadata = {
@@ -23,13 +23,16 @@ Gem::Specification.new do |spec|
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
25
  spec.required_ruby_version = "~> 3.2"
26
- spec.add_dependency "cogger", "~> 0.8"
26
+ spec.add_dependency "cogger", "~> 0.10"
27
27
  spec.add_dependency "core", "~> 0.1"
28
28
  spec.add_dependency "dry-container", "~> 0.11"
29
- spec.add_dependency "infusible", "~> 1.0"
30
- spec.add_dependency "refinements", "~> 10.0"
31
- spec.add_dependency "runcom", "~> 9.0"
32
- spec.add_dependency "spek", "~> 1.0"
29
+ spec.add_dependency "dry-schema", "~> 1.13"
30
+ spec.add_dependency "etcher", "~> 0.2"
31
+ spec.add_dependency "infusible", "~> 2.0"
32
+ spec.add_dependency "refinements", "~> 11.0"
33
+ spec.add_dependency "runcom", "~> 10.0"
34
+ spec.add_dependency "sod", "~> 0.0"
35
+ spec.add_dependency "spek", "~> 2.0"
33
36
  spec.add_dependency "zeitwerk", "~> 2.6"
34
37
 
35
38
  spec.bindir = "exe"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tocer
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.2.0
4
+ version: 16.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-04-13 00:00:00.000000000 Z
38
+ date: 2023-06-16 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: cogger
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.8'
46
+ version: '0.10'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.8'
53
+ version: '0.10'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: core
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -79,22 +79,64 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0.11'
82
+ - !ruby/object:Gem::Dependency
83
+ name: dry-schema
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.13'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.13'
96
+ - !ruby/object:Gem::Dependency
97
+ name: etcher
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.2'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.2'
82
110
  - !ruby/object:Gem::Dependency
83
111
  name: infusible
84
112
  requirement: !ruby/object:Gem::Requirement
85
113
  requirements:
86
114
  - - "~>"
87
115
  - !ruby/object:Gem::Version
88
- version: '1.0'
116
+ version: '2.0'
89
117
  type: :runtime
90
118
  prerelease: false
91
119
  version_requirements: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - "~>"
94
122
  - !ruby/object:Gem::Version
95
- version: '1.0'
123
+ version: '2.0'
96
124
  - !ruby/object:Gem::Dependency
97
125
  name: refinements
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '11.0'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '11.0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: runcom
98
140
  requirement: !ruby/object:Gem::Requirement
99
141
  requirements:
100
142
  - - "~>"
@@ -108,33 +150,33 @@ dependencies:
108
150
  - !ruby/object:Gem::Version
109
151
  version: '10.0'
110
152
  - !ruby/object:Gem::Dependency
111
- name: runcom
153
+ name: sod
112
154
  requirement: !ruby/object:Gem::Requirement
113
155
  requirements:
114
156
  - - "~>"
115
157
  - !ruby/object:Gem::Version
116
- version: '9.0'
158
+ version: '0.0'
117
159
  type: :runtime
118
160
  prerelease: false
119
161
  version_requirements: !ruby/object:Gem::Requirement
120
162
  requirements:
121
163
  - - "~>"
122
164
  - !ruby/object:Gem::Version
123
- version: '9.0'
165
+ version: '0.0'
124
166
  - !ruby/object:Gem::Dependency
125
167
  name: spek
126
168
  requirement: !ruby/object:Gem::Requirement
127
169
  requirements:
128
170
  - - "~>"
129
171
  - !ruby/object:Gem::Version
130
- version: '1.0'
172
+ version: '2.0'
131
173
  type: :runtime
132
174
  prerelease: false
133
175
  version_requirements: !ruby/object:Gem::Requirement
134
176
  requirements:
135
177
  - - "~>"
136
178
  - !ruby/object:Gem::Version
137
- version: '1.0'
179
+ version: '2.0'
138
180
  - !ruby/object:Gem::Dependency
139
181
  name: zeitwerk
140
182
  requirement: !ruby/object:Gem::Requirement
@@ -164,17 +206,14 @@ files:
164
206
  - exe/tocer
165
207
  - lib/tocer.rb
166
208
  - lib/tocer/builder.rb
167
- - lib/tocer/cli/actions/config.rb
168
- - lib/tocer/cli/actions/container.rb
169
- - lib/tocer/cli/actions/import.rb
170
- - lib/tocer/cli/actions/insert.rb
171
- - lib/tocer/cli/parser.rb
172
- - lib/tocer/cli/parsers/core.rb
173
- - lib/tocer/cli/parsers/flag.rb
209
+ - lib/tocer/cli/actions/label.rb
210
+ - lib/tocer/cli/actions/pattern.rb
211
+ - lib/tocer/cli/actions/root.rb
212
+ - lib/tocer/cli/commands/upsert.rb
174
213
  - lib/tocer/cli/shell.rb
175
- - lib/tocer/configuration/content.rb
214
+ - lib/tocer/configuration/contract.rb
176
215
  - lib/tocer/configuration/defaults.yml
177
- - lib/tocer/configuration/loader.rb
216
+ - lib/tocer/configuration/model.rb
178
217
  - lib/tocer/container.rb
179
218
  - lib/tocer/elements/comment_block.rb
180
219
  - lib/tocer/import.rb
@@ -212,8 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
251
  - !ruby/object:Gem::Version
213
252
  version: '0'
214
253
  requirements: []
215
- rubygems_version: 3.4.12
254
+ rubygems_version: 3.4.14
216
255
  signing_key:
217
256
  specification_version: 4
218
- summary: A command line interface for generating table of contents for Markdown files.
257
+ summary: A command line interface for generating Markdown table of contents.
219
258
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Actions
6
- # Handles the config action.
7
- class Config
8
- include Tocer::Import[:kernel, :logger]
9
-
10
- def initialize(client: Configuration::Loader::CLIENT, **)
11
- super(**)
12
- @client = client
13
- end
14
-
15
- def call selection
16
- case selection
17
- when :edit then edit
18
- when :view then view
19
- else logger.error { "Invalid configuration selection: #{selection}." }
20
- end
21
- end
22
-
23
- private
24
-
25
- attr_reader :client
26
-
27
- def edit = kernel.system("$EDITOR #{client.current}")
28
-
29
- def view = kernel.system("cat #{client.current}")
30
- end
31
- end
32
- end
33
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dry/container"
4
-
5
- module Tocer
6
- module CLI
7
- module Actions
8
- # Provides a single container with application and action specific dependencies.
9
- module Container
10
- extend Dry::Container::Mixin
11
-
12
- merge Tocer::Container
13
-
14
- register(:config) { Config.new }
15
- register(:insert) { Insert.new }
16
- end
17
- end
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "infusible"
4
-
5
- module Tocer
6
- module CLI
7
- module Actions
8
- Import = Infusible.with Container
9
- end
10
- end
11
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Actions
6
- # Handles the insert action.
7
- class Insert
8
- include Tocer::Import[:kernel]
9
-
10
- def initialize(runner: Runner.new, **)
11
- super(**)
12
- @runner = runner
13
- end
14
-
15
- def call configuration
16
- runner.call(configuration).each { |path| kernel.puts " #{path}" }
17
- end
18
-
19
- private
20
-
21
- attr_reader :runner
22
- end
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core"
4
- require "optparse"
5
-
6
- module Tocer
7
- module CLI
8
- # Assembles and parses all Command Line Interface (CLI) options.
9
- class Parser
10
- include Import[:configuration]
11
-
12
- CLIENT = OptionParser.new nil, 40, " "
13
- SECTIONS = [Parsers::Core, Parsers::Flag].freeze # Order matters.
14
-
15
- def initialize(sections: SECTIONS, client: CLIENT, **)
16
- super(**)
17
- @sections = sections
18
- @client = client
19
- @configuration_duplicate = configuration.dup
20
- end
21
-
22
- def call arguments = Core::EMPTY_ARRAY
23
- sections.each { |parser| parser.call configuration_duplicate, client: }
24
- client.parse arguments
25
- configuration_duplicate.freeze
26
- end
27
-
28
- def to_s = client.to_s
29
-
30
- private
31
-
32
- attr_reader :sections, :client, :configuration_duplicate
33
- end
34
- end
35
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core"
4
- require "refinements/structs"
5
-
6
- module Tocer
7
- module CLI
8
- module Parsers
9
- # Handles parsing of Command Line Interface (CLI) core options.
10
- class Core
11
- include Import[:specification]
12
-
13
- using Refinements::Structs
14
-
15
- def self.call(...) = new(...).call
16
-
17
- def initialize(configuration = Container[:configuration], client: Parser::CLIENT, **)
18
- super(**)
19
- @configuration = configuration
20
- @client = client
21
- end
22
-
23
- def call arguments = ::Core::EMPTY_ARRAY
24
- client.banner = specification.labeled_summary
25
- client.separator "\nUSAGE:\n"
26
- collate
27
- client.parse arguments
28
- configuration
29
- end
30
-
31
- private
32
-
33
- attr_reader :configuration, :client
34
-
35
- def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
36
-
37
- def add_config
38
- client.on(
39
- "-c",
40
- "--config ACTION",
41
- %i[edit view],
42
- "Manage gem configuration: edit or view."
43
- ) do |action|
44
- configuration.merge! action_config: action
45
- end
46
- end
47
-
48
- def add_insert
49
- root_dir = configuration.root_dir
50
-
51
- client.on(
52
- "-i",
53
- "--insert [PATH]",
54
- %(Insert/update table of contents. Default: "#{root_dir}".)
55
- ) do |path|
56
- configuration.merge! action_insert: true, root_dir: path || root_dir
57
- end
58
- end
59
-
60
- def add_version
61
- client.on "-v", "--version", "Show gem version." do
62
- configuration.merge! action_version: true
63
- end
64
- end
65
-
66
- def add_help
67
- client.on "-h", "--help", "Show this message." do
68
- configuration.merge! action_help: true
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core"
4
- require "refinements/structs"
5
-
6
- module Tocer
7
- module CLI
8
- module Parsers
9
- # Handles parsing of Command Line Interface (CLI) flags.
10
- class Flag
11
- using Refinements::Structs
12
-
13
- def self.call(...) = new(...).call
14
-
15
- def initialize configuration = Container[:configuration], client: Parser::CLIENT
16
- @configuration = configuration
17
- @client = client
18
- end
19
-
20
- def call arguments = ::Core::EMPTY_ARRAY
21
- client.separator "\nOPTIONS:\n"
22
- private_methods.sort.grep(/add_/).each { |method| __send__ method }
23
- client.parse arguments
24
- configuration
25
- end
26
-
27
- private
28
-
29
- attr_reader :configuration, :client
30
-
31
- def add_label
32
- client.on(
33
- "--label [LABEL]",
34
- %(Add label. Default: "#{configuration.label}".)
35
- ) do |value|
36
- configuration.merge! label: value if value
37
- end
38
- end
39
-
40
- def add_include
41
- client.on(
42
- "--includes [a,b,c]",
43
- Array,
44
- %(Add include patterns. Default: #{configuration.includes}.)
45
- ) do |items|
46
- configuration.merge! includes: items if items
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module Configuration
5
- # Defines the content of the configuration for use throughout the gem.
6
- Content = Struct.new(
7
- :action_config,
8
- :action_help,
9
- :action_insert,
10
- :action_version,
11
- :includes,
12
- :label,
13
- :root_dir,
14
- keyword_init: true
15
- ) do
16
- def initialize *arguments
17
- super
18
- freeze
19
- end
20
- end
21
- end
22
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- require "refinements/structs"
5
- require "runcom"
6
- require "yaml"
7
-
8
- module Tocer
9
- module Configuration
10
- # Represents the fully assembled Command Line Interface (CLI) configuration.
11
- class Loader
12
- using Refinements::Structs
13
-
14
- DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
15
- CLIENT = Runcom::Config.new "tocer/configuration.yml", defaults: DEFAULTS
16
-
17
- def self.call = new.call
18
-
19
- def self.with_defaults = new(client: DEFAULTS)
20
-
21
- def initialize content: Content.new, client: CLIENT
22
- @content = content
23
- @client = client
24
- end
25
-
26
- def call = content.merge(**client.to_h)
27
-
28
- private
29
-
30
- attr_reader :content, :client
31
- end
32
- end
33
- end