Skip to content

Commit 2ac4e17

Browse files
author
Francis Murillo
committed
Working clap
1 parent 511637a commit 2ac4e17

2 files changed

Lines changed: 71 additions & 45 deletions

File tree

seq/src/main.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
use std::process;
22

33
use clap::{load_yaml, App};
4-
use sugars::sleep;
54

65
fn main() {
76
let yaml = load_yaml!("seq.yml");
87
let matches = App::from_yaml(yaml).get_matches();
98

10-
let numbers = match matches.values_of("NUMBER") {
11-
Some(values) => values,
12-
None => {
13-
eprintln!("sleep: Missing operand.\nTry 'sleep --help' for more information.");
14-
process::exit(1);
15-
}
16-
};
17-
18-
let total: u64 = numbers.filter_map(|s| s.parse::<u64>().ok()).sum();
19-
20-
let suffix = if matches.is_present("suffix") {
21-
matches.value_of("suffix").unwrap()
22-
} else {
23-
"s"
24-
};
25-
26-
match suffix {
27-
"s" | "sec" => sleep!(total sec),
28-
"m" | "min" => sleep!(total min),
29-
"h" | "hour" => {
30-
let total = 60 * total;
31-
sleep!(total min)
32-
}
33-
_ => {
34-
eprintln!("sleep: Invalid suffix value. It must be 'sec', 'min', 'hour', 's', 'm' or 'h'.\nFor more information, try 'sleep --help'.");
35-
process::exit(1);
36-
}
37-
}
9+
10+
std::dbg!(matches);
11+
12+
// let numbers = match matches.values_of("NUMBER") {
13+
// Some(values) => values,
14+
// None => {
15+
// eprintln!("sleep: Missing operand.\nTry 'sleep --help' for more information.");
16+
// process::exit(1);
17+
// }
18+
// };
19+
20+
// let total: u64 = numbers.filter_map(|s| s.parse::<u64>().ok()).sum();
21+
22+
// let suffix = if matches.is_present("suffix") {
23+
// matches.value_of("suffix").unwrap()
24+
// } else {
25+
// "s"
26+
// };
27+
28+
// match suffix {
29+
// "s" | "sec" => sleep!(total sec),
30+
// "m" | "min" => sleep!(total min),
31+
// "h" | "hour" => {
32+
// let total = 60 * total;
33+
// sleep!(total min)
34+
// }
35+
// _ => {
36+
// eprintln!("sleep: Invalid suffix value. It must be 'sec', 'min', 'hour', 's', 'm' or 'h'.\nFor more information, try 'sleep --help'.");
37+
// process::exit(1);
38+
// }
39+
// }
3840
}

seq/src/seq.yml

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
name: seq
22
version: "0.0.0"
3-
author:
4-
- Eric Shimizu Karbstein <gr41.j4ck@gmail.com>
5-
- Francis Murillo <francisavmurillo@gmail.com>
6-
about: "Suspends execution for a NUMBER of SUFFIX time.\nSUFFIX can be 'sec' or 's' for seconds, 'min' or 'm' for minutes, 'hour' or 'h' for hours."
3+
author: Francis Murillo <francisavmurillo@gmail.com>
4+
about: "Print a sequence of numbers"
5+
long_about: >
6+
Print numbers from FIRST to LAST, in steps of INCREMENT.
7+
usage: >
8+
9+
[OPTIONS] <LAST>
10+
11+
[OPTIONS] <FIRST> <LAST>
12+
13+
[OPTIONS] <FIRST> <INCREMENT> <LAST>
714
args:
8-
- LAST:
9-
help: Number to set the sleep. If more than one, will sleep the sum of the numbers.
10-
required: true
1115
- FIRST:
12-
help: Number to set the sleep. If more than one, will sleep the sum of the numbers.
13-
required: false
16+
help: >
17+
The initial number to start the sequence.
18+
long_help: >
19+
The initial number to start the sequence.
20+
21+
22+
This must not be NaN. If omitted, defaults to 1.
1423
- INCREMENT:
15-
help: Number to set the sleep. If more than one, will sleep the sum of the numbers.
16-
required: false
17-
- suffix:
18-
help: A optional parameter to set the time measurement to be used. The default is seconds.
19-
long: suffix
20-
short: s
21-
value_name: SUFFIX
24+
help: >
25+
The step/increment added after each preceeding number in the
26+
sequence.
27+
long_help: >
28+
The step/increment added after each preceeding number in the
29+
sequence.
30+
31+
32+
If FIRST is greater than LAST, this should be a positive
33+
number; if less than, this should be a negative number. This
34+
must not be 0 or NaN. If omitted, defaults to 1 even if FIRST
35+
is greater than LAST.
36+
- LAST:
37+
help: >
38+
The limit of the sequence.
39+
long_help: >
40+
The limit of the sequence.
41+
42+
43+
If the next number in a sequence exceeds above or falls below
44+
LAST whether STEP is positive or negative respectively, the
45+
sequence ends. This must not be NaN.

0 commit comments

Comments
 (0)