pragmater 12.2.0 → 13.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: 882b859ccab89edc6bc3ac8087e2fc01b55eaed5d3e4e1e789a7635fd77bd485
4
- data.tar.gz: ee6d15c015fa56a52f7deecdb7ce58cc1561957cdc2f17e39ead1ee67972f74a
3
+ metadata.gz: 7b8bbafa69b9ca2657b65492b451e9117b45f9ccb997d7a2eee400ca545a470d
4
+ data.tar.gz: 46979ac45da1860b2153bd1fcb0b60861bd0ed1ff4280d087b878ec2bdfe1ff1
5
5
  SHA512:
6
- metadata.gz: '0847fdb2ab90ef4911a85a4c294dd00f2990477fadfa3cafac1785a6e92b2dc2e32f91a895b0102c48a542115dea1fee42a96ab96bbddf445e2a579bde70ccbf'
7
- data.tar.gz: e1508b6eb3c052277f345d6444b4e6d11372a00a59632816975f6b17fbc3a72fbfa6e6f95f9715a8a1333f689898fa5b469d1a444f8f0d6c8cd9a9002b445529
6
+ metadata.gz: f43c0b2fe3751f48ab99d9f2ee9d21b81feeb1992bef7f692d3efe91dc50181c80fa2c9563fdaed7ad89e30608330a35f3bb1d6f682245c52385283e7772d7ad
7
+ data.tar.gz: 19996ab2e495ff39396f5e45c8bed0caad1799d40a6a2f56a91ccb4af73d89d0725a441234065872570568d899cfdafd69420f88dbc33d1485abe98afbca745b
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -58,27 +58,30 @@ gem install pragmater
58
58
  From the command line, type: `pragmater --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 pragmas. Default: ".".
65
- -r, --remove [PATH] Remove pragmas. Default: ".".
66
- -v, --version Show gem version.
67
-
68
- OPTIONS:
69
- --comments a,b,c Add pragma comments. Default: [].
70
- --includes a,b,c Add include patterns. Default: [].
61
+ USAGE
62
+ pragmater [OPTIONS]
63
+ pragmater 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
+ insert Insert pragma comments.
73
+ remove Remove pragma comments.
71
74
  ....
72
75
 
73
- Both the `--insert` and `--remove` commands support the same options for specifying pragmas and/or
76
+ Both the `insert` and `remove` commands support the same options for specifying pragmas and/or
74
77
  included files. Example:
75
78
 
76
79
  [source,bash]
77
80
  ----
78
- pragmater --insert --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
81
+ pragmater insert --comments "# frozen_string_literal: true" --patterns "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
79
82
  ----
80
83
 
81
- The `--insert` and `--remove` commands default to the current working directory so a path isn’t
84
+ The `insert` and `remove` commands default to the current working directory so a path isn’t
82
85
  necessary unless you want to run Pragmater in a directory structure other than your current working
83
86
  directory.
84
87
 
@@ -93,9 +96,9 @@ The default configuration is as follows:
93
96
 
94
97
  [source,yaml]
95
98
  ----
96
- :comments: []
97
- :includes: []
98
- :root_dir: "."
99
+ comments: []
100
+ patterns: []
101
+ root_dir: "."
99
102
  ----
100
103
 
101
104
  Feel free to take the above configuration, modify, and save as your own custom `configuration.yml`.
@@ -246,7 +249,7 @@ freeze strings.
246
249
  === Consistency
247
250
 
248
251
  As an added bonus, this gem ensures pragmas for all analyzed files are formatted in a consistent
249
- style. This means there is always a space after the octothorpe (`#`). Here are multiple pragmas
252
+ style. This means there is always a space after the octothorp (`#`). Here are multiple pragmas
250
253
  presented together for a visual comparison:
251
254
 
252
255
  [source,ruby]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+ require "sod"
