Sha256: f18dc894921ad305e43e77e7e75ea1aa9210a9787e73ced8e9412f67ec67f425

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

require 'forwardable'
require_relative 'database'
require_relative 'settings'
require_relative 'sig_from_stream'

module Signore
  class CLI
    extend Forwardable

    delegate %i(action tags) => :settings

    def initialize(args = ARGV, db: Database.new)
      @settings = Settings.new(args)
      @db       = db
    end

    def run(input: $stdin)
      trap(:INT) { exit }
      case action
      when 'prego'  then puts retrieve_sig
      when 'pronto' then puts create_sig_from(input)
      else abort 'usage: signore prego|pronto [tag, …]'
      end
    end

    attr_reader :db, :settings
    private     :db, :settings

    private

    def create_sig_from(input)
      SigFromStream.sig_from(input, tags: tags).tap { |sig| db << sig }
    end

    def retrieve_sig
      db.find(tags: tags)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signore-0.2.4 lib/signore/cli.rb