lib/icarus/mod/cli/base.rb in Icarus-Mod-Tools-1.3.5 vs lib/icarus/mod/cli/base.rb in Icarus-Mod-Tools-1.4.0
- old
+ new
@@ -5,69 +5,22 @@
require "thor"
module Icarus
module Mod
module CLI
- # Base class for all subcommands
- class SubCommandBase < Thor
- class_option :verbose,
- aliases: "-v",
- type: :boolean,
- repeatable: true,
- default: [true],
- desc: "Increase verbosity. May be repeated for even more verbosity."
+ # The Base CLI class for Icarus Mod Tools. This is inherited by all subcommands.
+ class Base < Thor
+ class_option :config,
+ aliases: "-C", type: :string, default: File.join(Dir.home, "/.imtconfig.json"),
+ desc: "Path to the config file"
- no_commands do
- def check_false
- options[:verbose] = [] if options[:verbose].include?(false)
- end
+ class_option :version,
+ aliases: "-V", type: :boolean,
+ desc: "Print the version and exit"
- def verbose
- check_false
- options[:verbose]&.count || 0
- end
-
- def verbose?
- check_false
- options[:verbose]&.count&.positive?
- end
- end
-
- def self.banner(command, _namespace = nil, _subcommand = false) # rubocop:disable Style/OptionalBooleanParameter
- "#{basename} #{subcommand_prefix} #{command.usage}"
- end
-
- def self.subcommand_prefix
- name.gsub(/.*::/, "").gsub(/^[A-Z]/) { |match| match[0].downcase }.gsub(/[A-Z]/) { |match| "-#{match[0].downcase}" }
- end
- end
-
- # Require subcommands after the SubCommandBase class is defined
- require "cli/sync"
- require "cli/list"
- require "cli/add"
-
- # The main CLI for Icarus Mod Tools
- class Base < Thor
def self.exit_on_failure?
true
end
-
- map %w[--version -V] => :__print_version
-
- desc "--version, -V", "print the version and exit"
- def __print_version
- puts "IcarusModTool (imt) v#{Icarus::Mod::VERSION}"
- end
-
- desc "sync", "Syncs the databases"
- subcommand "sync", Sync
-
- desc "list", "Lists the databases"
- subcommand "list", List
-
- desc "add", "Adds entries to the databases"
- subcommand "add", Add
end
end
end
end