0
0
Fork 0

Handle CLI failure exit status at the top-level script (#28322)

This commit is contained in:
Matt Jankowski 2024-01-26 03:53:44 -05:00 committed by GitHub
parent 881e8c113c
commit 0e0a94f483
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 150 additions and 320 deletions

View file

@ -31,15 +31,9 @@ module Mastodon::CLI
following anyone locally are pruned.
DESC
def remove
if options[:prune_profiles] && options[:remove_headers]
say('--prune-profiles and --remove-headers should not be specified simultaneously', :red, true)
exit(1)
end
fail_with_message '--prune-profiles and --remove-headers should not be specified simultaneously' if options[:prune_profiles] && options[:remove_headers]
if options[:include_follows] && !(options[:prune_profiles] || options[:remove_headers])
say('--include-follows can only be used with --prune-profiles or --remove-headers', :red, true)
exit(1)
end
fail_with_message '--include-follows can only be used with --prune-profiles or --remove-headers' if options[:include_follows] && !(options[:prune_profiles] || options[:remove_headers])
time_ago = options[:days].days.ago
if options[:prune_profiles] || options[:remove_headers]
@ -156,11 +150,9 @@ module Mastodon::CLI
end
end
when :fog
say('The fog storage driver is not supported for this operation at this time', :red)
exit(1)
fail_with_message 'The fog storage driver is not supported for this operation at this time'
when :azure
say('The azure storage driver is not supported for this operation at this time', :red)
exit(1)
fail_with_message 'The azure storage driver is not supported for this operation at this time'
when :filesystem
require 'find'
@ -254,10 +246,7 @@ module Mastodon::CLI
username, domain = options[:account].split('@')
account = Account.find_remote(username, domain)
if account.nil?
say('No such account', :red)
exit(1)
end
fail_with_message 'No such account' if account.nil?
scope = MediaAttachment.where(account_id: account.id)
elsif options[:domain]
@ -265,8 +254,7 @@ module Mastodon::CLI
elsif options[:days].present?
scope = MediaAttachment.remote
else
say('Specify the source of media attachments', :red)
exit(1)
fail_with_message 'Specify the source of media attachments'
end
scope = scope.where('media_attachments.id > ?', Mastodon::Snowflake.id_at(options[:days].days.ago, with_random: false)) if options[:days].present?
@ -306,38 +294,25 @@ module Mastodon::CLI
path_segments = path.split('/')[2..]
path_segments.delete('cache')
unless VALID_PATH_SEGMENTS_SIZE.include?(path_segments.size)
say('Not a media URL', :red)
exit(1)
end
fail_with_message 'Not a media URL' unless VALID_PATH_SEGMENTS_SIZE.include?(path_segments.size)
model_name = path_segments.first.classify
record_id = path_segments[2..-2].join.to_i
unless PRELOAD_MODEL_WHITELIST.include?(model_name)
say("Cannot find corresponding model: #{model_name}", :red)
exit(1)
end
fail_with_message "Cannot find corresponding model: #{model_name}" unless PRELOAD_MODEL_WHITELIST.include?(model_name)
record = model_name.constantize.find_by(id: record_id)
record = record.status if record.respond_to?(:status)
unless record
say('Cannot find corresponding record', :red)
exit(1)
end
fail_with_message 'Cannot find corresponding record' unless record
display_url = ActivityPub::TagManager.instance.url_for(record)
if display_url.blank?
say('No public URL for this type of record', :red)
exit(1)
end
fail_with_message 'No public URL for this type of record' if display_url.blank?
say(display_url, :blue)
rescue Addressable::URI::InvalidURIError
say('Invalid URL', :red)
exit(1)
fail_with_message 'Invalid URL'
end
private