Class: Trustworthy::CLI::Init
- Inherits:
-
Object
- Object
- Trustworthy::CLI::Init
- Includes:
- Command
- Defined in:
- lib/trustworthy/cli/init.rb
Class Method Summary collapse
Instance Method Summary collapse
- #default_options ⇒ Object
- #parse_options(args) ⇒ Object
-
#run(args) ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods included from Command
Class Method Details
.description ⇒ Object
6 7 8 |
# File 'lib/trustworthy/cli/init.rb', line 6 def self.description 'Generate a new master key and user keys' end |
Instance Method Details
#default_options ⇒ Object
10 11 12 |
# File 'lib/trustworthy/cli/init.rb', line 10 def {keys: 2}.merge(super) end |
#parse_options(args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/trustworthy/cli/init.rb', line 14 def (args) super('init', args) do |opts, | opts.on('-k', '--keys N', OptionParser::DecimalInteger, 'Number of keys to generate (default: 2, minimum: 2)') do |k| [:keys] = k end end end |
#run(args) ⇒ Object
rubocop:disable Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/trustworthy/cli/init.rb', line 23 def run(args) = (args) if [:keys] < 2 print_help return end Trustworthy::Settings.open([:config_file]) do |settings| unless settings.empty? say("Config #{[:config_file]} already exists") return # rubocop:disable Lint/NonLocalExitFromIterator end end say("Creating a new master key with #{[:keys]} keys") master_key = Trustworthy::MasterKey.create prompt = Trustworthy::Prompt.new([:config_file], $terminal) [:keys].times do key = master_key.create_key username = prompt.add_user_key(key) $terminal.say("Key #{username} added") end say("Created #{[:config_file]}") end |