Skip to content

Commit

Permalink
fix: argument parsing with clap; notifies user if file is not .fit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeromos Kovacs committed Jul 4, 2024
1 parent 8913774 commit f94ad44
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 2 deletions.
193 changes: 193 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.8", features = ["derive"] }
fit-rust = "0.1.8"
geo-types = "0.7.13"
gpx = "0.10.0"
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::Parser;
use fit_rust::{
protocol::{message_type::MessageType, value::Value, DataMessage, FitMessage},
Fit,
Expand All @@ -7,6 +8,12 @@ use gpx::{Gpx, GpxVersion, Track, TrackSegment, Waypoint};
use std::{fs, fs::File, io::BufWriter};
use time::OffsetDateTime;

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
pub files: Vec<String>,
}

#[derive(Clone, Copy, Default, Debug, PartialEq)]
struct RecordData {
/// latitude
Expand Down Expand Up @@ -104,10 +111,14 @@ impl From<RecordData> for Waypoint {

fn main() {
// collecting cli args
let args = std::env::args().collect::<Vec<_>>();
let args = Args::parse();

let mut handles = vec![];
for file in args.iter().skip(1).filter(|f| f.ends_with(".fit")) {
for file in args.files.iter() {
if !file.ends_with(".fit") {
eprintln!("invalid file: {file:?}");
continue;
}
let file = file.clone();
let jh = std::thread::spawn(move || {
fit2gpx(&file);
Expand Down

0 comments on commit f94ad44

Please sign in to comment.