Class: Githuh::CLI::Commands::Base

Inherits:
Dry::CLI::Command
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/githuh/cli/commands/base.rb

Direct Known Subclasses

Issue::Export, Repo::List, User::Info

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boxObject

Returns the value of attribute box.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def box
  @box
end

#clientObject

Returns the value of attribute client.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def client
  @client
end

#contextObject

Returns the value of attribute context.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def context
  @context
end

#infoObject

Returns the value of attribute info.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def info
  @info
end

#per_pageObject

Returns the value of attribute per_page.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def per_page
  @per_page
end

#tokenObject

Returns the value of attribute token.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def token
  @token
end

#verboseObject

Returns the value of attribute verbose.



31
32
33
# File 'lib/githuh/cli/commands/base.rb', line 31

def verbose
  @verbose
end

Class Method Details

.inherited(base) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/githuh/cli/commands/base.rb', line 20

def inherited(base)
  super
  base.instance_eval do
    option :api_token, required: false, desc: "Github API token; if not given, user.token is read from ~/.gitconfig"
    option :per_page, required: false, default: DEFAULT_PAGE_SIZE, desc: "Pagination page size for Github API"
    option :info, type: :boolean, default: true, desc: 'Print UI elements, like a the progress bar'
    option :verbose, type: :boolean, default: false, desc: 'Print additional debugging info'
  end
end

Instance Method Details

#call(api_token: nil, per_page: DEFAULT_PAGE_SIZE, verbose: false, info: true) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/githuh/cli/commands/base.rb', line 33

def call(api_token: nil,
         per_page: DEFAULT_PAGE_SIZE,
         verbose: false,
         info: true)

  self.context  = Githuh
  self.verbose  = verbose
  self.info     = info
  self.token    = api_token || token_from_gitconfig
  self.per_page = per_page.to_i || DEFAULT_PAGE_SIZE
  self.client   = Octokit::Client.new(access_token: token)

  print_userinfo if info
end