Class: HexaPDF::CLI::Batch
- Defined in:
- lib/hexapdf/cli/batch.rb
Overview
Execute the same command for multiple input files.
Instance Method Summary collapse
-
#execute(command, *files) ⇒ Object
:nodoc:.
-
#initialize ⇒ Batch
constructor
:nodoc:.
Methods included from Command::Extensions
Constructor Details
#initialize ⇒ Batch
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hexapdf/cli/batch.rb', line 46 def initialize #:nodoc: super('batch', takes_commands: false) short_desc("Execute a single command on multiple files") long_desc(<<~EOF) This command allows executing a single command for multiple input files, thereby reducing the overall execution time. The first argument is used as a hexapdf command line (but without the binary name) and the rest as input files. The specified command will be executed for each input file, with {} being replaced by the file name. EOF end |
Instance Method Details
#execute(command, *files) ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hexapdf/cli/batch.rb', line 59 def execute(command, *files) #:nodoc: args = Shellwords.split(command) files.each do |file| HexaPDF::CLI::Application.new.parse(args.map {|a| a.gsub(/{}/, file) }) rescue StandardError if command_parser.verbosity_warning? $stderr.puts "Error processing '#{file}': #{$!.}" end end end |