Class: Ukiryu::Models::CommandDefinition

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/ukiryu/models/command_definition.rb

Overview

Command definition for a tool

Examples:

cmd = CommandDefinition.new(
  name: 'convert',
  description: 'Convert image format',
  implements: ['convert'], # v2: command implements interface
  options: [OptionDefinition.new(...)],
  flags: [FlagDefinition.new(...)]
)

Instance Method Summary collapse

Instance Method Details

#argument(name) ⇒ ArgumentDefinition?

Get an argument by name using indexed O(1) lookup

Parameters:

  • name (String, Symbol)

    the argument name

Returns:



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

Returns:

  • (Boolean)

    true if belongs_to is set



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

Parameters:

  • name (String, Symbol)

    the flag name

Returns:



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

Returns:

  • (Boolean)

    true if cli_flag is set



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

Returns:

  • (Boolean)

    true if has subcommand



123
124
125
# File 'lib/ukiryu/models/command_definition.rb', line 123

def has_subcommand?
  !subcommand.nil? && !subcommand.empty?
end

#last_argumentArgumentDefinition?

Get the last argument

Returns:



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

Parameters:

  • name (String, Symbol)

    the option name

Returns:



72
73
74
75
76
77
# File 'lib/ukiryu/models/command_definition.rb', line 72

def option(name)
  return nil unless options

  build_options_index unless @options_index_built
  @options_index[name.to_s]
end

#regular_argumentsArray<ArgumentDefinition>

Get regular arguments (not last)

Returns:



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)

Returns:

  • (Boolean)

    true if standalone_executable is true



131
132
133
# File 'lib/ukiryu/models/command_definition.rb', line 131

def standalone_executable?
  standalone_executable == true
end