options.cr 1.16 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 14

    # Specifiy the file you wish to save data to as opposed to data.csv
15 16 17
    p.on("-f PATH", "--file PATH", "Choose file to write to") do |new_path|
      ENV["file"] = new_path.empty? ? "data.csv" : new_path
    end
18 19 20 21 22 23 24

    # For importing AAT GPX file
    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
25 26
      exit
    end
27 28

    # Get help for this program
29 30 31 32
    p.on("-h", "--help", "Show this help") do
      puts p
      exit
    end
33

34 35 36 37 38 39 40 41
    # 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