Skip to content

Commit

Permalink
convert subcommand enhancement
Browse files Browse the repository at this point in the history
supports converting in both ways now
  • Loading branch information
elektronenhirn committed Mar 17, 2021
1 parent 265638b commit 8d69b80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Converts a calendar week version string into an ISO date. E.g.:
✗ cwver convert 21w05.6
21w05.6 = 2021-02-06

Or the other way around:

✗ cwver convert 2021-02-06
2021-02-06 = 21w05.6

### today

Prints today's date in the calender week format. E.g.
Expand Down
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn main() -> Result<(), String> {
)
.subcommand(
App::new("convert")
.about("Convert cw version string (e.g. 21w45.7) into ISO date.")
.about("Convert cw version string (e.g. 21w45.7) into ISO date (2021-11-14) or vice versa.")
.arg(
Arg::with_name("cw_ver_str")
Arg::with_name("data_str")
.help("cw version string")
.index(1)
.required(true),
Expand Down Expand Up @@ -61,12 +61,18 @@ fn main() -> Result<(), String> {
Ok(())
}
Some("convert") => {
let cw_ver_str = matches
let date_str = matches
.subcommand_matches("convert")
.unwrap()
.value_of("cw_ver_str")
.value_of("data_str")
.unwrap();
println!("{} = {:?}", cw_ver_str, cwver_str_to_date(cw_ver_str)?);
match date_str.contains("w") {
true => println!("{} = {:?}", date_str, cwver_str_to_date(date_str)?),
false => {
let str_as_date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d").map_err(|_| format!("Failed to parse ISO date {}", date_str))?;
println!("{} = {}", date_str, date_to_cwver_str(&str_as_date));
}
}
Ok(())
}
Some("bisect") => {
Expand Down

0 comments on commit 8d69b80

Please sign in to comment.