Class: GithubCLI::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/github_cli/cli.rb,
lib/github_cli/subcommands.rb
Overview
Main command line interface
Constant Summary collapse
- ALIASES =
{ 'repository' => 'repo', 'reference' => 'ref', 'is' => :issue, '--version' => 'version', '-V' => 'version', 'ls' => 'list' }
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
Attributes included from Thor::Base
#args, #options, #parent_options
Instance Method Summary collapse
- #authorize ⇒ Object
- #config(*args) ⇒ Object
- #init(filename = nil) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list(pattern = "") ⇒ Object
- #version ⇒ Object
- #whoami ⇒ Object
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?, 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, register_klass_file, shell, shell=, subclass_files, subclasses
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 14 15 16 |
# File 'lib/github_cli/cli.rb', line 10 def initialize(*args) super the_shell = (["no-color"] ? Thor::Shell::Basic.new : shell) GithubCLI.ui = UI.new(the_shell) GithubCLi.ui.debug! if ["verbose"] ["no-pager"] ? Pager.disable : Pager.enable end |
Instance Method Details
#authorize ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/github_cli/cli.rb', line 93 def = .dup params = {} params['scopes'] = [:scopes] || %w(public_repo repo) params['note'] = [:note] || 'github_cli' params['note_url'] = [:note_url] || 'https://github.com/peter-murach/github_cli' [:params] = params # Need to configure client with login and password login = TTY.shell.ask("login: ").read_string.strip! password = TTY.shell.ask("password: ").read_password.strip! ['login'] = login ['password'] = password ['quiet'] = [:quiet] res = self.invoke("auth:create", [], ) token = res.body['token'] config = GithubCLI.config config.location = [:local] ? 'local' : 'global' config['user.login'] = login config['user.password'] = password config['user.token'] = token GithubCLI.ui.warn " \\nYour \#{GithubCLI.config.location} configuration file has been overwritten!\n EOF\nend\n" |
#config(*args) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/github_cli/cli.rb', line 173 def config(*args) name, value = args.shift, args.shift GithubCLI.config.location = [:local] ? 'local' : 'global' if !File.exists?(GithubCLI.config.path) GithubCLI.ui.error "Configuration file does not exist. Please use `#{GithubCLI.executable_name} init` to create one." exit 1 end if [:list] Terminal.print_config(name) && return elsif [: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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/github_cli/cli.rb', line 142 def init(filename=nil) config_filename = filename ? filename : [:filename] config = GithubCLI.config config.filename = config_filename config.location = [:local] ? 'local' : 'global' if File.exists?(GithubCLI.config.path) && ![:force] GithubCLI.ui.error "Not overwritting existing config file #{GithubCLI.config.path}, use --force to override." exit 1 end config.save(defaults) GithubCLI.ui.confirm "Writing new configuration file to #{GithubCLI.config.path}" end |
#list(pattern = "") ⇒ Object
203 204 205 206 |
# File 'lib/github_cli/cli.rb', line 203 def list(pattern="") pattern = /^#{pattern}.*$/i Terminal.print_commands pattern end |
#version ⇒ Object
209 210 211 |
# File 'lib/github_cli/cli.rb', line 209 def version GithubCLI.ui.info "#{GithubCLI.program_name} #{GithubCLI::VERSION}" end |
#whoami ⇒ Object
123 124 125 126 127 |
# File 'lib/github_cli/cli.rb', line 123 def whoami config = GithubCLI.config me = config['user.login'] || "Not authed. Run 'gcli authorize'" GithubCLI.ui.info me end |