29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/bookbinder/cli.rb', line 29
def run(args)
command_name = args[0]
command_arguments = args[1..-1]
logger = BookbinderLogger.new
yaml_loader = YAMLLoader.new
local_file_system_accessor = LocalFileSystemAccessor.new
configuration_validator = ConfigurationValidator.new(logger, local_file_system_accessor)
configuration_fetcher = ConfigurationFetcher.new(logger, configuration_validator, yaml_loader)
configuration_fetcher.set_config_file_path './config.yml'
usage_messenger = UsageMessenger.new
usage_message = usage_messenger.construct_for(COMMANDS, FLAGS)
command_validator = CommandValidator.new usage_messenger, COMMANDS + FLAGS, usage_message
command_runner = CommandRunner.new(configuration_fetcher, usage_message, logger, COMMANDS + FLAGS)
begin
command_name ? command_validator.validate!(command_name) : command_name = '--help'
command_runner.run command_name, command_arguments
rescue Commands::Publish::VersionUnsupportedError => e
logger.error "config.yml at version '#{e.message}' has an unsupported API."
1
rescue Configuration::CredentialKeyError => e
logger.error "#{e.message}, in credentials.yml"
1
rescue KeyError => e
logger.error "#{e.message} from your configuration."
1
rescue CliError::UnknownCommand => e
logger.log e.message
1
rescue RuntimeError => e
logger.error e.message
1
end
end
|