Module: Pandocomatic::Pandocomatic
- Defined in:
- lib/pandocomatic/pandocomatic.rb
Overview
The Pandocomatic class controlls the pandocomatic conversion process
Constant Summary collapse
- LOG =
Global logger for pandocomatic
Log.new
- FEATURES =
Feature toggles supported by pandocomatic
[:pandoc_verbose].freeze
- ERROR_STATUS =
Pandocomatic error status codes start from ERROR_STATUS
1266
Class Method Summary collapse
-
.run(args) ⇒ Object
Run pandocomatic given options.
Class Method Details
.run(args) ⇒ Object
Run pandocomatic given options
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/pandocomatic/pandocomatic.rb', line 150 def self.run(args) LOG.pandocomatic_called_with args start_time = Time.now # Depending on given command-line arguments, CLI#parse! also # installs a file logger in LOG. configuration = CLI.parse! args if configuration.show_version? # The version option has precedence over all other options; if # given, the version is printed VersionPrinter.new(VERSION).print elsif configuration.show_help? # The help option has precedence over all other options except the # version option. If given, the help is printed. HelpPrinter.new.print else # When using multiple input files, errors reading these # files are already encountered at this point. If there # are any errors, there is no reason to continue. if configuration.input.errors? ConfigurationErrorsPrinter.new(configuration.input.all_errors).print exit ERROR_STATUS end if configuration.dry_run? LOG.debug 'Start dry-run conversion:' else LOG.debug 'Start conversion:' end # Run the pandocomatic converter configured according to the options # given. # # Pandocomatic has two modes: converting a directory tree or # converting a single file. The mode is selected by the input. if configuration.directory? command = ConvertDirCommand.new(configuration, configuration.input_file, configuration.output) else command = ConvertFileMultipleCommand.new(configuration, configuration.input_file, configuration.output) command.make_quiet unless command.subcommands.size > 1 end # Notify the user about all configuration errors collected when # determining the commands to run to perform this pandocomatic # conversion. if command.all_errors.size.positive? ConfigurationErrorsPrinter.new(command.all_errors).print exit ERROR_STATUS end # Pandocomatic is successfully configured: running the # actual conversion now. But first a short summary of the # process to execute is printed. SummaryPrinter.new(command, configuration).print if !configuration.quiet? || command.directory? # Depending on the options dry-run and quiet, the command.execute # method will actually performing the commands (dry-run = false) and # print the command to STDOUT (quiet = false) command.execute FinishPrinter.new(command, configuration, start_time).print unless configuration.quiet? end rescue PandocomaticError => e # Report the error and break off the conversion process. ErrorPrinter.new(e).print exit ERROR_STATUS + 1 rescue StandardError => e # An unexpected error has occurred; break off the program drastically # for now. This is likely a bug: ask the user to report it. UnknownErrorPrinter.new(e).print LOG.error e.backtrace.join("\n") exit ERROR_STATUS + 2 ensure configuration&.clean_up! LOG.info "------------ END ---------------\n" end |