options.cr 1.14 KB
Newer Older
1 2
require "option_parser"
require "../cycling"
3
require "./options"
4 5 6 7 8 9 10 11 12

class Cycling::Options
  # Option Flags to select different options for things
  OptionParser.parse do |p|
    p.banner = "Usage: cycling [arguments]"
    p.on("-o", "--output", "Output the data to I/O for use in other programs") do
      puts "Not Available"
      exit
    end
13

Konstantine's avatar
Konstantine committed
14 15 16 17 18
    p.on("-v", "--version", "Prints Version of program to terminal") do
      puts VERSION
      exit
    end

19 20 21
    p.on("-f PATH", "--file PATH", "Choose file to write to") do |new_path|
      ENV["file"] = new_path.empty? ? "data.csv" : new_path
    end
22 23 24 25 26 27

    p.on("-a FILE", "--aat FILE", "Put path to AAT data file to input") do |aat_file|
      # if aat_file.empty?
      #   raise "File Needs to be specified... Please try again..."
      # end
      File.exists?(aat_file) ? Cycling::AAT.import(aat_file) : Cycling::AAT.error
28 29
      exit
    end
30

31 32 33 34
    p.on("-h", "--help", "Show this help") do
      puts p
      exit
    end
35

36 37 38 39 40 41 42 43
    # If flag unknown show help but show error
    p.invalid_option do |flag|
      STDERR.puts "ERROR: #{flag} is not a valid option."
      STDERR.puts p
      exit(1)
    end
  end
end