Sha256: aa7494375d9dbc8da9cfb82d072d4343a7fce66f50cf075801632b37202e077c

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

module Shhh
  module App

    class Args

      OPTIONS_REQUIRE_KEY    = %i(encrypt decrypt edit)
      OPTIONS_KEY_CREATED    = %i(generate)
      OPTIONS_SPECIFY_KEY    = %i(private_key interactive keyfile keychain)
      OPTIONS_SPECIFY_OUTPUT = %i(output quiet)

      attr_accessor :opts, :selected_options

      def initialize(opts)
        self.opts             = opts
        self.selected_options = opts.keys.reject { |k| !opts[k] }
      end

      def specify_key?
        do?(OPTIONS_SPECIFY_KEY)
      end

      def require_key?
        do?(OPTIONS_REQUIRE_KEY)
      end

      def generate_key?
        do?(OPTIONS_KEY_CREATED)
      end

      def output_class
        output_type = OPTIONS_SPECIFY_OUTPUT.find { |o| opts[o] } # includes nil
        Shhh::App::Output.outputs[output_type]
      end

      private
      def do?(list)
        !(list & selected_options).empty?
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shhh-1.7.0 lib/shhh/app/args.rb