Class: Pike13::CLI::Commands::Base

Inherits:
Thor
  • Object
show all
Includes:
ThorNestedSubcommand
Defined in:
lib/pike13/cli/commands/base.rb

Class Method Summary collapse

Methods included from ThorNestedSubcommand

included

Class Method Details

.base_usageObject

Auto-generate base_usage from class name



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pike13/cli/commands/base.rb', line 31

def self.base_usage
  # Convert class name like Pike13::CLI::Commands::Report::Clients
  # to "report clients"
  namespace_parts = name.split("::")[3..] # Skip Pike13::CLI::Commands
  if namespace_parts && namespace_parts.length > 1
    # For nested classes like Report::Clients
    namespace_parts.map(&:downcase).join(" ")
  elsif namespace_parts&.length == 1
    # For top-level namespace classes
    namespace_parts.first.downcase
  else
    ""
  end
end

.format_optionsObject

Helper to add format options to commands



47
48
49
50
51
52
# File 'lib/pike13/cli/commands/base.rb', line 47

def self.format_options
  option :format, type: :string, default: "json", desc: "Output format (json, table, csv)"
  option :compact, type: :boolean, default: false, desc: "Compact JSON output"
  option :color, type: :boolean, default: false, desc: "Colorize table output"
  option :progress, type: :boolean, default: false, desc: "Show progress indicator"
end

.handle_argument_error(task, error, _type) ⇒ Object

Override help to show command-specific options



23
24
25
26
27
28
# File 'lib/pike13/cli/commands/base.rb', line 23

def self.handle_argument_error(task, error, _type)
  puts "Error: #{error.message}"
  puts
  puts "Run '#{basename} #{base_usage} #{task.name} --help' for more information."
  exit 1
end

.printable_commands(*args) ⇒ Object

Override printable_commands to hide redundant help command from listings



16
17
18
19
20
# File 'lib/pike13/cli/commands/base.rb', line 16

def self.printable_commands(*args)
  result = super
  # Remove the help command from listings since it's redundant when using -h/--help
  result.reject { |item| item.first.include?("help [COMMAND]") }
end