Class: GithubCLI::Command

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/github_cli/command/usage.rb,
lib/github_cli/command.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

API_CLASSES =
%w(
  c_l_i
  repo download key fork hook watch collab content
  issue label milestone
  tag tree blob reference commit
  pull
  user email follower
  org member team
  event
  search
)
HELP_COMMAND =
'help'
ALIASES =
{
  "ls"  => :list,
  "all" => :list,
  "del" => :delete,
  "rm"  => :delete,
  "c"   => :create,
  "e"   => :edit
}

Constants inherited from Thor

Thor::HELP_MAPPINGS, Thor::MANPAGES, Thor::THOR_RESERVED_WORDS, 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?, default_task, desc, global_flags, handle_no_task_error, #help, help, long_desc, map, method_option, method_options, printable_tasks, register, subcommand, subcommands, task_help

Methods included from Thor::Base

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

Class Method Details

.allObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/github_cli/command.rb', line 56

def all
  commands = []
  Thor::Base.subclasses.each do |klass|
    namespace = extract_namespace(klass)
    next unless is_api_command?(namespace)
    namespace = "" if namespace.index API_CLASSES.first

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


52
53
54
# File 'lib/github_cli/command.rb', line 52

def banner(task, namespace=true, subcommand=true)
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
end

.command_to_show(command) ⇒ Object

Decide whether to show specific command or placeholder



85
86
87
88
89
90
91
# File 'lib/github_cli/command.rb', line 85

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

.extract_namespace(klass) ⇒ Object



79
80
81
# File 'lib/github_cli/command.rb', line 79

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

.is_api_command?(klass) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
# File 'lib/github_cli/command.rb', line 74

def is_api_command?(klass)
  return false unless API_CLASSES.include?(klass.to_s)
  return true
end

.output_formatsObject



23
24
25
26
27
28
29
30
# File 'lib/github_cli/command.rb', line 23

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