pragmater 9.3.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- :insert:
2
- :comments: []
3
- :includes: []
4
- :remove:
5
- :comments: []
6
- :includes: []
@@ -1,38 +0,0 @@
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
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
- require "pathname"
5
- require "runcom"
6
-
7
- module Pragmater
8
- module CLI
9
- module Options
10
- # Merges arguments with configuration for fully assembled configuration for use by shell.
11
- class Merger
12
- DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
13
- CONFIGURATION = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
14
-
15
- def initialize configuration = CONFIGURATION, assembler = Assembler.new
16
- @configuration = configuration
17
- @assembler = assembler
18
- end
19
-
20
- def call arguments = []
21
- assembler.call(arguments).then do |options|
22
- case options
23
- in insert: path, **settings then build_insert_options path, settings
24
- in remove: path, **settings then build_remove_options path, settings
25
- else options
26
- end
27
- end
28
- end
29
-
30
- def configuration_path
31
- configuration.current
32
- end
33
-
34
- def usage
35
- assembler.to_s
36
- end
37
-
38
- private
39
-
40
- attr_reader :configuration, :assembler
41
-
42
- def build_insert_options path, options
43
- {insert: path, **configuration.to_h.fetch(:insert).merge(options)}
44
- end
45
-
46
- def build_remove_options path, options
47
- {remove: path, **configuration.to_h.fetch(:remove).merge(options)}
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pragmater
4
- # Provides context for runner.
5
- Context = Struct.new :action, :root_dir, :comments, :includes, keyword_init: true do
6
- def initialize *arguments
7
- super
8
-
9
- self[:root_dir] ||= "."
10
- self[:comments] = Array comments
11
- self[:includes] = Array includes
12
- end
13
- end
14
- end