tocer 12.2.0 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
metadata.gz.sig CHANGED
Binary file
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Configuration
6
- # Defines the content of the configuration for use throughout the gem.
7
- Content = Struct.new :label, :includes, keyword_init: true
8
- end
9
- end
10
- 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 CLI
10
- module Configuration
11
- # Represents the fully assembled Command Line Interface (CLI) configuration.
12
- class Loader
13
- using Refinements::Structs
14
-
15
- DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
16
- CLIENT = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
17
-
18
- def self.call = new.call
19
-
20
- def initialize content: Content.new, client: CLIENT
21
- @content = content
22
- @client = client
23
- end
24
-
25
- def call = content.merge(**client.to_h)
26
-
27
- private
28
-
29
- attr_reader :content, :client
30
- end
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Parsers
6
- # Assembles and parses all Command Line Interface (CLI) options.
7
- class Assembler
8
- SECTIONS = [Core, Build].freeze # Order is important.
9
-
10
- def initialize configuration: CLI::Configuration::Loader.call,
11
- sections: SECTIONS,
12
- client: CLIENT
13
- @options = configuration.to_h
14
- @sections = sections
15
- @client = client
16
- end
17
-
18
- def call arguments = []
19
- sections.each { |parser| parser.call client: client, options: options }
20
- client.parse! arguments
21
- options
22
- end
23
-
24
- def to_h = options
25
-
26
- def to_s = client.to_s
27
-
28
- private
29
-
30
- attr_reader :options, :sections, :client
31
- end
32
- end
33
- end
34
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Parsers
6
- # Handles parsing of Command Line Interface (CLI) build options.
7
- class Build
8
- def self.call options: {}, configuration: Configuration::Loader.call, client: CLIENT
9
- new(options: options, configuration: configuration, client: client).call
10
- end
11
-
12
- def initialize options: {}, configuration: Configuration::Loader.call, client: CLIENT
13
- @options = options
14
- @configuration = configuration
15
- @client = client
16
- end
17
-
18
- def call arguments = []
19
- client.separator "\nBUILD OPTIONS:\n"
20
- private_methods.sort.grep(/add_/).each { |method| __send__ method }
21
- arguments.empty? ? arguments : client.parse!(arguments)
22
- end
23
-
24
- private
25
-
26
- attr_reader :options, :configuration, :client
27
-
28
- def add_label
29
- client.on(
30
- "-l",
31
- "--label [LABEL]",
32
- %(Label. Default: "#{CLI::Configuration::Loader.call.label}".)
33
- ) do |value|
34
- options[:label] = value || configuration.to_h.fetch(:label)
35
- end
36
- end
37
-
38
- def add_include
39
- client.on(
40
- "-i",
41
- "--includes [a,b,c]",
42
- Array,
43
- %(Include pattern list. Default: #{CLI::Configuration::Loader.call.includes}.)
44
- ) do |value|
45
- list = Array value
46
- options[:includes] = list.empty? ? configuration.to_h.fetch(:includes) : list
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "optparse"
4
-
5
- module Tocer
6
- module CLI
7
- module Parsers
8
- CLIENT = OptionParser.new nil, 40, " "
9
- end
10
- end
11
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Processors
6
- # Handles the Command Line Interface (CLI) for building of table of contents.
7
- class Build
8
- def initialize runner: Runner.new
9
- @runner = runner
10
- end
11
-
12
- def call root_dir = ".", configuration = {}
13
- runner.call(root_dir: root_dir, **configuration.slice(:label, :includes)) do |path|
14
- puts " #{path}"
15
- end
16
- end
17
-
18
- private
19
-
20
- attr_reader :runner
21
- end
22
- end
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- module CLI
5
- module Processors
6
- # Handles the Command Line Interface (CLI) configuration processing.
7
- class Config
8
- def initialize configuration: CLI::Configuration::Loader::CLIENT, kernel: Kernel
9
- @configuration = configuration
10
- @kernel = kernel
11
- end
12
-
13
- def call action
14
- case action
15
- when :edit then edit
16
- when :view then view
17
- else fail StandardError, "Invalid configuration action: #{action}."
18
- end
19
- end
20
-
21
- private
22
-
23
- attr_reader :configuration, :kernel
24
-
25
- def edit = kernel.system("$EDITOR #{configuration.current}")
26
-
27
- def view = kernel.system("cat #{configuration.current}")
28
- end
29
- end
30
- end
31
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tocer
4
- # Gem identity information.
5
- module Identity
6
- NAME = "tocer"
7
- LABEL = "Tocer"
8
- VERSION = "12.2.0"
9
- VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
- SUMMARY = "A command line interface for generating table of contents for Markdown files."
11
- end
12
- end