Class: HexaPDF::CLI::Application

Inherits:
CmdParse::CommandParser
  • Object
show all
Defined in:
lib/hexapdf/cli.rb

Overview

The CmdParse::CommandParser class that is used for running the CLI application.

Constant Summary collapse

VERBOSITY_QUIET =

Verbosity level for no output

0
VERBOSITY_WARNING =

Verbosity level for warning output

1
VERBOSITY_INFO =

Verbosity level for informational output

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

:nodoc:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hexapdf/cli.rb', line 79

def initialize #:nodoc:
  super(handle_exceptions: :no_help)
  main_command.options.program_name = "hexapdf"
  main_command.options.version = HexaPDF::VERSION
  main_command.extend(Command::Extensions)
  main_command.define_singleton_method(:usage_commands) { "COMMAND" }
  add_command(HexaPDF::CLI::Info.new)
  add_command(HexaPDF::CLI::Files.new)
  add_command(HexaPDF::CLI::Images.new)
  add_command(HexaPDF::CLI::Inspect.new)
  add_command(HexaPDF::CLI::Modify.new)
  add_command(HexaPDF::CLI::Optimize.new)
  add_command(HexaPDF::CLI::Merge.new)
  add_command(HexaPDF::CLI::Batch.new)
  add_command(CmdParse::HelpCommand.new)
  version_command = CmdParse::VersionCommand.new(add_switches: false)
  add_command(version_command)
  main_options.on_tail("--version", "Show hexapdf version") { version_command.execute }

  @force = false
  @verbosity = VERBOSITY_WARNING
  @strict = false
  global_options.on("--[no-]force", "Force overwriting existing files. Default: false") do |f|
    @force = f
  end
  global_options.on("--strict", "Enable strict parsing and validation") do |s|
    @strict = s
  end
  global_options.on("--verbose", "-v", "Verbose output") do
    @verbosity += 1
  end
  global_options.on("--quiet", "-q", "Suppress any output") do
    @verbosity = VERBOSITY_QUIET
  end
end

Instance Attribute Details

#forceObject (readonly)

Specifies whether an operation should be forced. For example, if an existing file should be overwritten.



74
75
76
# File 'lib/hexapdf/cli.rb', line 74

def force
  @force
end

#strictObject (readonly)

Specifies whether strict parsing and validation should be used.



77
78
79
# File 'lib/hexapdf/cli.rb', line 77

def strict
  @strict
end

Instance Method Details

#parse(argv = ARGV) ⇒ Object

:nodoc:



125
126
127
128
# File 'lib/hexapdf/cli.rb', line 125

def parse(argv = ARGV) #:nodoc:
  ARGV.unshift('help') if ARGV.empty?
  super
end

#verbosity_info?Boolean

Returns true if the verbosity level info is enabled.

Returns:

  • (Boolean)


121
122
123
# File 'lib/hexapdf/cli.rb', line 121

def verbosity_info?
  @verbosity >= VERBOSITY_INFO
end

#verbosity_warning?Boolean

Returns true if the verbosity level warning is enabled.

Returns:

  • (Boolean)


116
117
118
# File 'lib/hexapdf/cli.rb', line 116

def verbosity_warning?
  @verbosity >= VERBOSITY_WARNING
end