5
+
6
+ module Pragmater
7
+ module CLI
8
+ module Actions
9
+ # Stores pragma comments.
10
+ class Comment < Sod::Action
11
+ include Import[:inputs]
12
+
13
+ using Refinements::Structs
14
+
15
+ description "Set pragma comments."
16
+
17
+ on %w[-c --comments], argument: "[a,b,c]"
18
+
19
+ default { Container[:configuration].patterns }
20
+
21
+ def call(comments = default) = inputs.merge! comments: Array(comments)
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 Pragmater
7
+ module CLI
8
+ module Actions
9
+ # Stores 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 Pragmater
7
+ module CLI
8
+ module Actions
9
+ # Stores 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,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sod"
4
+
5
+ module Pragmater
6
+ module CLI
7
+ module Commands
8
+ # Inserts pragmas.
9
+ class Insert < Sod::Command
10
+ include Import[:inputs, :kernel]
11
+
12
+ handle "insert"
13
+
14
+ description "Insert pragma comments."
15
+
16
+ on Actions::Root
17
+ on Actions::Comment
18
+ on Actions::Pattern
19
+
20
+ def initialize(handler: Inserter.new, **)
21
+ super(**)
22
+ @handler = handler
23
+ end
24
+
25
+ def call = handler.call(inputs) { |path| kernel.puts path }
26
+
27
+ private
28
+
29
+ attr_reader :handler
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sod"
4
+
5
+ module Pragmater
6
+ module CLI
7
+ module Commands
8
+ # Removes pragmas.
9
+ class Remove < Sod::Command
10
+ include Import[:inputs, :kernel]
11
+
12
+ handle "remove"
13
+
14
+ description "Remove pragma comments."
15
+
16
+ on Actions::Root
17
+ on Actions::Comment
18
+ on Actions::Pattern
19
+
20
+ def initialize(handler: Remover.new, **)
21
+ super(**)
22
+ @handler = handler
23
+ end
24
+
25
+ def call = handler.call(inputs) { |path| kernel.puts path }
26
+
27
+ private
28
+
29
+ attr_reader :handler
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,36 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "core"
3
+ require "sod"
4
4
 
5
5
  module Pragmater
6
6
  module CLI
7
7
  # The main Command Line Interface (CLI) object.
8
8
  class Shell
9
- include Actions::Import[:config, :kernel, :logger, :run, :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} | {action_remove: true} then run.call configuration
30
- in action_version: true then kernel.puts specification.labeled_version
31
- else kernel.puts parser.to_s
26
+ dsl.new :pragmater, banner: specification.banner do
27
+ on(Sod::Prefabs::Commands::Config, context:)
28
+ on Commands::Insert
29
+ on Commands::Remove
30
+ on(Sod::Prefabs::Actions::Version, context:)
31
+ on Sod::Prefabs::Actions::Help, self
32
32
  end
33
33
  end
34
+
35
+ def build_context
36
+ context[defaults_path:, xdg_config:, version_label: specification.labeled_version]
37
+ end
34
38
  end
35
39
  end
36
40
  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 Pragmater
9
+ module Configuration
10
+ Contract = Dry::Schema.Params do
11
+ required(:comments).array :string
12
+ required(:patterns).array :string
13
+ required(:root_dir).filled Etcher::Types::Pathname
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
- :comments: []
2
- :includes: []
3
- :root_dir: "."
1
+ comments: []
2
+ patterns: []
3
+ root_dir: "."
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pragmater
4
+ module Configuration
5
+ # Defines the content of the configuration for use throughout the gem.
6
+ Model = Struct.new(
7
+ :comments,
8
+ :patterns,
9
+ :root_dir
10
+ ) do
11
+ def initialize(**)
12
+ super
13
+ self[:comments] = Array comments
14
+ self[:patterns] = Array patterns
15
+ end
16
+ end
17
+ end
18
+ 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 Pragmater
@@ -9,7 +11,20 @@ module Pragmater
9
11
  module Container
10
12
  extend Dry::Container::Mixin
11
13
 
12
- register(:configuration) { Configuration::Loader.call }
14
+ # :nocov:
15
+ register :configuration do
16
+ self[:defaults].add_loader(Etcher::Loaders::YAML.new(self[:xdg_config].active))
17
+ .then { |registry| Etcher.call registry }
18
+ end
19
+
20
+ register :defaults do
21
+ Etcher::Registry.new(contract: Configuration::Contract, model: Configuration::Model)
22
+ .add_loader(Etcher::Loaders::YAML.new(self[:defaults_path]))
23
+ end
24
+
25
+ register(:inputs, memoize: true) { self[:configuration].dup }
26
+ register(:defaults_path) { Pathname(__dir__).join("configuration/defaults.yml") }
27
+ register(:xdg_config) { Runcom::Config.new "pragmater/configuration.yml" }
13
28
  register(:specification) { Spek::Loader.call "#{__dir__}/../../pragmater.gemspec" }
