Class: GithubCLI::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/github_cli/command.rb,
lib/github_cli/command/usage.rb,
lib/github_cli/command/arguments.rb,
lib/github_cli/command/completion.rb

Overview

Provides command completion/suggestion for mistyped command or subcommand.

Defined Under Namespace

Classes: Arguments, Comm, Completion, Usage

Constant Summary collapse

HELP_COMMAND =
'help'
ALIASES =
{
  "ls"  => :list,
  "all" => :list,
  "del" => :delete,
  "rm"  => :delete,
  "c"   => :create,
  "e"   => :edit
}

Constants inherited from Thor

Thor::DynamicTask, Thor::HELP_MAPPINGS, Thor::HiddenTask, Thor::MANPAGES, Thor::THOR_RESERVED_WORDS, Thor::Task, Thor::UndefinedTaskError, Thor::VERSION

Instance Attribute Summary

Attributes included from Thor::Actions

#behavior

Attributes included from Thor::Base

#args, #options, #parent_options

Class Method Summary collapse

Methods included from Thor::Actions

#action, #append_to_file, #apply, #chmod, #comment_lines, #copy_file, #create_file, #create_link, #destination_root, #destination_root=, #directory, #empty_directory, #find_in_source_paths, #get, #gsub_file, #in_root, included, #initialize, #inject_into_class, #insert_into_file, #inside, #link_file, #prepend_to_file, #relative_to_original_destination_root, #remove_file, #run, #run_ruby_script, #source_paths, #template, #thor, #uncomment_lines

Methods inherited from Thor

check_unknown_options!, check_unknown_options?, command_help, default_command, desc, global_flags, handle_no_task_error, help, #help, long_desc, map, method_option, method_options, package_name, printable_commands, register, stop_on_unknown_option!, stop_on_unknown_option?, subcommand, subcommands

Methods included from Thor::Base

included, #initialize, register_klass_file, shell, shell=, subclass_files, subclasses

Class Method Details

.allObject

Search for all commands



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/github_cli/command.rb', line 52

def self.all
  commands = []
  Thor::Base.subclasses.each do |klass|
    namespace = extract_namespace(klass)
    next unless is_api_command?(namespace)

    klass.tasks.each do |task|
      last_task = task.last
      name = last_task.name
      next if name.index HELP_COMMAND
      commands << Comm.new(namespace, name, last_task.description, last_task.usage)
    end
  end
  commands
end

.command_to_show(command) ⇒ Object

Decide whether to show specific command or display placeholder



70
71
72
73
74
75
76
77
# File 'lib/github_cli/command.rb', line 70

def self.command_to_show(command)
  command_token = Command.all.find do |cmd|
    cmd_index = command.index('<') || -1
    namespace = cmd.namespace
    !namespace.empty? && command[0..cmd_index].include?(namespace)
  end
  command_token ? command_token.namespace : '<command>'
end

.extract_namespace(klass) ⇒ Object



46
47
48
# File 'lib/github_cli/command.rb', line 46

def self.extract_namespace(klass)
  klass.namespace.split(':').last
end

.is_api_command?(namespace) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/github_cli/command.rb', line 42

def self.is_api_command?(namespace)
  !%w[c_l_i command thor].include?(namespace)
end

.output_formatsObject



14
15
16
17
18
19
20
21
# File 'lib/github_cli/command.rb', line 14

def self.output_formats
  {
    'csv' => nil,
    'json' => nil,
    'pretty' => nil,
    'table' => nil
  }
end