bookbindery 8.5.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bookbinder.gemspec +1 -1
- data/lib/bookbinder/cli.rb +36 -55
- data/lib/bookbinder/commands/bind.rb +3 -19
- data/lib/bookbinder/commands/collection.rb +33 -73
- data/lib/bookbinder/commands/components/command_options.rb +3 -22
- data/lib/bookbinder/commands/generate.rb +0 -11
- data/lib/bookbinder/commands/imprint.rb +3 -10
- data/lib/bookbinder/commands/punch.rb +0 -11
- data/lib/bookbinder/commands/update_local_doc_repos.rb +1 -9
- data/lib/bookbinder/commands/watch.rb +1 -10
- data/lib/bookbinder/config/fetcher.rb +2 -18
- data/lib/bookbinder/preprocessing/dita_html_preprocessor.rb +3 -6
- data/lib/bookbinder/preprocessing/dita_pdf_preprocessor.rb +3 -5
- data/lib/bookbinder/terminal.rb +0 -1
- metadata +3 -31
- data/lib/bookbinder/cf_command_runner.rb +0 -123
- data/lib/bookbinder/command_runner.rb +0 -23
- data/lib/bookbinder/command_validator.rb +0 -51
- data/lib/bookbinder/commands/build_and_push_tarball.rb +0 -38
- data/lib/bookbinder/commands/chain.rb +0 -11
- data/lib/bookbinder/commands/help.rb +0 -70
- data/lib/bookbinder/commands/naming.rb +0 -29
- data/lib/bookbinder/commands/push_from_local.rb +0 -132
- data/lib/bookbinder/commands/push_to_prod.rb +0 -66
- data/lib/bookbinder/commands/run_publish_ci.rb +0 -37
- data/lib/bookbinder/commands/version.rb +0 -29
- data/lib/bookbinder/config/aws_credentials.rb +0 -21
- data/lib/bookbinder/config/cf_credentials.rb +0 -62
- data/lib/bookbinder/config/remote_yaml_credential_provider.rb +0 -22
- data/lib/bookbinder/deploy/app_fetcher.rb +0 -36
- data/lib/bookbinder/deploy/archive.rb +0 -102
- data/lib/bookbinder/deploy/artifact.rb +0 -26
- data/lib/bookbinder/deploy/blue_green_app.rb +0 -29
- data/lib/bookbinder/deploy/cf_routes.rb +0 -32
- data/lib/bookbinder/deploy/deployment.rb +0 -55
- data/lib/bookbinder/deploy/distributor.rb +0 -76
- data/lib/bookbinder/deploy/failure.rb +0 -15
- data/lib/bookbinder/deploy/pusher.rb +0 -34
- data/lib/bookbinder/deploy/success.rb +0 -16
- data/lib/bookbinder/deprecated_logger.rb +0 -33
- data/lib/bookbinder/errors/cli_error.rb +0 -6
- data/lib/bookbinder/legacy/cli.rb +0 -71
- data/lib/bookbinder/preprocessing/dita_preprocessor.rb +0 -17
@@ -1,24 +1,13 @@
|
|
1
|
-
require_relative '../errors/cli_error'
|
2
|
-
require_relative 'naming'
|
3
|
-
|
4
1
|
module Bookbinder
|
5
2
|
module Commands
|
6
3
|
class Punch
|
7
|
-
include Commands::Naming
|
8
|
-
|
9
4
|
def initialize(streams, configuration_fetcher, version_control_system)
|
10
5
|
@streams = streams
|
11
6
|
@configuration_fetcher = configuration_fetcher
|
12
7
|
@version_control_system = version_control_system
|
13
8
|
end
|
14
9
|
|
15
|
-
def usage
|
16
|
-
["punch <git tag>", "Apply the specified <git tag> to your book, sections, and layout repo"]
|
17
|
-
end
|
18
|
-
|
19
10
|
def run((tag, *))
|
20
|
-
raise CliError::InvalidArguments unless tag
|
21
|
-
|
22
11
|
urls(config).each do |url|
|
23
12
|
version_control_system.remote_tag(url, tag, 'HEAD')
|
24
13
|
end
|
@@ -1,23 +1,15 @@
|
|
1
1
|
require_relative '../ingest/destination_directory'
|
2
|
-
require_relative 'naming'
|
3
2
|
|
4
3
|
module Bookbinder
|
5
4
|
module Commands
|
6
5
|
class UpdateLocalDocRepos
|
7
|
-
include Commands::Naming
|
8
|
-
|
9
6
|
def initialize(streams, configuration_fetcher, version_control_system)
|
10
7
|
@streams = streams
|
11
8
|
@configuration_fetcher = configuration_fetcher
|
12
9
|
@version_control_system = version_control_system
|
13
10
|
end
|
14
11
|
|
15
|
-
def
|
16
|
-
[command_name,
|
17
|
-
"Run `git pull` on all sections that exist at the same directory level as your book directory"]
|
18
|
-
end
|
19
|
-
|
20
|
-
def run(_)
|
12
|
+
def run
|
21
13
|
urls = configuration_fetcher.fetch_config.sections.map(&:repo_url)
|
22
14
|
paths(urls).each do |path|
|
23
15
|
streams[:out] << "\nUpdating #{path}:"
|
@@ -1,10 +1,6 @@
|
|
1
|
-
require_relative 'naming'
|
2
|
-
|
3
1
|
module Bookbinder
|
4
2
|
module Commands
|
5
3
|
class Watch
|
6
|
-
include Commands::Naming
|
7
|
-
|
8
4
|
def initialize(streams,
|
9
5
|
middleman_runner: nil,
|
10
6
|
output_locations: nil,
|
@@ -27,12 +23,7 @@ module Bookbinder
|
|
27
23
|
@directory_preparer = directory_preparer
|
28
24
|
end
|
29
25
|
|
30
|
-
def
|
31
|
-
["watch",
|
32
|
-
"Bind and serve a local book, watching for changes"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def run(_)
|
26
|
+
def run
|
36
27
|
watch_config = config_fetcher.fetch_config
|
37
28
|
|
38
29
|
directory_preparer.prepare_directories(
|
@@ -1,15 +1,12 @@
|
|
1
|
-
require_relative 'aws_credentials'
|
2
|
-
require_relative 'cf_credentials'
|
3
1
|
require_relative 'configuration'
|
4
2
|
require_relative 'yaml_loader'
|
5
3
|
|
6
4
|
module Bookbinder
|
7
5
|
module Config
|
8
6
|
class Fetcher
|
9
|
-
def initialize(configuration_validator, loader,
|
7
|
+
def initialize(configuration_validator, loader, config_class)
|
10
8
|
@loader = loader
|
11
9
|
@configuration_validator = configuration_validator
|
12
|
-
@credentials_provider = credentials_provider
|
13
10
|
@config_class = config_class
|
14
11
|
end
|
15
12
|
|
@@ -22,19 +19,6 @@ module Bookbinder
|
|
22
19
|
@config ||= validate(@base_config, @optional_configs)
|
23
20
|
end
|
24
21
|
|
25
|
-
def fetch_credentials(environment = 'null-environment')
|
26
|
-
@credentials ||= credentials_provider.credentials(fetch_config.cred_repo_url)
|
27
|
-
{
|
28
|
-
aws: Config::AwsCredentials.new(
|
29
|
-
@credentials.fetch('aws', {})
|
30
|
-
),
|
31
|
-
cloud_foundry: Config::CfCredentials.new(
|
32
|
-
@credentials.fetch('cloud_foundry', {}),
|
33
|
-
environment
|
34
|
-
)
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
22
|
def set_config_dir_path(config_dir_path)
|
39
23
|
@config_dir_path = File.expand_path(config_dir_path)
|
40
24
|
end
|
@@ -46,7 +30,7 @@ module Bookbinder
|
|
46
30
|
private
|
47
31
|
|
48
32
|
attr_reader(:loader, :configuration_validator, :config, :config_file_path, :config_dir_path,
|
49
|
-
:
|
33
|
+
:config_class)
|
50
34
|
|
51
35
|
def read_config_file
|
52
36
|
loader.load(config_file_path)
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require_relative '../values/subnav_template'
|
2
2
|
require_relative '../../../lib/bookbinder/subnav/json_from_html_toc'
|
3
|
-
require_relative 'dita_preprocessor'
|
4
3
|
|
5
4
|
module Bookbinder
|
6
5
|
module Preprocessing
|
7
|
-
class DitaHTMLPreprocessor
|
6
|
+
class DitaHTMLPreprocessor
|
8
7
|
DitaToHtmlLibraryFailure = Class.new(RuntimeError)
|
9
8
|
|
10
9
|
ACCEPTED_IMAGE_FORMATS = %w(png jpeg jpg svg gif bmp tif tiff eps)
|
@@ -21,16 +20,14 @@ module Bookbinder
|
|
21
20
|
section.subnav_template.include?('dita_subnav') if section.subnav_template
|
22
21
|
end
|
23
22
|
|
24
|
-
def preprocess(sections, output_locations, options:
|
23
|
+
def preprocess(sections, output_locations, options: {}, output_streams: nil, **_)
|
25
24
|
@output_locations = output_locations
|
26
25
|
|
27
|
-
dita_options = dita_flags(options)
|
28
|
-
|
29
26
|
sections.each do |section|
|
30
27
|
if section.path_to_preprocessor_attribute('ditamap_location')
|
31
28
|
convert_dita_files(section,
|
32
29
|
command_creator,
|
33
|
-
|
30
|
+
options[:dita_flags],
|
34
31
|
section_html_dir(section),
|
35
32
|
sheller,
|
36
33
|
output_streams)
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require_relative 'dita_preprocessor'
|
2
|
-
|
3
1
|
module Bookbinder
|
4
2
|
module Preprocessing
|
5
|
-
class DitaPDFPreprocessor
|
3
|
+
class DitaPDFPreprocessor
|
6
4
|
DitaToPDFLibraryFailure = Class.new(RuntimeError)
|
7
5
|
|
8
6
|
def initialize(fs, command_creator, sheller)
|
@@ -15,11 +13,11 @@ module Bookbinder
|
|
15
13
|
!!section.pdf_output_filename
|
16
14
|
end
|
17
15
|
|
18
|
-
def preprocess(sections, output_locations, options:
|
16
|
+
def preprocess(sections, output_locations, options: {}, output_streams: nil, **_)
|
19
17
|
sections.each do |section|
|
20
18
|
command = command_creator.convert_to_pdf_command(
|
21
19
|
section,
|
22
|
-
dita_flags: dita_flags
|
20
|
+
dita_flags: options[:dita_flags],
|
23
21
|
write_to: output_locations.pdf_from_preprocessing_dir
|
24
22
|
)
|
25
23
|
status = sheller.run_command(command, output_streams.to_h)
|
data/lib/bookbinder/terminal.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookbindery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Grafton
|
@@ -22,7 +22,7 @@ authors:
|
|
22
22
|
autorequire:
|
23
23
|
bindir: install_bin
|
24
24
|
cert_chain: []
|
25
|
-
date: 2016-04-
|
25
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
26
26
|
dependencies:
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fog-aws
|
@@ -314,33 +314,20 @@ extra_rdoc_files: []
|
|
314
314
|
files:
|
315
315
|
- bookbinder.gemspec
|
316
316
|
- install_bin/bookbinder
|
317
|
-
- lib/bookbinder/cf_command_runner.rb
|
318
317
|
- lib/bookbinder/cli.rb
|
319
318
|
- lib/bookbinder/code_example_reader.rb
|
320
319
|
- lib/bookbinder/colorizer.rb
|
321
|
-
- lib/bookbinder/command_runner.rb
|
322
|
-
- lib/bookbinder/command_validator.rb
|
323
320
|
- lib/bookbinder/commands/bind.rb
|
324
|
-
- lib/bookbinder/commands/build_and_push_tarball.rb
|
325
|
-
- lib/bookbinder/commands/chain.rb
|
326
321
|
- lib/bookbinder/commands/collection.rb
|
327
322
|
- lib/bookbinder/commands/components/bind/directory_preparer.rb
|
328
323
|
- lib/bookbinder/commands/components/bind/layout_preparer.rb
|
329
324
|
- lib/bookbinder/commands/components/command_options.rb
|
330
325
|
- lib/bookbinder/commands/components/imprint/directory_preparer.rb
|
331
326
|
- lib/bookbinder/commands/generate.rb
|
332
|
-
- lib/bookbinder/commands/help.rb
|
333
327
|
- lib/bookbinder/commands/imprint.rb
|
334
|
-
- lib/bookbinder/commands/naming.rb
|
335
328
|
- lib/bookbinder/commands/punch.rb
|
336
|
-
- lib/bookbinder/commands/push_from_local.rb
|
337
|
-
- lib/bookbinder/commands/push_to_prod.rb
|
338
|
-
- lib/bookbinder/commands/run_publish_ci.rb
|
339
329
|
- lib/bookbinder/commands/update_local_doc_repos.rb
|
340
|
-
- lib/bookbinder/commands/version.rb
|
341
330
|
- lib/bookbinder/commands/watch.rb
|
342
|
-
- lib/bookbinder/config/aws_credentials.rb
|
343
|
-
- lib/bookbinder/config/cf_credentials.rb
|
344
331
|
- lib/bookbinder/config/checkers/archive_menu_checker.rb
|
345
332
|
- lib/bookbinder/config/checkers/ditamap_presence_checker.rb
|
346
333
|
- lib/bookbinder/config/checkers/duplicate_section_name_checker.rb
|
@@ -354,26 +341,13 @@ files:
|
|
354
341
|
- lib/bookbinder/config/fetcher.rb
|
355
342
|
- lib/bookbinder/config/imprint/configuration.rb
|
356
343
|
- lib/bookbinder/config/product_config.rb
|
357
|
-
- lib/bookbinder/config/remote_yaml_credential_provider.rb
|
358
344
|
- lib/bookbinder/config/section_config.rb
|
359
345
|
- lib/bookbinder/config/validator.rb
|
360
346
|
- lib/bookbinder/config/yaml_loader.rb
|
361
347
|
- lib/bookbinder/css_link_checker.rb
|
362
|
-
- lib/bookbinder/deploy/app_fetcher.rb
|
363
|
-
- lib/bookbinder/deploy/archive.rb
|
364
|
-
- lib/bookbinder/deploy/artifact.rb
|
365
|
-
- lib/bookbinder/deploy/blue_green_app.rb
|
366
|
-
- lib/bookbinder/deploy/cf_routes.rb
|
367
|
-
- lib/bookbinder/deploy/deployment.rb
|
368
|
-
- lib/bookbinder/deploy/distributor.rb
|
369
|
-
- lib/bookbinder/deploy/failure.rb
|
370
|
-
- lib/bookbinder/deploy/pusher.rb
|
371
|
-
- lib/bookbinder/deploy/success.rb
|
372
|
-
- lib/bookbinder/deprecated_logger.rb
|
373
348
|
- lib/bookbinder/directory_helpers.rb
|
374
349
|
- lib/bookbinder/dita_command_creator.rb
|
375
350
|
- lib/bookbinder/dita_html_for_middleman_formatter.rb
|
376
|
-
- lib/bookbinder/errors/cli_error.rb
|
377
351
|
- lib/bookbinder/errors/programmer_mistake.rb
|
378
352
|
- lib/bookbinder/html_document_manipulator.rb
|
379
353
|
- lib/bookbinder/ingest/cloner_factory.rb
|
@@ -387,13 +361,11 @@ files:
|
|
387
361
|
- lib/bookbinder/ingest/update_failure.rb
|
388
362
|
- lib/bookbinder/ingest/update_success.rb
|
389
363
|
- lib/bookbinder/ingest/working_copy.rb
|
390
|
-
- lib/bookbinder/legacy/cli.rb
|
391
364
|
- lib/bookbinder/local_filesystem_accessor.rb
|
392
365
|
- lib/bookbinder/middleman_runner.rb
|
393
366
|
- lib/bookbinder/postprocessing/broken_links_checker.rb
|
394
367
|
- lib/bookbinder/preprocessing/dita_html_preprocessor.rb
|
395
368
|
- lib/bookbinder/preprocessing/dita_pdf_preprocessor.rb
|
396
|
-
- lib/bookbinder/preprocessing/dita_preprocessor.rb
|
397
369
|
- lib/bookbinder/preprocessing/link_to_site_gen_dir.rb
|
398
370
|
- lib/bookbinder/preprocessing/preprocessor.rb
|
399
371
|
- lib/bookbinder/server_director.rb
|
@@ -449,7 +421,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
449
421
|
version: '0'
|
450
422
|
requirements: []
|
451
423
|
rubyforge_project:
|
452
|
-
rubygems_version: 2.
|
424
|
+
rubygems_version: 2.6.3
|
453
425
|
signing_key:
|
454
426
|
specification_version: 4
|
455
427
|
summary: Markdown to Rackup application documentation generator
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require_relative 'deploy/blue_green_app'
|
2
|
-
|
3
|
-
module Bookbinder
|
4
|
-
class CfCommandRunner
|
5
|
-
def initialize(streams, sheller, cf_credentials, trace_file)
|
6
|
-
@streams = streams
|
7
|
-
@sheller = sheller
|
8
|
-
@creds = cf_credentials
|
9
|
-
@trace_file = trace_file
|
10
|
-
end
|
11
|
-
|
12
|
-
def login
|
13
|
-
username = creds.username
|
14
|
-
password = creds.password
|
15
|
-
api_endpoint = creds.api_endpoint
|
16
|
-
organization = creds.organization
|
17
|
-
space = creds.space
|
18
|
-
creds_string = (username && password) ? "-u '#{username}' -p '#{password}'" : ''
|
19
|
-
|
20
|
-
result = sheller.run_command(
|
21
|
-
"#{cf_binary_path} login #{creds_string} -a '#{api_endpoint}' -o '#{organization}' -s '#{space}'",
|
22
|
-
streams
|
23
|
-
)
|
24
|
-
raise "Could not log in to #{creds.api_endpoint}" unless result.success?
|
25
|
-
end
|
26
|
-
|
27
|
-
def cf_routes_output
|
28
|
-
sheller.get_stdout("CF_COLOR=false #{cf_binary_path} routes").tap do |output|
|
29
|
-
raise 'failure executing cf routes' if output == ''
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def new_app
|
34
|
-
Deploy::BlueGreenApp.new([creds.app_name, 'blue'].join('-'))
|
35
|
-
end
|
36
|
-
|
37
|
-
def start(deploy_target_app)
|
38
|
-
# Theoretically we shouldn't need this (and corresponding "stop" below), but we've seen CF pull files from both
|
39
|
-
# green and blue when a DNS redirect points to HOST.cfapps.io
|
40
|
-
# Also, shutting down the unused app saves $$
|
41
|
-
sheller.run_command("#{cf_binary_path} start #{deploy_target_app}", streams)
|
42
|
-
end
|
43
|
-
|
44
|
-
def push(deploy_target_app)
|
45
|
-
# Currently --no-routes is used to blow away all existing routes from a newly deployed app.
|
46
|
-
# The routes will then be recreated from the creds repo.
|
47
|
-
result = sheller.run_command(
|
48
|
-
environment_variables,
|
49
|
-
"#{cf_binary_path} push #{deploy_target_app} -b ruby_buildpack -s cflinuxfs2 --no-route -m 256M -i 3",
|
50
|
-
streams
|
51
|
-
)
|
52
|
-
raise "Could not deploy app to #{deploy_target_app}" unless result.success?
|
53
|
-
end
|
54
|
-
|
55
|
-
def unmap_routes(app)
|
56
|
-
creds.flat_routes.each do |domain, host|
|
57
|
-
unmap_route(app, domain, host)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def map_routes(app)
|
62
|
-
succeeded = []
|
63
|
-
|
64
|
-
creds.flat_routes.each do |domain, name|
|
65
|
-
begin
|
66
|
-
map_route(app, domain, name)
|
67
|
-
succeeded << [app, domain, name]
|
68
|
-
rescue RuntimeError
|
69
|
-
succeeded.each { |app, domain, host| unmap_route(app, domain, host) }
|
70
|
-
raise
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def takedown_old_target_app(app)
|
76
|
-
# Routers flush every 10 seconds (but not guaranteed), so wait a bit longer than that.
|
77
|
-
streams[:out].puts "waiting 15 seconds for routes to remap...\n\n"
|
78
|
-
(1..15).to_a.reverse.each do |seconds|
|
79
|
-
streams[:out] << "\r\r#{seconds}... "
|
80
|
-
Kernel.sleep 1
|
81
|
-
end
|
82
|
-
stop(app)
|
83
|
-
unmap_routes(app)
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
attr_reader :creds, :sheller, :streams
|
89
|
-
|
90
|
-
def stop(app)
|
91
|
-
result = sheller.run_command("#{cf_binary_path} stop #{app}", streams)
|
92
|
-
raise "Failed to stop application #{app}" unless result.success?
|
93
|
-
end
|
94
|
-
|
95
|
-
def map_route(deploy_target_app, domain, host)
|
96
|
-
map_route_command = "#{cf_binary_path} map-route #{deploy_target_app} #{domain}"
|
97
|
-
map_route_command += " -n #{host}" unless host.empty?
|
98
|
-
|
99
|
-
result = sheller.run_command(map_route_command, streams)
|
100
|
-
raise "Deployed app to #{deploy_target_app} but failed to map hostname #{host}.#{domain} to it." unless result.success?
|
101
|
-
end
|
102
|
-
|
103
|
-
def unmap_route(deploy_target_app, domain, host)
|
104
|
-
unmap_route_command = "#{cf_binary_path} unmap-route #{deploy_target_app} #{domain}"
|
105
|
-
unmap_route_command += " -n #{host}" unless host.empty?
|
106
|
-
|
107
|
-
result = sheller.run_command(unmap_route_command, streams)
|
108
|
-
raise "Failed to unmap route #{host} on #{deploy_target_app}." unless result.success?
|
109
|
-
end
|
110
|
-
|
111
|
-
def cf_binary_path
|
112
|
-
@cf_binary_path ||= sheller.get_stdout("which cf").tap do |path|
|
113
|
-
if path == ''
|
114
|
-
raise "CF CLI could not be found in your PATH. Please make sure cf cli is in your PATH."
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def environment_variables
|
120
|
-
{'CF_TRACE' => @trace_file}
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'errors/cli_error'
|
2
|
-
|
3
|
-
module Bookbinder
|
4
|
-
class CommandRunner
|
5
|
-
def initialize(logger, commands)
|
6
|
-
@logger = logger
|
7
|
-
@commands = commands
|
8
|
-
end
|
9
|
-
|
10
|
-
def run(command_name, command_arguments)
|
11
|
-
command = commands.detect { |known_command| known_command.command_for?(command_name) }
|
12
|
-
command.run(command_arguments)
|
13
|
-
rescue CliError::InvalidArguments
|
14
|
-
logger.log ["bookbinder #{command.usage[0]}", command.usage[1]]
|
15
|
-
1
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
attr_reader :logger, :commands
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require_relative 'errors/cli_error'
|
3
|
-
require_relative 'commands/naming'
|
4
|
-
require_relative 'values/user_message'
|
5
|
-
|
6
|
-
module Bookbinder
|
7
|
-
class CommandValidator
|
8
|
-
def initialize(commands, usage_text)
|
9
|
-
@commands = commands
|
10
|
-
@usage_text = usage_text
|
11
|
-
end
|
12
|
-
|
13
|
-
def validate(command_name)
|
14
|
-
candidate = Candidate.new(command_name, commands)
|
15
|
-
if candidate.unrecognized?
|
16
|
-
UserMessage.new(
|
17
|
-
"Unrecognized #{candidate.command_type} '#{command_name}'\n#{usage_text}",
|
18
|
-
EscalationType.error
|
19
|
-
)
|
20
|
-
elsif candidate.deprecated_match
|
21
|
-
UserMessage.new(
|
22
|
-
"Use of #{command_name} is deprecated. " +
|
23
|
-
"The preferred usage is below: \nbookbinder #{candidate.deprecated_match.usage[0]}",
|
24
|
-
EscalationType.warn
|
25
|
-
)
|
26
|
-
else
|
27
|
-
UserMessage.new "Success", EscalationType.success
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Candidate = Struct.new(:command_name, :commands) do
|
32
|
-
include Bookbinder::Commands::Naming
|
33
|
-
|
34
|
-
def unrecognized?
|
35
|
-
commands.none? { |command| command.command_for?(command_name) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def deprecated_match
|
39
|
-
@deprecated_match ||= commands.find { |command|
|
40
|
-
command.respond_to?(:deprecated_command_for?) &&
|
41
|
-
command.deprecated_command_for?(command_name)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
attr_reader :commands, :usage_text
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|