lib/pragmater/cli.rb in pragmater-2.2.0 vs lib/pragmater/cli.rb in pragmater-3.0.0
- old
+ new
@@ -6,10 +6,11 @@
require "thor_plus/actions"
require "runcom"
module Pragmater
# The Command Line Interface (CLI) for the gem.
+ # rubocop:disable Metrics/ClassLength
class CLI < Thor
include Thor::Actions
include ThorPlus::Actions
package_name Identity.version_label
@@ -31,23 +32,47 @@
super args, options, config
end
desc "-a, [--add=PATH]", "Add pragma comments to source file(s)."
map %w[-a --add] => :add
- method_option :comments, aliases: "-c", desc: "Pragma comments", type: :array, default: []
- method_option :whitelist, aliases: "-w", desc: "File extension whitelist", type: :array, default: []
+ method_option :comments,
+ aliases: "-c",
+ desc: "Pragma comments",
+ type: :array,
+ default: []
+ method_option :whitelist,
+ aliases: "-w",
+ desc: "File extension whitelist",
+ type: :array,
+ default: []
def add path
- settings = self.class.configuration.merge add: {comments: options[:comments], whitelist: options[:whitelist]}
+ settings = self.class.configuration.merge add: {
+ comments: options[:comments],
+ whitelist: options[:whitelist]
+ }
+
write path, settings, :add
end
desc "-r, [--remove=PATH]", "Remove pragma comments from source file(s)."
map %w[-r --remove] => :remove
- method_option :comments, aliases: "-c", desc: "Pragma comments", type: :array, default: []
- method_option :whitelist, aliases: "-w", desc: "File extension whitelist", type: :array, default: []
+ method_option :comments,
+ aliases: "-c",
+ desc: "Pragma comments",
+ type: :array,
+ default: []
+ method_option :whitelist,
+ aliases: "-w",
+ desc: "File extension whitelist",
+ type: :array,
+ default: []
def remove path
- settings = self.class.configuration.merge remove: {comments: options[:comments], whitelist: options[:whitelist]}
+ settings = self.class.configuration.merge remove: {
+ comments: options[:comments],
+ whitelist: options[:whitelist]
+ }
+
write path, settings, :remove
end
desc "-c, [--config]", %(Manage gem configuration ("#{configuration.computed_path}").)
map %w[-c --config] => :config
@@ -94,14 +119,17 @@
formatted_message = error.message
formatted_message[0] = formatted_message[0].capitalize
error "#{formatted_message}: #{path}."
end
+ # rubocop:disable Metrics/ParameterLists
def update_files path, comments, whitelist, action
if path.file?
update_file path, comments, action
elsif path.directory?
- whitelisted_files(path, whitelist).each { |file_path| update_file file_path, comments, action }
+ whitelisted_files(path, whitelist).each do |file_path|
+ update_file file_path, comments, action
+ end
else
error %(Invalid source path: "#{path}".)
end
end