14
29
  register(:kernel) { Kernel }
15
30
  register(:logger) { Cogger.new formatter: :emoji }
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/pathnames"
4
+
5
+ module Pragmater
6
+ # Inserts pragma comments.
7
+ class Inserter
8
+ using Refinements::Pathnames
9
+
10
+ def initialize parser: Parsers::File.new
11
+ @parser = parser
12
+ end
13
+
14
+ def call configuration = Container[:configuration]
15
+ Pathname(configuration.root_dir).files("{#{configuration.patterns.join ","}}").map do |path|
16
+ yield path if block_given?
17
+ path.write parser.call(path, configuration.comments, action: :insert).join
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :parser
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/pathnames"
4
+
5
+ module Pragmater
6
+ # Removes pragma comments.
7
+ class Remover
8
+ using Refinements::Pathnames
9
+
10
+ def initialize parser: Parsers::File.new
11
+ @parser = parser
12
+ end
13
+
14
+ def call configuration = Container[:configuration]
15
+ Pathname(configuration.root_dir).files("{#{configuration.patterns.join ","}}").map do |path|
16
+ yield path if block_given?
17
+ path.write parser.call(path, configuration.comments, action: :remove).join
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :parser
24
+ end
25
+ end
data/pragmater.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "pragmater"
5
- spec.version = "12.2.0"
5
+ spec.version = "13.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/pragmater"
9
- spec.summary = "A command line interface for managing/formatting source file pragma comments."
9
+ spec.summary = "A command line interface for managing pragma comments."
10
10
  spec.license = "Hippocratic-2.1"
11
11
 
12
12
  spec.metadata = {
@@ -23,13 +23,15 @@ 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"
27
- spec.add_dependency "core", "~> 0.1"
26
+ spec.add_dependency "cogger", "~> 0.10"
28
27
  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"
28
+ spec.add_dependency "dry-schema", "~> 1.13"
29
+ spec.add_dependency "etcher", "~> 0.2"
30
+ spec.add_dependency "infusible", "~> 2.0"
31
+ spec.add_dependency "refinements", "~> 11.0"
32
+ spec.add_dependency "runcom", "~> 10.0"
33
+ spec.add_dependency "sod", "~> 0.0"
34
+ spec.add_dependency "spek", "~> 2.0"
33
35
  spec.add_dependency "zeitwerk", "~> 2.6"
34
36
 
35
37
  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: pragmater
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.2.0
4
+ version: 13.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,58 +43,86 @@ 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
- name: core
55
+ name: dry-container
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.1'
60
+ version: '0.11'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.1'
67
+ version: '0.11'
68
68
  - !ruby/object:Gem::Dependency
69
- name: dry-container
69
+ name: dry-schema
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.11'
74
+ version: '1.13'
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0.11'
81
+ version: '1.13'
82
+ - !ruby/object:Gem::Dependency
83
+ name: etcher
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.2'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.2'
82
96
  - !ruby/object:Gem::Dependency
83
97
  name: infusible
84
98
  requirement: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: '1.0'
102
+ version: '2.0'
89
103
  type: :runtime
90
104
  prerelease: false
91
105
  version_requirements: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - "~>"
94
108
  - !ruby/object:Gem::Version
95
- version: '1.0'
109
+ version: '2.0'
96
110
  - !ruby/object:Gem::Dependency
97
111
  name: refinements
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '11.0'
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '11.0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: runcom
98
126
  requirement: !ruby/object:Gem::Requirement
99
127
  requirements:
100
128
  - - "~>"
@@ -108,33 +136,33 @@ dependencies:
108
136
  - !ruby/object:Gem::Version
109
137
  version: '10.0'
110
138
  - !ruby/object:Gem::Dependency
111
- name: runcom
139
+ name: sod
112
140
  requirement: !ruby/object:Gem::Requirement
113
141
  requirements:
114
142
  - - "~>"
115
143
  - !ruby/object:Gem::Version
116
- version: '9.0'
144
+ version: '0.0'
117
145
  type: :runtime
118
146
  prerelease: false
119
147
  version_requirements: !ruby/object:Gem::Requirement
120
148
  requirements:
121
149
  - - "~>"
122
150
  - !ruby/object:Gem::Version
123
- version: '9.0'
151
+ version: '0.0'
124
152
  - !ruby/object:Gem::Dependency
125
153
  name: spek
126
154
  requirement: !ruby/object:Gem::Requirement
127
155
  requirements:
128
156
  - - "~>"
129
157
  - !ruby/object:Gem::Version
130
- version: '1.0'
158
+ version: '2.0'
131
159
  type: :runtime
132
160
  prerelease: false
133
161
  version_requirements: !ruby/object:Gem::Requirement
134
162
  requirements:
135
163
  - - "~>"
136
164
  - !ruby/object:Gem::Version
137
- version: '1.0'
165
+ version: '2.0'
138
166
  - !ruby/object:Gem::Dependency
139
167
  name: zeitwerk
140
168
  requirement: !ruby/object:Gem::Requirement
@@ -163,28 +191,27 @@ files:
163
191
  - README.adoc
164
192
  - exe/pragmater
165
193
  - lib/pragmater.rb
166
- - lib/pragmater/cli/actions/config.rb
167
- - lib/pragmater/cli/actions/container.rb
168
- - lib/pragmater/cli/actions/import.rb
169
- - lib/pragmater/cli/actions/run.rb
170
- - lib/pragmater/cli/parser.rb
171
- - lib/pragmater/cli/parsers/core.rb
172
- - lib/pragmater/cli/parsers/flag.rb
194
+ - lib/pragmater/cli/actions/comment.rb
195
+ - lib/pragmater/cli/actions/pattern.rb
196
+ - lib/pragmater/cli/actions/root.rb
197
+ - lib/pragmater/cli/commands/insert.rb
198
+ - lib/pragmater/cli/commands/remove.rb
173
199
  - lib/pragmater/cli/shell.rb
174
- - lib/pragmater/configuration/content.rb
200
+ - lib/pragmater/configuration/contract.rb
175
201
  - lib/pragmater/configuration/defaults.yml
176
- - lib/pragmater/configuration/loader.rb
202
+ - lib/pragmater/configuration/model.rb
177
203
  - lib/pragmater/container.rb
178
204
  - lib/pragmater/formatters/general.rb
179
205
  - lib/pragmater/formatters/main.rb
180
206
  - lib/pragmater/formatters/shebang.rb
181
207
  - lib/pragmater/import.rb
208
+ - lib/pragmater/inserter.rb
182
209
  - lib/pragmater/parsers/comments.rb
183
210
  - lib/pragmater/parsers/file.rb
184
211
  - lib/pragmater/processors/handler.rb
185
212
  - lib/pragmater/processors/inserter.rb
186
213
  - lib/pragmater/processors/remover.rb
187
- - lib/pragmater/runner.rb
214
+ - lib/pragmater/remover.rb
188
215
  - pragmater.gemspec
189
216
  homepage: https://alchemists.io/projects/pragmater
190
217
  licenses:
@@ -212,8 +239,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
239
  - !ruby/object:Gem::Version
213
240
  version: '0'
214
241
  requirements: []
215
- rubygems_version: 3.4.12
242
+ rubygems_version: 3.4.14
216
243
  signing_key:
217
244
  specification_version: 4
218
- summary: A command line interface for managing/formatting source file pragma comments.
245
+ summary: A command line interface for managing pragma comments.
219
246
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pragmater
4
- module CLI
5
- module Actions
6
- # Handles the config action.
7
- class Config
8
- include Pragmater::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 Pragmater
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 Pragmater::Container
13
-
14
- register(:config) { Config.new }
15
- register(:run) { Run.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 Pragmater
6
- module CLI
7
- module Actions
8
- Import = Infusible.with Container
9
- end
10
- end
11
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pragmater
4
- module CLI
5
- module Actions
6
- # Handles insert or remove actions.
7
- class Run
8
- include Pragmater::Import[:kernel]
9
-
10
- def initialize(runner: Runner.new, **)
11
- super(**)
12
- @runner = runner
13
- end
14
-
15
- def call(configuration) = runner.call(configuration) { |path| kernel.puts path }
16
-
17
- private
18
-
19
- attr_reader :runner
20
- end
21
- end
22
- end
23
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core"
4
- require "optparse"
5
-
6
- module Pragmater
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 { |section| section.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 Pragmater
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 "-c",
39
- "--config ACTION",
40
- %i[edit view],
41
- "Manage gem configuration: edit or view." do |action|
42
- configuration.merge! action_config: action
43
- end
44
- end
45
-
46
- def add_insert
47
- client.on "-i", "--insert [PATH]", %(Insert pragmas. Default: "#{root_dir}".) do |path|
48
- configuration.merge! action_insert: true, root_dir: path || root_dir
49
- end
50
- end
51
-
52
- def add_remove
53
- client.on "-r", "--remove [PATH]", %(Remove pragmas. Default: "#{root_dir}".) do |path|
54
- configuration.merge! action_remove: true, root_dir: path || root_dir
55
- end
56
- end
57
-
58
- def add_version
59
- client.on "-v", "--version", "Show gem version." do
60
- configuration.merge! action_version: true
61
- end
62
- end
63
-
64
- def add_help
65
- client.on "-h", "--help", "Show this message." do
66
- configuration.merge! action_help: true
67
- end
68
- end
69
-
70
- def root_dir = configuration.root_dir
71
- end
72
- end
73
- end
74
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "core"
4
- require "refinements/structs"
5
-
6
- module Pragmater
7
- module CLI
8
- module Parsers
9
- # Parses common command line 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
- collate
23
- client.parse arguments
24
- configuration
25
- end
26
-
27
- private
28
-
29
- attr_reader :configuration, :client
30
-
31
- def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
32
-
33
- def add_comments
34
- client.on "--comments a,b,c", Array, "Add pragma comments. Default: []." do |comments|
35
- configuration.merge! comments:
36
- end
37
- end
38
-
39
- def add_includes
40
- client.on "--includes a,b,c", Array, "Add include patterns. Default: []." do |includes|
41
- configuration.merge! includes:
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pragmater
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_remove,
11
- :action_version,
12
- :comments,
13
- :includes,
14
- :root_dir,
15
- keyword_init: true
16
- ) do
17
- def initialize *arguments
18
- super
19
- freeze
20
- end
21
- end
22
- end
23
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- require "refinements/hashes"
5
- require "refinements/structs"
6
- require "runcom"
7
- require "yaml"
8
-
9
- module Pragmater
10
- module Configuration
11
- # Represents the fully assembled Command Line Interface (CLI) configuration.
12
- class Loader
13
- using Refinements::Hashes
14
- using Refinements::Structs
15
-
16
- DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
17
- CLIENT = Runcom::Config.new "pragmater/configuration.yml", defaults: DEFAULTS
18
-
19
- def self.call = new.call
20
-
21
- def self.with_defaults = new(client: DEFAULTS)
22
-
23
- def initialize content: Content.new, client: CLIENT
24
- @content = content
25
- @client = client
26
- end
27
-
28
- def call = content.merge(**client.to_h.flatten_keys)
29
-
30
- private
31
-
32
- attr_reader :content, :client
33
- end
34
- end
35
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/pathnames"
4
-
5
- module Pragmater
6
- # Adds/removes pragma comments for files in given path.
7
- class Runner
8
- include Import[:logger]
9
-
10
- using Refinements::Pathnames
11
-
12
- def initialize(parser: Parsers::File.new, **)
13
- super(**)
14
- @parser = parser
15
- end
16
-
17
- def call configuration = Container[:configuration]
18
- Pathname(configuration.root_dir).files("{#{configuration.includes.join ","}}").map do |path|
19
- yield path if block_given?
20
-
21
- case configuration
22
- in action_insert: true then write path, configuration, :insert
23
- in action_remove: true then write path, configuration, :remove
24
- else logger.error { "Unknown run action. Use insert or remove." }
25
- end
26
- end
27
- end
28
-
29
- private
30
-
31
- attr_reader :parser
32
-
33
- def write path, configuration, action
34
- path.write parser.call(path, configuration.comments, action:).join
35
- end
36
- end
37
- end