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::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, 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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/github_cli/command.rb', line 65

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

.api(name = nil) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/github_cli/command.rb', line 52

def api(name=nil)
  @api = case name
  when nil
    @api || GithubCLI.const_get(name.to_s.capitalize)
  else
    @pi
  end
end


61
62
63
# File 'lib/github_cli/command.rb', line 61

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



94
95
96
97
98
99
100
# File 'lib/github_cli/command.rb', line 94

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



88
89
90
# File 'lib/github_cli/command.rb', line 88

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

.is_api_command?(klass) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/github_cli/command.rb', line 83

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