Sha256: 07c1b738e908cf2b18123ead0fcd4447c71edbc8e74f6507d22f65c49a6c5c2b

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

require 'opener/core'

module Opener
  class PolarityTagger
    ##
    # CLI wrapper around {Opener::LanguageIdentifier} using OptionParser.
    #
    # @!attribute [r] options
    #  @return [Hash]
    # @!attribute [r] option_parser
    #  @return [OptionParser]
    #
    class CLI
      attr_reader :options, :option_parser, :resource_switcher

      ##
      # @param [Hash] options
      #
      def initialize(options = {})
        @options = options

        @resource_switcher = Opener::Core::ResourceSwitcher.new
        component_options, options[:args] = Opener::Core::ArgvSplitter.split(options[:args])

        @option_parser = OptionParser.new do |opts|
          opts.program_name   = 'polarity-tagger'
          opts.summary_indent = '  '

          resource_switcher.bind(opts, @options)

          opts.on('-h', '--help', 'Shows this help message') do
            show_help
          end

          opts.on('-v', '--version', 'Shows the current version') do
            show_version
          end

          opts.on('-l', '--log', 'Enable logging to STDERR') do
            @options[:logging] = true
          end
        end

        option_parser.parse!(component_options)
        force = false
        resource_switcher.install(@options, force)
      end

      ##
      # @param [String] input
      #
      def run(input)
        tagger = PolarityTagger.new(options)

        stdout, stderr, process = tagger.run(input)

        puts stdout
      end

      private

      ##
      # Shows the help message and exits the program.
      #
      def show_help
        abort option_parser.to_s
      end

      ##
      # Shows the version and exits the program.
      #
      def show_version
        abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
      end
    end # CLI
  end # PolarityTagger
end # Opener

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opener-polarity-tagger-2.5.0 lib/opener/polarity_tagger/cli.rb
opener-polarity-tagger-2.4.2 lib/opener/polarity_tagger/cli.rb
opener-polarity-tagger-2.4.1 lib/opener/polarity_tagger/cli.rb
opener-polarity-tagger-2.4.0 lib/opener/polarity_tagger/cli.rb