Class: Ninny::Commands::Setup
- Inherits:
-
Ninny::Command
- Object
- Ninny::Command
- Ninny::Commands::Setup
- Defined in:
- lib/ninny/commands/setup.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #execute(output: $stdout) ⇒ Object
-
#initialize(options) ⇒ Setup
constructor
A new instance of Setup.
- #prompt_for_gitlab_private_token ⇒ Object
- #try_reading_user_config ⇒ Object
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.
10 11 12 13 |
# File 'lib/ninny/commands/setup.rb', line 10 def initialize() = @config = Ninny.user_config end |
Instance Attribute Details
#config ⇒ Object (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(output: $stdout) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ninny/commands/setup.rb', line 15 def execute(output: $stdout) try_reading_user_config private_token = prompt_for_gitlab_private_token begin # TODO: This only works with thor gem < 1. So, we need to make this work when TTY # releases versions compatible with thor versions >= 1 as well. config.write(force: true) rescue StandardError puts ' Unable to write config file via TTY... continuing anyway...' File.open("#{ENV['HOME']}/.ninny.yml", 'w') do |file| file.puts "gitlab_private_token: #{private_token}" end end output.puts "User config #{@result}!" end |
#prompt_for_gitlab_private_token ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ninny/commands/setup.rb', line 41 def prompt_for_gitlab_private_token begin new_token_text = config.gitlab_private_token ? ' new' : '' rescue MissingUserConfig new_token_text = '' end return unless prompt.yes?("Do you have a#{new_token_text} GitLab private token?") private_token = prompt.ask('Enter private token:', required: true) begin # TODO: This only works with thor gem < 1. So, we need to make this work when TTY # releases versions compatible with thor versions >= 1 as well. config.set(:gitlab_private_token, value: private_token) rescue ArgumentError puts ' Unable to set new token via TTY... continuing anyway...' end private_token end |
#try_reading_user_config ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ninny/commands/setup.rb', line 34 def try_reading_user_config config.read @result = 'updated' rescue MissingUserConfig @result = 'created' end |