Sha256: 07cae8d3de7633aa087f5acda11d69dc8aa4c36b016aac3689398b6dc407d3b2

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true
require 'optparse'

class Coursemology::Evaluator::CLI
  Options = Struct.new(:host, :api_token, :api_user_email, :one_shot)

  def self.start(argv)
    new.start(argv)
  end

  def start(argv)
    run(argv)
  end

  def run(argv)
    options = optparse!(argv)
    Coursemology::Evaluator::Client.initialize(options.host, options.api_user_email,
                                               options.api_token)
    Coursemology::Evaluator::Client.new(options.one_shot).run
  end

  private

  # Parses the options specified on the command line.
  #
  # @param [Array<String>] argv The arguments specified on the command line.
  # @return [Coursemology::Evaluator::CLI::Options]
  def optparse!(argv) # rubocop:disable Metrics/MethodLength
    options = Options.new
    option_parser = OptionParser.new do |parser|
      parser.banner = "Usage: #{parser.program_name} [options]"
      parser.on('-hHOST', '--host=HOST', 'Coursemology host to connect to') do |host|
        options.host = host
      end

      parser.on('-tTOKEN', '--api-token=TOKEN') do |token|
        options.api_token = token
      end

      parser.on('-uUSER', '--api-user-email=USER') do |user|
        options.api_user_email = user
      end

      parser.on('-o', '--one-shot') do
        options.one_shot = true
      end
    end

    option_parser.parse!(argv)
    options
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coursemology-evaluator-0.1.4 lib/coursemology/evaluator/cli.rb
coursemology-evaluator-0.1.3 lib/coursemology/evaluator/cli.rb