Class: Ukiryu::Models::ExitCodes

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

Overview

Exit code definitions for tool commands

Provides machine-readable error semantics for exit codes.

Examples:

exit_codes = ExitCodes.new(
  standard: { '0' => 'success', '1' => 'general_error' },
  custom: { '3' => 'merge_conflict', '4' => 'permission_denied' }
)

Instance Method Summary collapse

Instance Method Details

#all_codesHash

Get all defined exit codes

Returns:

  • (Hash)

    all codes merged (standard + custom)



53
54
55
# File 'lib/ukiryu/models/exit_codes.rb', line 53

def all_codes
  @standard.to_h.merge(@custom.to_h)
end

#custom_codesHash

Get custom exit codes

Returns:

  • (Hash)

    custom codes



67
68
69
# File 'lib/ukiryu/models/exit_codes.rb', line 67

def custom_codes
  @custom.to_h
end

#defined?(code) ⇒ Boolean

Check if an exit code is defined

Parameters:

  • code (Integer)

    the exit code

Returns:

  • (Boolean)

    true if defined



38
39
40
# File 'lib/ukiryu/models/exit_codes.rb', line 38

def defined?(code)
  !meaning(code).nil?
end

#meaning(code) ⇒ String?

Get the meaning of an exit code

Parameters:

  • code (Integer)

    the exit code

Returns:

  • (String, nil)

    the meaning or nil if not defined



27
28
29
30
31
32
# File 'lib/ukiryu/models/exit_codes.rb', line 27

def meaning(code)
  code_str = code.to_s

  # Check custom codes first (more specific)
  @custom&.dig(code_str) || @standard&.dig(code_str)
end

#standard_codesHash

Get standard exit codes

Returns:

  • (Hash)

    standard codes



60
61
62
# File 'lib/ukiryu/models/exit_codes.rb', line 60

def standard_codes
  @standard.to_h
end

#success?(code) ⇒ Boolean

Check if an exit code indicates success

Parameters:

  • code (Integer)

    the exit code

Returns:

  • (Boolean)

    true if success (0 or defined as success)



46
47
48
# File 'lib/ukiryu/models/exit_codes.rb', line 46

def success?(code)
  code.zero? || meaning(code) == 'success'
end