diff options
author | Matt Jankowski <matt@jankowski.online> | 2023-05-24 05:55:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 11:55:40 +0200 |
commit | 384345b0de9cc6b8cc62bbf60f2361449995717d (patch) | |
tree | ef1c703307d4ee668985589ce7bb08f5ec7fa60a /lib | |
parent | d2e5430d4a4f3828f5adbd7429752f9f11cfc07f (diff) |
Add CLI Base class for command line code (#25106)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/cli/accounts.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/base.rb | 19 | ||||
-rw-r--r-- | lib/mastodon/cli/cache.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/canonical_email_blocks.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/domains.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/email_domain_blocks.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/emoji.rb | 10 | ||||
-rw-r--r-- | lib/mastodon/cli/feeds.rb | 11 | ||||
-rw-r--r-- | lib/mastodon/cli/ip_blocks.rb | 10 | ||||
-rw-r--r-- | lib/mastodon/cli/main.rb | 28 | ||||
-rw-r--r-- | lib/mastodon/cli/maintenance.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/media.rb | 11 | ||||
-rw-r--r-- | lib/mastodon/cli/preview_cards.rb | 11 | ||||
-rw-r--r-- | lib/mastodon/cli/search.rb | 8 | ||||
-rw-r--r-- | lib/mastodon/cli/settings.rb | 12 | ||||
-rw-r--r-- | lib/mastodon/cli/statuses.rb | 11 | ||||
-rw-r--r-- | lib/mastodon/cli/upgrade.rb | 12 |
17 files changed, 62 insertions, 153 deletions
diff --git a/lib/mastodon/cli/accounts.rb b/lib/mastodon/cli/accounts.rb index a44f63db030..417f126ccd0 100644 --- a/lib/mastodon/cli/accounts.rb +++ b/lib/mastodon/cli/accounts.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true require 'set' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Accounts < Thor - include Helper - - def self.exit_on_failure? - true - end - + class Accounts < Base option :all, type: :boolean desc 'rotate [USERNAME]', 'Generate and broadcast new keys' long_desc <<-LONG_DESC diff --git a/lib/mastodon/cli/base.rb b/lib/mastodon/cli/base.rb new file mode 100644 index 00000000000..f3c9fea921a --- /dev/null +++ b/lib/mastodon/cli/base.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require_relative '../../../config/boot' +require_relative '../../../config/environment' + +require 'thor' +require_relative 'helper' + +module Mastodon + module CLI + class Base < Thor + include CLI::Helper + + def self.exit_on_failure? + true + end + end + end +end diff --git a/lib/mastodon/cli/cache.rb b/lib/mastodon/cli/cache.rb index b0bf6aabd8d..105d4b3c324 100644 --- a/lib/mastodon/cli/cache.rb +++ b/lib/mastodon/cli/cache.rb @@ -1,17 +1,9 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Cache < Thor - include Helper - - def self.exit_on_failure? - true - end - + class Cache < Base desc 'clear', 'Clear out the cache storage' def clear Rails.cache.clear diff --git a/lib/mastodon/cli/canonical_email_blocks.rb b/lib/mastodon/cli/canonical_email_blocks.rb index f3c427a2c7d..dd5e6596dd1 100644 --- a/lib/mastodon/cli/canonical_email_blocks.rb +++ b/lib/mastodon/cli/canonical_email_blocks.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class CanonicalEmailBlocks < Thor - include Helper - - def self.exit_on_failure? - true - end - + class CanonicalEmailBlocks < Base desc 'find EMAIL', 'Find a given e-mail address in the canonical e-mail blocks' long_desc <<-LONG_DESC When suspending a local user, a hash of a "canonical" version of their e-mail diff --git a/lib/mastodon/cli/domains.rb b/lib/mastodon/cli/domains.rb index 8b5f03ce0f3..d885c956381 100644 --- a/lib/mastodon/cli/domains.rb +++ b/lib/mastodon/cli/domains.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Domains < Thor - include Helper - - def self.exit_on_failure? - true - end - + class Domains < Base option :concurrency, type: :numeric, default: 5, aliases: [:c] option :verbose, type: :boolean, aliases: [:v] option :dry_run, type: :boolean diff --git a/lib/mastodon/cli/email_domain_blocks.rb b/lib/mastodon/cli/email_domain_blocks.rb index 6ef35cc8cf6..abbbdfe31c9 100644 --- a/lib/mastodon/cli/email_domain_blocks.rb +++ b/lib/mastodon/cli/email_domain_blocks.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class EmailDomainBlocks < Thor - include Helper - - def self.exit_on_failure? - true - end - + class EmailDomainBlocks < Base desc 'list', 'List blocked e-mail domains' def list EmailDomainBlock.where(parent_id: nil).order(id: 'DESC').find_each do |entry| diff --git a/lib/mastodon/cli/emoji.rb b/lib/mastodon/cli/emoji.rb index 9b41a59c29e..912c0991240 100644 --- a/lib/mastodon/cli/emoji.rb +++ b/lib/mastodon/cli/emoji.rb @@ -1,16 +1,10 @@ # frozen_string_literal: true require 'rubygems/package' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Emoji < Thor - def self.exit_on_failure? - true - end - + class Emoji < Base option :prefix option :suffix option :overwrite, type: :boolean diff --git a/lib/mastodon/cli/feeds.rb b/lib/mastodon/cli/feeds.rb index 4307b880f71..342b550ca32 100644 --- a/lib/mastodon/cli/feeds.rb +++ b/lib/mastodon/cli/feeds.rb @@ -1,18 +1,11 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Feeds < Thor - include Helper + class Feeds < Base include Redisable - def self.exit_on_failure? - true - end - option :all, type: :boolean, default: false option :concurrency, type: :numeric, default: 5, aliases: [:c] option :verbose, type: :boolean, aliases: [:v] diff --git a/lib/mastodon/cli/ip_blocks.rb b/lib/mastodon/cli/ip_blocks.rb index 561d64d1824..d12919c3601 100644 --- a/lib/mastodon/cli/ip_blocks.rb +++ b/lib/mastodon/cli/ip_blocks.rb @@ -1,16 +1,10 @@ # frozen_string_literal: true require 'rubygems/package' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class IpBlocks < Thor - def self.exit_on_failure? - true - end - + class IpBlocks < Base option :severity, required: true, enum: %w(no_access sign_up_requires_approval sign_up_block), desc: 'Severity of the block' option :comment, aliases: [:c], desc: 'Optional comment' option :duration, aliases: [:d], type: :numeric, desc: 'Duration of the block in seconds' diff --git a/lib/mastodon/cli/main.rb b/lib/mastodon/cli/main.rb index 0f2236f78f7..e61a6f9c468 100644 --- a/lib/mastodon/cli/main.rb +++ b/lib/mastodon/cli/main.rb @@ -1,29 +1,25 @@ # frozen_string_literal: true -require 'thor' -require_relative 'media' -require_relative 'emoji' +require_relative 'base' + require_relative 'accounts' +require_relative 'cache' +require_relative 'canonical_email_blocks' +require_relative 'domains' +require_relative 'email_domain_blocks' +require_relative 'emoji' require_relative 'feeds' +require_relative 'ip_blocks' +require_relative 'maintenance' +require_relative 'media' +require_relative 'preview_cards' require_relative 'search' require_relative 'settings' require_relative 'statuses' -require_relative 'domains' -require_relative 'preview_cards' -require_relative 'cache' require_relative 'upgrade' -require_relative 'email_domain_blocks' -require_relative 'canonical_email_blocks' -require_relative 'ip_blocks' -require_relative 'maintenance' -require_relative '../version' module Mastodon::CLI - class Main < Thor - def self.exit_on_failure? - true - end - + class Main < Base desc 'media SUBCOMMAND ...ARGS', 'Manage media files' subcommand 'media', Media diff --git a/lib/mastodon/cli/maintenance.rb b/lib/mastodon/cli/maintenance.rb index d9f1b025709..660adef80e8 100644 --- a/lib/mastodon/cli/maintenance.rb +++ b/lib/mastodon/cli/maintenance.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true require 'tty-prompt' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Maintenance < Thor - include Helper - - def self.exit_on_failure? - true - end - + class Maintenance < Base MIN_SUPPORTED_VERSION = 2019_10_01_213028 MAX_SUPPORTED_VERSION = 2022_11_04_133904 diff --git a/lib/mastodon/cli/media.rb b/lib/mastodon/cli/media.rb index 509c4ca2646..045f6351ad7 100644 --- a/lib/mastodon/cli/media.rb +++ b/lib/mastodon/cli/media.rb @@ -1,20 +1,13 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Media < Thor + class Media < Base include ActionView::Helpers::NumberHelper - include Helper VALID_PATH_SEGMENTS_SIZE = [7, 10].freeze - def self.exit_on_failure? - true - end - option :days, type: :numeric, default: 7, aliases: [:d] option :prune_profiles, type: :boolean, default: false option :remove_headers, type: :boolean, default: false diff --git a/lib/mastodon/cli/preview_cards.rb b/lib/mastodon/cli/preview_cards.rb index 794b25693ae..c66bcb504a1 100644 --- a/lib/mastodon/cli/preview_cards.rb +++ b/lib/mastodon/cli/preview_cards.rb @@ -1,18 +1,11 @@ # frozen_string_literal: true require 'tty-prompt' -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class PreviewCards < Thor + class PreviewCards < Base include ActionView::Helpers::NumberHelper - include Helper - - def self.exit_on_failure? - true - end option :days, type: :numeric, default: 180 option :concurrency, type: :numeric, default: 5, aliases: [:c] diff --git a/lib/mastodon/cli/search.rb b/lib/mastodon/cli/search.rb index ccece5b5f88..6f48dcb0969 100644 --- a/lib/mastodon/cli/search.rb +++ b/lib/mastodon/cli/search.rb @@ -1,13 +1,9 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Search < Thor - include Helper - + class Search < Base # Indices are sorted by amount of data to be expected in each, so that # smaller indices can go online sooner INDICES = [ diff --git a/lib/mastodon/cli/settings.rb b/lib/mastodon/cli/settings.rb index 5869efc4663..7d4c13b78e8 100644 --- a/lib/mastodon/cli/settings.rb +++ b/lib/mastodon/cli/settings.rb @@ -1,15 +1,9 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Registrations < Thor - def self.exit_on_failure? - true - end - + class Registrations < Base desc 'open', 'Open registrations' def open Setting.registrations_mode = 'open' @@ -37,7 +31,7 @@ module Mastodon::CLI end end - class Settings < Thor + class Settings < Base desc 'registrations SUBCOMMAND ...ARGS', 'Manage state of registrations' subcommand 'registrations', Registrations end diff --git a/lib/mastodon/cli/statuses.rb b/lib/mastodon/cli/statuses.rb index e5eb759608f..bd5b0470779 100644 --- a/lib/mastodon/cli/statuses.rb +++ b/lib/mastodon/cli/statuses.rb @@ -1,18 +1,11 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Statuses < Thor - include Helper + class Statuses < Base include ActionView::Helpers::NumberHelper - def self.exit_on_failure? - true - end - option :days, type: :numeric, default: 90 option :batch_size, type: :numeric, default: 1_000, aliases: [:b], desc: 'Number of records in each batch' option :continue, type: :boolean, default: false, desc: 'If remove is not completed, execute from the previous continuation' diff --git a/lib/mastodon/cli/upgrade.rb b/lib/mastodon/cli/upgrade.rb index f20fa4cdf4a..e5c86b3d731 100644 --- a/lib/mastodon/cli/upgrade.rb +++ b/lib/mastodon/cli/upgrade.rb @@ -1,17 +1,9 @@ # frozen_string_literal: true -require_relative '../../../config/boot' -require_relative '../../../config/environment' -require_relative 'helper' +require_relative 'base' module Mastodon::CLI - class Upgrade < Thor - include Helper - - def self.exit_on_failure? - true - end - + class Upgrade < Base CURRENT_STORAGE_SCHEMA_VERSION = 1 option :dry_run, type: :boolean, default: false |