Class: Mytotp::Commands::Services::Add
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- Mytotp::Commands::Services::Add
- Defined in:
- lib/mytotp/commands/services/add.rb
Overview
Class command for add a new service.
Instance Method Summary collapse
-
#ask_for_incomplete(service_obj) ⇒ Mytotp::Models::Service
Ask incomplete information for a service_obj.
-
#call(service: nil, username: nil, key: nil) ⇒ Object
execute the command.
Instance Method Details
#ask_for_incomplete(service_obj) ⇒ Mytotp::Models::Service
Ask incomplete information for a service_obj
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mytotp/commands/services/add.rb', line 34 def ask_for_incomplete(service_obj) # Check service if was input by argument or interactive ask if service_obj.service.nil? service_obj.service = CLI::UI.ask( 'Which service do you want to add?', allow_empty: false ) end # Check service if was input by argument or interactive ask service_obj.username = CLI::UI.ask('Username?', allow_empty: false) if service_obj.username.nil? # Check service if was input by argument or interactive ask service_obj.key = CLI::UI.ask('Key?', allow_empty: false) if service_obj.key.nil? service_obj end |
#call(service: nil, username: nil, key: nil) ⇒ Object
execute the command
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mytotp/commands/services/add.rb', line 19 def call(service: nil, username: nil, key: nil, **) service_obj = Mytotp::Models::Service.new(service: service, username: username, key: key) service_obj = ask_for_incomplete(service_obj) service_obj.save puts CLI::UI.fmt '{{green:Correct saved!}}' rescue StandardError => e print(e.to_s) puts CLI::UI.fmt '{{red:Something is not fine, try again!}}' end |