Commit 58b34a43 authored by Konstantine's avatar Konstantine 💮

v0.2.1 moved options to src/options, added option to change csv file

parent 25ce96a5
......@@ -4,4 +4,3 @@
/.shards/
*.dwarf
*.csv
cycling
......@@ -24,11 +24,25 @@ I wanted it to be simple and not get in the way, so simply running `cycling` sho
$ cycling
```
### Changing File Output
If you want the program to create a new file in a particular place within your filesystem specify it with the `-f` flag
``` sh
$ cycling -f <new file>
```
or
``` sh
$ cycling --file <new file>
```
### Getting Help
The program accepts flags, use `-h` to read about them.
``` sh
$ cycling -h
```
or
``` sh
$ cycling --help
```
### Other Flags
I want to add more flags so you can import data from AAT and output into stdout for piping in the console.
......
require "option_parser"
require "csv"
require "./cycling/**"
module Cycling
VERSION = "0.1.5"
@@data : String = "data.csv"
VERSION = "0.2.1"
# Option Flags to select different options for things
OptionParser.parse do |parser|
parser.banner = "Usage: cycling [arguments]"
parser.on("-o", "--output", "Output the data to I/O for use in other programs"){puts "Not Available yet..."}
parser.on("-h", "--help", "Show this help") do
puts parser
exit
end
# If flag unknown show help but show error
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
# Initializing
Cycling::Options
ENV["file"] ||= "./data.csv"
# Create a new file if once doesn't exist
def self.create_file()
File.touch(@@data) # Create new file
File.touch(ENV["file"]) # Create new file
# Create Header Row
first_row = CSV.build do |csv|
csv.row "Date",
......@@ -35,11 +22,11 @@ module Cycling
"Cadence",
"Comments"
end
File.write(@@data, first_row) # Write to file
File.write(ENV["file"], first_row) # Write to file
end
# Check if data file exist or create it
File.exists?(@@data) ? true : Cycling.create_file()
File.exists?(ENV["file"]) ? true : Cycling.create_file()
# Create new row of test data
def self.build_file()
......@@ -75,9 +62,9 @@ module Cycling
csv.row d1,d2,d3,d4,d5,d6,d7,d8
end
# Write data to file
File.write(@@data, result, mode: "a")
File.write(ENV["file"], result, mode: "a")
end
Cycling.build_file()
# Some Text to know it all worked.
puts "Success: Data written to #{@@data}."
puts "Success: Data written to #{ENV["file"]}."
end
require "option_parser"
require "../cycling"
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
p.on("-f PATH", "--file PATH", "Choose file to write to") do |new_path|
ENV["file"] = new_path.empty? ? "data.csv" : new_path
end
p.on("-a", "--aat", "Put path to AAT data file to input") do
puts "Not Available"
exit
end
p.on("-h", "--help", "Show this help") do
puts p
exit
end
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment