pragmater 7.2.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE.adoc +1 -1
- data/README.adoc +50 -54
- data/bin/pragmater +4 -3
- data/lib/pragmater.rb +16 -4
- data/lib/pragmater/cli/helper.rb +40 -0
- data/lib/pragmater/cli/options/assembler.rb +45 -0
- data/lib/pragmater/cli/options/configuration.rb +37 -0
- data/lib/pragmater/cli/options/core.rb +56 -0
- data/lib/pragmater/cli/options/defaults.yml +6 -0
- data/lib/pragmater/cli/options/insert_remove.rb +38 -0
- data/lib/pragmater/cli/options/merger.rb +52 -0
- data/lib/pragmater/cli/shell.rb +63 -0
- data/lib/pragmater/context.rb +14 -0
- data/lib/pragmater/formatters/general.rb +34 -0
- data/lib/pragmater/formatters/main.rb +26 -0
- data/lib/pragmater/formatters/shebang.rb +25 -0
- data/lib/pragmater/identity.rb +2 -1
- data/lib/pragmater/parsers/comments.rb +30 -0
- data/lib/pragmater/parsers/file.rb +32 -0
- data/lib/pragmater/processors/handler.rb +25 -0
- data/lib/pragmater/processors/inserter.rb +24 -0
- data/lib/pragmater/processors/remover.rb +24 -0
- data/lib/pragmater/runner.rb +13 -16
- metadata +27 -224
- metadata.gz.sig +2 -3
- data/lib/pragmater/cli.rb +0 -124
- data/lib/pragmater/commenter.rb +0 -32
- data/lib/pragmater/formatter.rb +0 -59
- data/lib/pragmater/writer.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3510b74dca65adfeed1751708bb5f85b1520cf3d226e7ff1493858431666b32f
|
4
|
+
data.tar.gz: 1fcf9908e0de075ae96fc609ffe94209c13dc25676fe3c87b371083601b59451
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 783e0fe7bc7d0c6a2993e2a77f3b4093bd1f9b1e1b272ac014a39805487cb36b8cd8f30958461d5de19f12529b23f10bce188ebb0ed104d95c1d291097192c65
|
7
|
+
data.tar.gz: 40ce62fd3b9a050a951c91c423cb2787f82ffd0de568eaa17ff2e9efcd6351bb4edd860bdaac15c019a6122115ce1e174908a46c87fdc407d0953a82cd1e76cd
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/LICENSE.adoc
CHANGED
@@ -150,7 +150,7 @@ additional liability.
|
|
150
150
|
|
151
151
|
END OF TERMS AND CONDITIONS
|
152
152
|
|
153
|
-
Copyright link:https://www.alchemists.io[
|
153
|
+
Copyright 2015 link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
154
154
|
|
155
155
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
156
156
|
compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
|
data/README.adoc
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
[link=http://badge.fury.io/rb/pragmater]
|
8
8
|
image::https://badge.fury.io/rb/pragmater.svg[Gem Version]
|
9
|
+
[link=https://www.alchemists.io/projects/code_quality]
|
10
|
+
image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
|
9
11
|
[link=https://circleci.com/gh/bkuhlmann/pragmater]
|
10
12
|
image::https://circleci.com/gh/bkuhlmann/pragmater.svg?style=svg[Circle CI Status]
|
11
13
|
|
@@ -21,14 +23,14 @@ Examples:
|
|
21
23
|
----
|
22
24
|
|
23
25
|
With https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released[Ruby 2.3.0], frozen strings
|
24
|
-
are supported via a pragma. This gem provides an easy way to
|
25
|
-
source files in order to benefit from improved memory and concurrency performance.
|
26
|
+
are supported via a pragma. This gem provides an easy way to insert or remove pragmas to single or
|
27
|
+
multiple Ruby source files in order to benefit from improved memory and concurrency performance.
|
26
28
|
|
27
29
|
toc::[]
|
28
30
|
|
29
31
|
== Features
|
30
32
|
|
31
|
-
* Supports
|
33
|
+
* Supports inserting a pragma or multiple pragmas to single or multiple source files.
|
32
34
|
* Supports removing pragma(s) from single or multiple source files.
|
33
35
|
* Supports file list filtering. Defaults to any file.
|
34
36
|
* Ensures duplicate pragmas never exist.
|
@@ -45,8 +47,6 @@ image::https://www.alchemists.io/images/screencasts/pragmater/cover.svg[Screenca
|
|
45
47
|
|
46
48
|
== Setup
|
47
49
|
|
48
|
-
=== Production
|
49
|
-
|
50
50
|
To install, run:
|
51
51
|
|
52
52
|
[source,bash]
|
@@ -54,55 +54,43 @@ To install, run:
|
|
54
54
|
gem install pragmater
|
55
55
|
----
|
56
56
|
|
57
|
-
=== Development
|
58
|
-
|
59
|
-
To contribute, run:
|
60
|
-
|
61
|
-
[source,bash]
|
62
|
-
----
|
63
|
-
git clone https://github.com/bkuhlmann/pragmater.git
|
64
|
-
cd pragmater
|
65
|
-
bin/setup
|
66
|
-
----
|
67
|
-
|
68
|
-
You can also use the IRB console for direct access to all objects:
|
69
|
-
|
70
|
-
[source,bash]
|
71
|
-
----
|
72
|
-
bin/console
|
73
|
-
----
|
74
|
-
|
75
57
|
== Usage
|
76
58
|
|
77
59
|
=== Command Line Interface (CLI)
|
78
60
|
|
79
|
-
From the command line, type:
|
61
|
+
From the command line, type: `pragmater --help`
|
80
62
|
|
81
63
|
....
|
82
|
-
|
83
|
-
pragmater -c, [--config] # Manage gem configuration.
|
84
|
-
pragmater -h, [--help=COMMAND] # Show this message or get help for a command.
|
85
|
-
pragmater -r, [--remove=PATH] # Remove comments from source file(s).
|
86
|
-
pragmater -v, [--version] # Show gem version.
|
87
|
-
....
|
64
|
+
Pragmater - A command line interface for managing/formatting source file pragma comments.
|
88
65
|
|
89
|
-
|
90
|
-
|
66
|
+
USAGE:
|
67
|
+
-v, --version Show gem version.
|
68
|
+
-h, --help Show this message.
|
69
|
+
-c, --config [options] Manage gem configuration.
|
70
|
+
-i, --insert [PATH] Insert pragam comments into files.
|
71
|
+
-r, --remove [options] Remove pragam comments from files.
|
91
72
|
|
92
|
-
|
93
|
-
|
94
|
-
|
73
|
+
OPTIONS:
|
74
|
+
|
75
|
+
Insert/Remove:
|
76
|
+
--comments a,b,c Add pragma comments.
|
77
|
+
--includes a,b,c Add console support.
|
78
|
+
|
79
|
+
Configuration:
|
80
|
+
--edit Edit configuration.
|
81
|
+
--info Print configuration.
|
95
82
|
....
|
96
83
|
|
97
|
-
|
84
|
+
Both the `--insert` and `--remove` commands support the same options for specifying pragmas and/or
|
85
|
+
included files. Example:
|
98
86
|
|
99
87
|
[source,bash]
|
100
88
|
----
|
101
|
-
pragmater --
|
89
|
+
pragmater --insert --comments "# frozen_string_literal: true" --includes "Gemfile" "Guardfile" "Rakefile" ".gemspec" "config.ru" "bin/**/*" "**/*.rake" "**/*.rb"
|
102
90
|
----
|
103
91
|
|
104
|
-
The `--
|
105
|
-
necessary unless you want to run Pragmater
|
92
|
+
The `--insert` and `--remove` commands default to the current working directory so a path isn’t
|
93
|
+
necessary unless you want to run Pragmater in a directory structure other than your current working
|
106
94
|
directory.
|
107
95
|
|
108
96
|
=== Customization
|
@@ -116,7 +104,7 @@ The default configuration is as follows:
|
|
116
104
|
|
117
105
|
[source,yaml]
|
118
106
|
----
|
119
|
-
:
|
107
|
+
:insert:
|
120
108
|
:comments: []
|
121
109
|
:includes: []
|
122
110
|
:remove:
|
@@ -128,10 +116,10 @@ Feel free to take the above configuration, modify, and save as your own custom `
|
|
128
116
|
|
129
117
|
The `configuration.yml` file can be configured as follows:
|
130
118
|
|
131
|
-
* `
|
132
|
-
and `includes` options can be either a single string or an array.
|
119
|
+
* `insert`: Defines global/local comments and/or file include lists when inserting pragmas. The
|
120
|
+
`comments` and `includes` options can be either a single string or an array of strings.
|
133
121
|
* `remove`: Defines global/local comments and/or file include lists when removing pragmas. The
|
134
|
-
`comments` and `includes` options can be either a single string or an array.
|
122
|
+
`comments` and `includes` options can be either a single string or an array of strings.
|
135
123
|
|
136
124
|
=== Available Pragmas
|
137
125
|
|
@@ -255,17 +243,7 @@ immutable = -"test"
|
|
255
243
|
mutable = +"test"
|
256
244
|
----
|
257
245
|
|
258
|
-
|
259
|
-
to hard to read code. Instead use the following:
|
260
|
-
|
261
|
-
[source,ruby]
|
262
|
-
----
|
263
|
-
immutable = "test".freeze
|
264
|
-
mutable = "test"
|
265
|
-
----
|
266
|
-
|
267
|
-
While this requires extra typing, it expresses intent more clearly. There is a slight caveat to this
|
268
|
-
rule in which the use of `+String#-@+` was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
|
246
|
+
💡 The use of `+String#-@+`, specifically, was http://bit.ly/2DGAjgG[enhanced in Ruby 2.5.0] to
|
269
247
|
_deduplicate_ all instances of the same string thus reducing your memory footprint. This can be
|
270
248
|
valuable in situations where you are not using the frozen string comment and need to selectively
|
271
249
|
freeze strings.
|
@@ -288,6 +266,24 @@ presented together for a visual comparison:
|
|
288
266
|
One oddity to the above is the use of `# !/usr/bin/env ruby` is not allowed but `#! /usr/bin/env
|
289
267
|
ruby` is which is why spacing is slightly different for shell pragmas.
|
290
268
|
|
269
|
+
== Development
|
270
|
+
|
271
|
+
To contribute, run:
|
272
|
+
|
273
|
+
[source,bash]
|
274
|
+
----
|
275
|
+
git clone https://github.com/bkuhlmann/pragmater.git
|
276
|
+
cd pragmater
|
277
|
+
bin/setup
|
278
|
+
----
|
279
|
+
|
280
|
+
You can also use the IRB console for direct access to all objects:
|
281
|
+
|
282
|
+
[source,bash]
|
283
|
+
----
|
284
|
+
bin/console
|
285
|
+
----
|
286
|
+
|
291
287
|
== Tests
|
292
288
|
|
293
289
|
To test, run:
|
data/bin/pragmater
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# TODO: Remove once the Pattern Matching feature is fully supported.
|
5
|
+
Warning[:experimental] = false
|
6
|
+
|
4
7
|
require "pragmater"
|
5
|
-
require "pragmater/cli"
|
6
|
-
require "pragmater/identity"
|
7
8
|
|
8
9
|
Process.setproctitle Pragmater::Identity::VERSION_LABEL
|
9
|
-
Pragmater::CLI.
|
10
|
+
Pragmater::CLI::Shell.new.call ARGV
|
data/lib/pragmater.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "pragmater/identity"
|
4
|
-
require "pragmater/
|
5
|
-
require "pragmater/
|
6
|
-
require "pragmater/
|
4
|
+
require "pragmater/formatters/general"
|
5
|
+
require "pragmater/formatters/shebang"
|
6
|
+
require "pragmater/formatters/main"
|
7
|
+
require "pragmater/parsers/comments"
|
8
|
+
require "pragmater/parsers/file"
|
9
|
+
require "pragmater/processors/inserter"
|
10
|
+
require "pragmater/processors/remover"
|
11
|
+
require "pragmater/processors/handler"
|
12
|
+
require "pragmater/context"
|
7
13
|
require "pragmater/runner"
|
8
|
-
require "pragmater/cli"
|
14
|
+
require "pragmater/cli/options/configuration"
|
15
|
+
require "pragmater/cli/options/insert_remove"
|
16
|
+
require "pragmater/cli/options/core"
|
17
|
+
require "pragmater/cli/options/assembler"
|
18
|
+
require "pragmater/cli/options/merger"
|
19
|
+
require "pragmater/cli/helper"
|
20
|
+
require "pragmater/cli/shell"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "open3"
|
5
|
+
require "logger"
|
6
|
+
|
7
|
+
module Pragmater
|
8
|
+
module CLI
|
9
|
+
# A simple delegator for common shell functionality.
|
10
|
+
class Helper
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
LOGGER = Logger.new STDOUT,
|
14
|
+
formatter: (
|
15
|
+
proc do |_severity, _datetime, _program_name, message|
|
16
|
+
"#{message}\n"
|
17
|
+
end
|
18
|
+
)
|
19
|
+
|
20
|
+
delegate %i[info error fatal debug unknown] => :logger
|
21
|
+
|
22
|
+
def initialize commander: Open3, logger: LOGGER
|
23
|
+
@commander = commander
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def run command
|
28
|
+
commander.capture3 command
|
29
|
+
end
|
30
|
+
|
31
|
+
def warn message
|
32
|
+
logger.warn message
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :commander, :logger
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "forwardable"
|
5
|
+
|
6
|
+
module Pragmater
|
7
|
+
module CLI
|
8
|
+
module Options
|
9
|
+
# Coalesces all options and arguments into a single hash for further processing.
|
10
|
+
class Assembler
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
PARSER = OptionParser.new nil, 40, " "
|
14
|
+
SECTIONS = [Core, InsertRemove, Configuration].freeze
|
15
|
+
|
16
|
+
EXCEPTIONS = [
|
17
|
+
OptionParser::InvalidOption,
|
18
|
+
OptionParser::MissingArgument,
|
19
|
+
OptionParser::InvalidArgument
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
delegate %i[to_s] => :parser
|
23
|
+
|
24
|
+
def initialize sections: SECTIONS, parser: PARSER, exceptions: EXCEPTIONS
|
25
|
+
@sections = sections
|
26
|
+
@parser = parser
|
27
|
+
@options = {}
|
28
|
+
@exceptions = exceptions
|
29
|
+
end
|
30
|
+
|
31
|
+
def call arguments = []
|
32
|
+
sections.each { |section| section.new(options, parser: parser).call }
|
33
|
+
parser.parse! arguments
|
34
|
+
options
|
35
|
+
rescue *EXCEPTIONS
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :parser, :sections, :options, :exceptions
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragmater
|
4
|
+
module CLI
|
5
|
+
module Options
|
6
|
+
# Defines gem configuration options.
|
7
|
+
class Configuration
|
8
|
+
def initialize values, parser: OptionParser.new
|
9
|
+
@parser = parser
|
10
|
+
@values = values
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
parser.separator "\nConfiguration:\n"
|
15
|
+
private_methods.grep(/add_/).each { |method| __send__ method }
|
16
|
+
parser
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :parser, :values
|
22
|
+
|
23
|
+
def add_edit
|
24
|
+
parser.on "--edit", "Edit configuration." do
|
25
|
+
values[:edit] = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_info
|
30
|
+
parser.on "--info", "Print configuration." do
|
31
|
+
values[:info] = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragmater
|
4
|
+
module CLI
|
5
|
+
module Options
|
6
|
+
# Defines gem primary options.
|
7
|
+
class Core
|
8
|
+
def initialize values, parser: OptionParser.new
|
9
|
+
@values = values
|
10
|
+
@parser = parser
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
parser.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
|
15
|
+
parser.separator "\nUSAGE:\n"
|
16
|
+
private_methods.grep(/add_/).each { |method| __send__ method }
|
17
|
+
parser
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :values, :parser
|
23
|
+
|
24
|
+
def add_configuration
|
25
|
+
parser.on "-c", "--config [options]", "Manage gem configuration." do
|
26
|
+
values[:config] = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_insert
|
31
|
+
parser.on "-i", "--insert [PATH]", "Insert pragam comments into files." do |path|
|
32
|
+
values[:insert] = path || "."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_remove
|
37
|
+
parser.on "-r", "--remove [options]", "Remove pragam comments from files." do |path|
|
38
|
+
values[:remove] = path || "."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_version
|
43
|
+
parser.on "-v", "--version", "Show gem version." do
|
44
|
+
values[:version] = Identity::VERSION
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_help
|
49
|
+
parser.on "-h", "--help", "Show this message." do
|
50
|
+
values[:help] = true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragmater
|
4
|
+
module CLI
|
5
|
+
module Options
|
6
|
+
# Defines gem insert and remove options.
|
7
|
+
class InsertRemove
|
8
|
+
def initialize values, parser: OptionParser.new
|
9
|
+
@values = values
|
10
|
+
@parser = parser
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
parser.separator "\nOPTIONS:\n"
|
15
|
+
parser.separator "\nInsert/Remove:\n"
|
16
|
+
private_methods.grep(/add_/).each { |method| __send__ method }
|
17
|
+
parser
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :values, :parser
|
23
|
+
|
24
|
+
def add_comments
|
25
|
+
parser.on "--comments a,b,c", Array, "Add pragma comments." do |comments|
|
26
|
+
values[:comments] = comments
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_includes
|
31
|
+
parser.on "--includes a,b,c", Array, "Add console support." do |includes|
|
32
|
+
values[:includes] = includes
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|