Class: Ninny::Commands::Setup

Inherits:
Ninny::Command show all
Defined in:
lib/ninny/commands/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Ninny::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ Setup

Returns a new instance of Setup.



9
10
11
12
# File 'lib/ninny/commands/setup.rb', line 9

def initialize(options)
  @options = options
  @config = Ninny.user_config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/ninny/commands/setup.rb', line 8

def config
  @config
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ninny/commands/setup.rb', line 14

def execute(input: $stdin, output: $stdout)
  try_reading_user_config

  prompt_for_gitlab_private_token

  config.write(force: true)
  # Command logic goes here ...
  output.puts "User config #{@result}"
end

#prompt_for_gitlab_private_tokenObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ninny/commands/setup.rb', line 33

def prompt_for_gitlab_private_token
  begin
    new_token_text = config.gitlab_private_token ? ' new' : ''
  rescue MissingUserConfig
    new_token_text = 'new'
  end
  if prompt.yes?("Do you have a#{new_token_text} gitlab private token?")
    private_token = prompt.ask("Enter private token", required: true)
    config.set(:gitlab_private_token, value: private_token)
  end
end

#try_reading_user_configObject



24
25
26
27
28
29
30
31
# File 'lib/ninny/commands/setup.rb', line 24

def try_reading_user_config
  begin
    config.read
    @result = 'updated'
  rescue MissingUserConfig
    @result = 'created'
  end
end