Class: HexaPDF::CLI::Application
- Inherits:
-
CmdParse::CommandParser
- Object
- CmdParse::CommandParser
- HexaPDF::CLI::Application
- 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
-
#force ⇒ Object
readonly
Specifies whether an operation should be forced.
-
#strict ⇒ Object
readonly
Specifies whether strict parsing and validation should be used.
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
:nodoc:.
-
#parse(argv = ARGV) ⇒ Object
:nodoc:.
-
#verbosity_info? ⇒ Boolean
Returns
trueif the verbosity level info is enabled. -
#verbosity_warning? ⇒ Boolean
Returns
trueif the verbosity level warning is enabled.
Constructor Details
#initialize ⇒ Application
:nodoc:
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/hexapdf/cli.rb', line 109 def initialize #:nodoc: super(handle_exceptions: :no_help) main_command..program_name = "hexapdf" main_command..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(HexaPDF::CLI::Split.new) add_command(HexaPDF::CLI::Watermark.new) add_command(HexaPDF::CLI::Image2PDF.new) add_command(HexaPDF::CLI::Form.new) add_command(HexaPDF::CLI::Fonts.new) add_command(HexaPDF::CLI::Usage.new) add_command(HexaPDF::CLI::DebugInfo.new) add_command(CmdParse::HelpCommand.new) version_command = CmdParse::VersionCommand.new(add_switches: false) add_command(version_command) .on_tail("--version", "Show hexapdf version") { version_command.execute } @force = false @verbosity = VERBOSITY_WARNING @strict = false .on("--[no-]force", "Force overwriting existing files. Default: false") do |f| @force = f end .on("--strict", "Enable strict parsing and validation") do |s| @strict = s end .on("--verbose", "-v", "Verbose output") do @verbosity += 1 end .on("--quiet", "-q", "Suppress any output") do @verbosity = VERBOSITY_QUIET end end |
Instance Attribute Details
#force ⇒ Object (readonly)
Specifies whether an operation should be forced. For example, if an existing file should be overwritten.
104 105 106 |
# File 'lib/hexapdf/cli.rb', line 104 def force @force end |
#strict ⇒ Object (readonly)
Specifies whether strict parsing and validation should be used.
107 108 109 |
# File 'lib/hexapdf/cli.rb', line 107 def strict @strict end |
Instance Method Details
#parse(argv = ARGV) ⇒ Object
:nodoc:
162 163 164 165 |
# File 'lib/hexapdf/cli.rb', line 162 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.
158 159 160 |
# File 'lib/hexapdf/cli.rb', line 158 def verbosity_info? @verbosity >= VERBOSITY_INFO end |
#verbosity_warning? ⇒ Boolean
Returns true if the verbosity level warning is enabled.
153 154 155 |
# File 'lib/hexapdf/cli.rb', line 153 def verbosity_warning? @verbosity >= VERBOSITY_WARNING end |