Class: GithubCLI::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/github_cli/cli.rb,
lib/github_cli/subcommands.rb

Constant Summary collapse

ALIASES =
{
  'repository' => 'repo',
  'reference'  => 'ref',
  'is'         => :issue,
  '--version'  => 'version',
  '-V'         => 'version',
  'ls'         => 'list'
}

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

Instance 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, #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, register_klass_file, shell, shell=, subclass_files, subclasses

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
13
14
# File 'lib/github_cli/cli.rb', line 8

def initialize(*args)
  super
  the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
  GithubCLI.ui = UI.new(the_shell)
  GithubCLi.ui.debug! if options["verbose"]
  options["no-pager"] ? Pager.disable : Pager.enable
end

Instance Method Details

#config(*args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/github_cli/cli.rb', line 117

def config(*args)
  name, value = args.shift, args.shift

  GithubCLI.config.location = options[:local] ? 'local' : 'global'

  if !options[:global] and !options[:local]
    GithubCLI.ui.error 'Invalid scope given. Please use --local or --global.'
    exit 1
  elsif !File.exists?(GithubCLI.config.path)
    GithubCLI.ui.error "#{GithubCLI.config.location} configuration file does not exist. Please use `#{GithubCLI.executable_name} init --#{GithubCLI.config.location}`"
    exit 1
  end

  if options[:list]
    Terminal.print_config(name) && return
  elsif options[:edit]
    editor = Editor.new GithubCLI.config.path
    editor.open && return
  end

  if !name
    Terminal.print_config && return
  end

  if !value
    Terminal.line GithubCLI.config[name]
  else
    Terminal.line GithubCLI.config[name] = value
  end

  return
end

#init(filename = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/github_cli/cli.rb', line 79

def init(filename=nil)
  config_filename = (filename.nil? || filename =~ /^\//)? options[:config] : filename

  if !options[:global] and !options[:local]
    GithubCLI.ui.error 'Invalid scope given. Please use --local or --global.'
    exit 1
  end

  GithubCLI.config.location = options[:local] ? 'local' : 'global'

  if File.exists?(GithubCLI.config.path) && !options[:force]
    GithubCLI.ui.error "Not overwritting existing config file #{GithubCLI.config.path}, use --force to override."
    exit 1
  end

  oauth_token = ask "Please specify your GitHub Authentication Token (register on github.com to get it):"
  GithubCLI.config.save(defaults.merge({'auth.token' => oauth_token}))
  GithubCLI.ui.confirm "Writing new configuration file to #{GithubCLI.config.path}"
end

#list(pattern = "") ⇒ Object



151
152
153
154
# File 'lib/github_cli/cli.rb', line 151

def list(pattern="")
  pattern = /^#{pattern}.*$/i
  Terminal.print_commands pattern
end

#versionObject



157
158
159
# File 'lib/github_cli/cli.rb', line 157

def version
  GithubCLI.ui.info "#{GithubCLI.program_name} v#{GithubCLI::VERSION}"
end