<commit_before>require_relative 'command'
require_relative '../password_generator'
require_relative '../record'

module Passman
  module Commands
    class New < Command
      desc "Create a new password record"
      switch ['g', 'generate-password'], desc: 'generate a password'

      def invoke
        attrs = get_attributes args

        if options['generate-password']
          pw_gen = PasswordGenerator.new config['commands', 'password_gen']
          attrs[:secret] = pw_gen.generate
        end

        secret = Record.new(attrs)

        database.add secret
        database.write
      end

      def get_attributes(args)
        Hash[args.map do |a|
          k, v = a.split(/=/)
          [k.to_sym, v]
        end]
      end
    end<commit_msg>No need to pass args<commit_after>require_relative 'command'
require_relative '../password_generator'
require_relative '../record'

module Passman
  module Commands
    class New < Command
      desc "Create a new password record"
      switch ['g', 'generate-password'], desc: 'generate a password'

      def invoke
        attrs = get_attributes

        if options['generate-password']
          pw_gen = PasswordGenerator.new config['commands', 'password_gen']
          attrs[:secret] = pw_gen.generate
        end

        secret = Record.new(attrs)

        database.add secret
        database.write
      end

      def get_attributes
        Hash[args.map do |a|
          k, v = a.split(/=/)
          [k.to_sym, v]
        end]
      end
    end
{'fraction_non_alphanumeric': 0.09736842105263158, 'fraction_numerical': 0.0, 'mean_word_length': 2.16875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2331992', 'n_tokens_mistral': 429, 'n_tokens_neox': 414, 'n_words': 120}