mirror of
https://github.com/Miserlou/Loop
synced 2024-07-01 06:34:24 +00:00
adds until contains and travisyml
This commit is contained in:
parent
f832bd9ae3
commit
bb1df5d827
10
.travis.yml
Normal file
10
.travis.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
language: rust
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
fast_finish: true
|
||||
|
|
@ -39,6 +39,14 @@ Limited loops:
|
|||
./hello.txt
|
||||
$
|
||||
|
||||
Looping until conditions are met:
|
||||
|
||||
$ loop 'echo $RANDOM' --until-contains "666"
|
||||
11235
|
||||
35925
|
||||
666
|
||||
$
|
||||
|
||||
## Installation
|
||||
|
||||
Not published yet.
|
||||
|
@ -67,3 +75,4 @@ Iterators can be floats!
|
|||
2 1
|
||||
4 2
|
||||
[ .. ]
|
||||
|
||||
|
|
|
@ -24,4 +24,10 @@ args:
|
|||
long: every
|
||||
value_name: every
|
||||
help: How often to iterate
|
||||
takes_value: true
|
||||
- until_contains:
|
||||
short: c
|
||||
long: until-contains
|
||||
value_name: until_contains
|
||||
help: Keep going until the output contains this string
|
||||
takes_value: true
|
25
src/main.rs
25
src/main.rs
|
@ -34,6 +34,15 @@ fn main() {
|
|||
// Delay time
|
||||
let every = parse_duration(matches.value_of("every").unwrap_or("1us")).unwrap();
|
||||
|
||||
// --until-*
|
||||
let mut has_matched = false;
|
||||
let mut has_until_contains = false;
|
||||
let mut until_contains = "";
|
||||
if matches.is_present("until_contains"){
|
||||
has_until_contains = true;
|
||||
until_contains = matches.value_of("until_contains").unwrap();
|
||||
}
|
||||
|
||||
// Counters
|
||||
let mut count = 0.0;
|
||||
let mut adjusted_count = 0.0;
|
||||
|
@ -46,6 +55,7 @@ fn main() {
|
|||
// Executor/readers
|
||||
let mut executor;
|
||||
let mut buf_reader;
|
||||
let mut line;
|
||||
|
||||
while count < num {
|
||||
|
||||
|
@ -57,8 +67,19 @@ fn main() {
|
|||
buf_reader = BufReader::new(executor);
|
||||
|
||||
// Print the results
|
||||
for (_i, line) in buf_reader.lines().enumerate() {
|
||||
println!("{}", line.unwrap());
|
||||
for (_i, rline) in buf_reader.lines().enumerate() {
|
||||
line = rline.unwrap();
|
||||
println!("{}", line);
|
||||
if has_until_contains{
|
||||
if line.contains(until_contains){
|
||||
has_matched=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finish if we matched
|
||||
if has_matched {
|
||||
return;
|
||||
}
|
||||
|
||||
// Increment counters
|
||||
|
|
Loading…
Reference in New Issue
Block a user