Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion dcp_inspect
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class Options
options.verbosity = [ 'debug', 'dev' ]
options.logfile = nil
options.logfile_append = nil
options.json_output = false
options.logfile_autolog = nil
options.overwrite_logfile = false
options.verbosity_choices = [ 'quiet', 'errors', 'hints', 'siginfo', 'info', 'cpl', 'debug', 'dev', 'trace_func' ]
Expand Down Expand Up @@ -225,6 +226,9 @@ BANNER
opts.on( '--la', '--logfile-append path', String, 'Append full report to logfile at path' ) do |p|
options.logfile_append = p
end
opts.on( '--json', 'Emit structured JSON to stdout (suppresses normal output)' ) do
options.json_output = true
end
opts.on( '--autolog', "Write full report to $DCP_INSPECT_DIR. (Default: Don't)" ) do
options.logfile_autolog = true
end
Expand Down Expand Up @@ -4611,7 +4615,7 @@ def dcp_inspect( options, arg )
info << 'Found ' + [ am_info, pkl_info, cpl_info ].join( ', ' )
info << "#{ amount( 'Error', errors ) }#{ errors.size == 0 ? ' ✅' : ' ❌' }, #{ amount( 'Hint', hints ) }"

return { :errors => errors, :hints => hints, :siginfo => siginfo, :info => info, :am_files => am_files, :pkls => pkls, :cpls => cpls, :pkls_missing => pkls_missing, :cpls_missing => cpls_missing }
return { :errors => errors, :hints => hints, :siginfo => siginfo, :info => info, :am_files => am_files, :pkls => pkls, :cpls => cpls, :pkls_missing => pkls_missing, :cpls_missing => cpls_missing, :composition_summaries => composition_summaries, :packages_size_bytes => packages_size_actual }
Comment thread
Ra0R marked this conversation as resolved.
Outdated
end # dcp_inspect


Expand Down Expand Up @@ -4707,6 +4711,14 @@ begin
if ENV[ 'DCP_INSPECT_AUTOLOG' ]
options.logfile_autolog = true
end
if options.json_output
options.verbosity = [ 'quiet' ]
# TODO: Or should the JSON output be written to a file instead of stdout? Then we could have autolog and logfile options for JSON output as well.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should reuse the autolog and logfile mechanisms

# For now, just disable all logging except JSON output
options.logfile = nil
options.logfile_append = nil
options.logfile_autolog = nil
end
@logger = DLogger.new( prefix = '', options )


Expand Down Expand Up @@ -4860,6 +4872,34 @@ begin

# Inspection
inspection = dcp_inspect( options, args[ 0 ] )
if options.json_output
require 'json'
payload = {
:meta => {
:tool => AppName,
:version => AppVersion,
:asdcplib_version => ASDCPVersion,
:ruby => RubyVersionPlatform,
:run_at => RunDatetime.iso8601,
:path => Pathname( args[ 0 ] ).realpath.to_s,
},
:summary => {
:assetmap_count => inspection[ :am_files ].size,
:package_count => inspection[ :pkls ].size,
:composition_count => inspection[ :cpls ].size,
:total_size_bytes => inspection[ :packages_size_bytes ],
:error_count => inspection[ :errors ].size,
:hint_count => inspection[ :hints ].size,
},
:compositions => inspection[ :composition_summaries ],
:errors => inspection[ :errors ],
:hints => inspection[ :hints ],
:siginfo => inspection[ :siginfo ],
:info => inspection[ :info ],
}
puts JSON.pretty_generate( payload )
exit inspection[ :errors ].size == 0 ? DCP_OK : DCP_ERROR
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exiting here would leave @dcp_inspect_tmp dangling

end
print_inspection_messages( inspection ) unless @logger.is_quiet

# Remove @dcp_inspect_temp
Expand Down