Class: Ukiryu::Models::CommandDefinition
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Ukiryu::Models::CommandDefinition
- Defined in:
- lib/ukiryu/models/command_definition.rb
Overview
Command definition for a tool
Instance Method Summary collapse
-
#argument(name) ⇒ ArgumentDefinition?
Get an argument by name using indexed O(1) lookup.
-
#belongs_to_command? ⇒ Boolean
Check if this command/action belongs to a parent command.
-
#clear_indexes! ⇒ Object
private
Clear all indexes.
-
#flag(name) ⇒ FlagDefinition?
Get a flag by name using indexed O(1) lookup.
-
#flag_action? ⇒ Boolean
Check if this action is expressed as a flag.
-
#has_subcommand? ⇒ Boolean
Check if command has a subcommand.
-
#last_argument ⇒ ArgumentDefinition?
Get the last argument.
-
#option(name) ⇒ OptionDefinition?
Get an option by name using indexed O(1) lookup.
-
#regular_arguments ⇒ Array<ArgumentDefinition>
Get regular arguments (not last).
-
#standalone_executable? ⇒ Boolean
Check if this command should use a standalone executable (for ImageMagick v6 style where identify/mogrify are separate commands).
Instance Method Details
#argument(name) ⇒ ArgumentDefinition?
Get an argument by name using indexed O(1) lookup
94 95 96 97 98 99 |
# File 'lib/ukiryu/models/command_definition.rb', line 94 def argument(name) return nil unless arguments build_arguments_index unless @arguments_index_built @arguments_index[name.to_s] end |
#belongs_to_command? ⇒ Boolean
Check if this command/action belongs to a parent command
57 58 59 |
# File 'lib/ukiryu/models/command_definition.rb', line 57 def belongs_to_command? !belongs_to.nil? && !belongs_to.empty? end |
#clear_indexes! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clear all indexes
Call this if collections are modified after initial loading
140 141 142 143 144 145 146 147 |
# File 'lib/ukiryu/models/command_definition.rb', line 140 def clear_indexes! @options_index = nil @options_index_built = false @flags_index = nil @flags_index_built = false @arguments_index = nil @arguments_index_built = false end |
#flag(name) ⇒ FlagDefinition?
Get a flag by name using indexed O(1) lookup
83 84 85 86 87 88 |
# File 'lib/ukiryu/models/command_definition.rb', line 83 def flag(name) return nil unless flags build_flags_index unless @flags_index_built @flags_index[name.to_s] end |
#flag_action? ⇒ Boolean
Check if this action is expressed as a flag
64 65 66 |
# File 'lib/ukiryu/models/command_definition.rb', line 64 def flag_action? !cli_flag.nil? && !cli_flag.empty? end |
#has_subcommand? ⇒ Boolean
Check if command has a subcommand
123 124 125 |
# File 'lib/ukiryu/models/command_definition.rb', line 123 def has_subcommand? !subcommand.nil? && !subcommand.empty? end |
#last_argument ⇒ ArgumentDefinition?
Get the last argument
104 105 106 107 108 |
# File 'lib/ukiryu/models/command_definition.rb', line 104 def last_argument return nil unless arguments arguments.find { |a| a.is_a?(ArgumentDefinition) && a.last? } end |
#option(name) ⇒ OptionDefinition?
Get an option by name using indexed O(1) lookup
72 73 74 75 76 77 |
# File 'lib/ukiryu/models/command_definition.rb', line 72 def option(name) return nil unless unless @options_index_built @options_index[name.to_s] end |
#regular_arguments ⇒ Array<ArgumentDefinition>
Get regular arguments (not last)
113 114 115 116 117 118 |
# File 'lib/ukiryu/models/command_definition.rb', line 113 def regular_arguments return [] unless arguments args = arguments.select { |a| a.is_a?(ArgumentDefinition) } args.reject(&:last?).sort_by(&:numeric_position) end |
#standalone_executable? ⇒ Boolean
Check if this command should use a standalone executable (for ImageMagick v6 style where identify/mogrify are separate commands)
131 132 133 |
# File 'lib/ukiryu/models/command_definition.rb', line 131 def standalone_executable? standalone_executable == true end |