Module: Ukiryu::CliCommands::ResponseFormatter

Included in:
RunCommand, RunFileCommand
Defined in:
lib/ukiryu/cli_commands/response_formatter.rb

Overview

Response formatting module for CLI commands

Provides reusable formatting methods for execution responses in multiple formats (YAML, JSON, table, raw).

Constant Summary collapse

OUTPUT_FORMATS =

Supported output formats

%i[yaml json table raw].freeze

Instance Method Summary collapse

Instance Method Details

#output_response(response, format, output_file, config) ⇒ void

This method returns an undefined value.

Output response in specified format

Parameters:

  • response (Models::SuccessResponse, Models::ErrorResponse)

    the response to format

  • format (Symbol)

    the output format (:yaml, :json, :table, or :raw)

  • output_file (String, nil)

    optional file path to write output

  • config (Object)

    the CLI config object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ukiryu/cli_commands/response_formatter.rb', line 20

def output_response(response, format, output_file, config)
  if format == :raw
    output_raw_response(response, output_file)
  else
    output_string = case format
                    when :yaml
                      format_yaml_response(response, config)
                    when :json
                      format_json_response(response)
                    when :table, :human
                      format_table_response(response, config)
                    else
                      response.to_yaml
                    end

    if output_file
      File.write(output_file, output_string)
      say "Response written to: #{output_file}", :green
    else
      say output_string
    end
  end
end

#say_dry_run(request) ⇒ Object

Show dry run output

Parameters:

  • request (Hash)

    the execution request



47
48
49
50
51
52
53
54
55
56
# File 'lib/ukiryu/cli_commands/response_formatter.rb', line 47

def say_dry_run(request)
  say 'DRY RUN - Ukiryu Structured Execution Request:', :yellow
  say '', :clear
  say "Tool: #{request['tool']}", :cyan
  say "Command: #{request['command']}", :cyan
  say 'Arguments:', :cyan
  request['arguments'].each do |key, value|
    say "  #{key}: #{value.inspect}", :white
  end
end