Giter VIP home page Giter VIP logo

loop's Introduction

Logo, with help from Linn Kristiansen

loop Build Status crates.io

"UNIX's missing loop command!"

loop lets you write powerful, intuitive looping one-liners in your favorite shell! Finally, loops in Bash that make sense!

Why?

Loops in bash are surprisingly complicated and fickle! I wanted a simple and intuitive way to write controllable loops that:

  • Run on controllable timers!

    • $ loop --every 10s -- ls
  • Have custom counters!

    • $ loop --count-by 5 -- 'touch $COUNT.txt'
  • Loop until output matches a condition!

    • $ loop --until-contains 200 -- ./get_response_code.sh --site mysite.biz
  • Loop until a certain time!

    • $ loop --for-duration 8h -- ./poke_server
  • Loop until a program succeeds (or fails!)

    • $ loop --until-success -- ./poke_server
  • Iterate over the standard input!

    • $ cat files_to_create.txt | loop -- 'touch $ITEM'
  • Get a summary of the runs!

    • $ loop --for-duration 10min --summary -- ls
  • Run until output changes or stays the same between invocations!

    • $ loop --until-changes -- date +%s
    • $ loop --until-same -- date +%s
  • ..and much more!

And so loop was born!

Installation

Linux

loop is available on Snapcraft for all distributions as loop-rs.

$ snap install loop-rs --beta

Issues related to this package are tracked here.

There is also an AUR for Arch Linux users, but I don't maintain it, so use it at your own risk:

$ yaourt -S loop

OSX

If you're a Homebrew user:

$ brew tap miserlou/loop https://github.com/Miserlou/Loop.git
$ brew install loop --HEAD

Rust Users

$ cargo install loop-rs

Building

$ cargo build
./debug/loop
$ cargo run 'echo $COUNT'
1
2
[ .. ]

Usage

With no arguments, loop will simply repeatedly execute a command string as fast as it can until ^C (control + C) is sent.

$ loop 'echo hello'
hello
hello
hello
hello
[ .. ]

You can also use double dashes ( -- ) to seperate arguments:

$ loop -- echo hello
hello
hello
hello
hello
[ .. ]

Counters

loop places a counter value into the $COUNT environment variable.

$ loop -- 'echo $COUNT'
0
1
2
[ .. ]

The amount this counter increments can be changed with --count-by:

$ loop --count-by 2 -- 'echo $COUNT'
0
2
4
6
[ .. ]

The counter can be offset with --offset:

$ loop --count-by 2 --offset 10 -- 'echo $COUNT'
10
12
14
[ .. ]

And iterators can be floats!

$ loop --count-by 1.1 -- 'echo $COUNT'
0
1.1
2.2
[ .. ]

There's also an $ACTUALCOUNT:

$ loop --count-by 2 -- 'echo $COUNT $ACTUALCOUNT'
0 0
2 1
4 2
[ .. ]

You can get a summary of successes and failures (based on exit codes) with --summary:

$ loop --num 3 --summary -- 'echo $COUNT'
0
1
2
Total runs:  3
Successes:   3
Failures:    0

or

$ loop --num 3 --summary -- 'ls -foobarbatz'
[ .. ]
Total runs:  3
Successes:   0
Failures:    3 (1, 1, 1)

If you only want the output of the last result, you can use --only-last:

$ loop --count-by 2 --num 50 --offset 2 --only-last -- 'echo $COUNT' # Counting is 0-indexed
100

Timed Loops

Loops can be set to timers which accept humanized times from the microsecond to the year with --every:

$ loop --every 5s -- date
Thu May 17 10:51:03 EDT 2018
Thu May 17 10:51:08 EDT 2018
Thu May 17 10:51:13 EDT 2018

Looping can be limited to a set duration with --for-duration:

$ loop --for-duration 8s --every 2s -- date
Fri May 25 16:46:42 EDT 2018
Fri May 25 16:46:44 EDT 2018
Fri May 25 16:46:46 EDT 2018
Fri May 25 16:46:48 EDT 2018
$

Or until a certain date/time with --until-time:

$ loop --until-time '2018-05-25 20:50:00' --every 5s -- 'date -u'
Fri May 25 20:49:49 UTC 2018
Fri May 25 20:49:54 UTC 2018
Fri May 25 20:49:59 UTC 2018
$

Until Conditions

loop can iterate until output contains a string with --until-contains:

$ loop --until-contains "666" -- 'echo $RANDOM'
11235
35925
666
$

loop can iterate until the output changes with --until-changes:

$ loop --only-last --every 1s --until-changes -- 'date +%s'
1548884135
$

loop can iterate until the output stays the same with --until-same. This would be useful, for instance, for monitoring with du until a download or copy finishes:

$ loop --every 1s --until-same -- 'du -bs .'
236861997       .
$

Or until a program succeeds with --until-success:

$ loop --until-success -- 'if (( RANDOM % 2 )); then (echo "TRUE"; true); else (echo "FALSE"; false); fi'
FALSE
FALSE
TRUE
$

Or until it fails with --until-error (which also accepts an optional error code):

$ loop --until-error -- 'if (( RANDOM % 2 )); then (echo "TRUE"; true); else (echo "FALSE"; false); fi'
TRUE
TRUE
FALSE
$

Or until it matches a regular expression with --until-match:

$ loop --until-match "(\d{4})" -- `date`
Thu May 17 10:51:03 EDT 2018
$

Iterating Over Lists and Standard Inputs

Loops can iterate over all sorts of lists with --for:

$ loop --for red,green,blue -- 'echo $ITEM'
red
green
blue
$

And can read from the standard input via pipes:

$ cat /tmp/my-list-of-files-to-create.txt | loop -- 'touch $ITEM'
$ ls
hello.jpg
goodbye.jpg

This can be combined with various flags, such as --until-changes:

$ printf "%s\n" 1 1 3 | loop --until-changes -- echo '$ITEM'
1
1
3

$ seq 10 | loop --until-changes -- echo '$ITEM'
1
2

You can also easily pipe lists to loop:

$ ls -1 | loop -- 'cp $ITEM $ITEM.bak'; ls
hello.jpg
hello.jpg.bak

..or via the keyboard with -i:

$ loop -- 'echo $ITEM | tr a-z A-Z' -i
hello
world^D
HELLO
WORLD

--for can accept all sorts of lists:

$ loop --for "`ls`" -- 'echo $ITEM'
Cargo.lock
Cargo.toml
README.md
src
target
$

Useful Examples

Here are some handy things you can do with loop!

Testing inputs to a program

If you have a lot of files and a program, but don't know which file is the one the program takes, you can loop over them until you find it:

$ ls  -1 | loop --until-success -- './my_program $ITEM';

Or, if you have a list of files but need to find the one which causes your program to fail:

$ ls  -1 | loop --until-fail -- './my_program $ITEM';

Waiting for a website to appear online

If you've just kicked off a website deployment pipeline, you might want to run a process when the site starts returning 200 response codes. With --every and --until-contains, you can do this without flooding the site with requests:

$ ./deploy.sh; loop  --every 5s --until-contains 200 -- 'curl -sw "%{http_code}" http://coolwebsite.biz'; ./announce_to_slack.sh

Or until a host is online:

$ loop --until-success -- ping -c 1 mysite.com; ./do_next_thing

Waiting for a file to be created

If you have a long-running process that creates a new file, you might want to kick off another program when that process outputs a new file, like so:

$ ./create_big_file -o my_big_file.bin; loop --until-contains 'my_big_file.bin' -- 'ls'; ./upload_big_file my_big_file.bin

Create a backup for all files in a directory

If you've got a whole list of files that you want to create backup copies of, you can do it like so:

$ ls
hello.jpg
$ ls -1 | loop -- 'cp $ITEM $ITEM.bak'
$ ls
hello.jpg
hello.jpg.bak

Keep trying a failing script until it passes, up to 5 times

This is an example from StackExchange.

I want to write logic in shell script which will retry it to run again after 15 sec upto 5 times based on "status code=FAIL" if it fails due to some issue.

There are so many questions like this on StackExchange, which all end up with long threads of complicated answers.

With loop, it's a simple one liner:

loop --every 15s --until-success --num 5 -- './do_thing.sh'

Which will do the thing every 15 seconds until it succeeds, for a maximum of five times.

Keep trying a failing script until timeout

If dealing with a command or script that occasionally fails in a CI environment, you may want to try for a given amount of time before giving up and failing the build.

With loop you can do that with:

loop --every 5s --until-success --for-duration 180s --duration-error -- './do_thing.sh'

Which will do the thing every 5 seconds until it succeeds or until the duration is met. If the duration is met, it will give the same non-zero return as the timeout command 124.

Comparison with GNU Parallel

This thread on Reddit with GNU Parallel author Ole Tange has some interesting side-by-side comparisons between loop and parallel.

More examples

Got any more useful examples? Send a pull request!

Contributing

This project is still young, so there is still plenty to be done. Contributions are more than welcome!

Please file tickets for discussion before submitting patches. Pull requests should target master and should leave Loop in a "shippable" state if merged.

If you are adding a non-trivial amount of new code, please include a functioning test in your PR. The test suite will be run by Travis CI once you open a pull request. Please include the GitHub issue or pull request URL that has discussion related to your changes as a comment in the code (example). This greatly helps for project maintainability, as it allows us to trace back use cases and explain decision making. Similarly, please make sure that you meet all of the requirements listed in the pull request template.

Please feel free to work on any open ticket, especially any ticket marked with the "help-wanted" label!

License

(c) Rich Jones, 2018-2019+. MIT License.

loop's People

Contributors

arnidagur avatar art-of-dom avatar bobrippling avatar crazy-max avatar felipesere avatar fierthraix avatar gaetronik avatar k0ral avatar kpcyrd avatar madeddie avatar michaelmior avatar miserlou avatar paralax avatar tshepang avatar tspiteri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loop's Issues

Keep track of success/fail and provide a summary

I use looper to smoke out flaky tests.
As such, I run loop 'npm run test:acceptance' --num 5 and I look what the output is.
It would be awesome if at the end I could get a summary of success (0 exit code) vs unsuccessful (non-zero exit code) completions.

$ loop 'npm run test:acceptance' --num 5 --summary
...
Total: 5
Success: 4
Fail: 1

And then I'll know to take a closer look.
This would probably also work nicely with the other --until-*

With a bit of guidance I could give this a try 😄

cargo install fails on windows with unresolved import compilation error

I get the following error when I try to do cargo install loop-rs on Windows 7:

Compiling loop-rs v0.3.3
error[E0432]: unresolved import `isatty::stdin_isatty`
  --> src\main.rs:16:14
   |
16 | use isatty::{stdin_isatty};
   |              ^^^^^^^^^^^^ no `stdin_isatty` in the root. Did you mean to use `stderr_isatty`?

Here is my rustup show output:

Default host: x86_64-pc-windows-msvc
installed toolchains
--------------------
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.27.0 (3eda71b00 2018-06-19)

Add --detach option

This a tricky but important one.

Current behavior is this:

$ loop "date; sleep 5; " --every 2s
Fri Jun 15 16:08:58 EDT 2018
Fri Jun 15 16:09:03 EDT 2018
Fri Jun 15 16:09:08 EDT 2018

I want a way to:

$ loop "date; sleep 5; " --every 2s --detach
Fri Jun 15 16:08:58 EDT 2018
Fri Jun 15 16:09:00 EDT 2018
Fri Jun 15 16:09:02 EDT 2018

If this is incompatible with --until-* that's okay, although obviously that'd be preferred.

Normalize Usage in Readme

We use loop 'ls' formatting in some places and loop -- ls other places. We should normalize this to one or the other, now I'm leaning towards the latter.

stdin Broken

Goddammit

ls | loop -- "cat $ITEM"

That used to work and now it doesn't, motherfuck.

Could not compile `loop-rs`

error[E0631]: type mismatch in function arguments
   --> /Users/marcin/.cargo/registry/src/github.com-1ecc6299db9ec823/loop-rs-0.6.1/src/main.rs:238:48
    |
238 |     #[structopt(long = "for", parse(from_str = "get_values"))]
    |                                                ^^^^^^^^^^^^ expected signature of `fn(&str) -> _`
...
322 | fn get_values(input: &&str) -> Vec<String> {
    | ------------------------------------------ found signature of `for<'r, 's> fn(&'r &'s str) -> _`

error[E0631]: type mismatch in function arguments
   --> /Users/marcin/.cargo/registry/src/github.com-1ecc6299db9ec823/loop-rs-0.6.1/src/main.rs:266:69
    |
266 |     #[structopt(short = "r", long = "until-error", parse(from_str = "get_error_code"))]
    |                                                                     ^^^^^^^^^^^^^^^^ expected signature of `fn(&str) -> _`
...
314 | fn get_error_code(input: &&str) -> ErrorCode {
    | -------------------------------------------- found signature of `for<'r, 's> fn(&'r &'s str) -> _`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0631`.
error: failed to compile `loop-rs v0.6.1`, intermediate artifacts can be found at `/var/folders/gw/053czpm957z2rq6k8xqvnxx00000gn/T/cargo-installBihqf5`

Caused by:
  could not compile `loop-rs`

My rust version:

$ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/marcin/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.54.0 (a178d0322 2021-07-26)

Maintainer Needed

I think this tool is useful, but I've let it rot. Need a maintainer to triage and get a version release ready.

Pipe closing isn't handled gracefully

When loop is piped to some program that only takes a subset of loop's output the program prints throws a panic message that may confuse people when used as part of a long command chain.

Example:

user@pc $ loop 'echo $COUNT' | head -n 2
0
1
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', libstd/io/stdio.rs:692:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

The expected behaviour is that loop exits gracefully upon detecting the pipe is closed.

`--until-time` is in UTC

When using the --until-time flag the timestamps you use are implicitly in UTC. It would be nice to this default to the computer's local time, or have a flag to specify the timezone.

Parallel execution

It would be nice if loop-rs could run the loop body in parallel (using num-cpu).
Suggestion for the flag name: --parallel -p.

How to pass through stdout?

We have a bunch of images that need to be pushed to a registry so often, so we do them all in one big script. Problem is Gitlab's container registry constantly fails all the time so loop is a perfect fit for this.
Trying something like:

loop -s --summary -- scripts/push-images.sh (tried with -i as well)

But the problem is that there is zero output.

Whereas normally our scripts/push-images.sh outputs something like:

Pushing registry.gitlab.com/thing:prod
The push refers to repository [registry.gitlab.com/thing]
8850e5e866c3: Preparing
6d1eb370deee: Preparing
e6a9e93f2e3d: Preparing
f721b22510f1: Preparing
371e12a4bca7: Preparing
c97278a08a46: Preparing
7bff100f35cb: Preparing
c97278a08a46: Waiting

And updates as the scripts progress through each image.

Is there anyway to keep that stdout and print it to term live as loop receives it from the subprocess?

Error codes in summary are reported as negative numbers

Error codes of executed commands are reported in summary with minus sign as shown bellow:

loop --for=0,1,2,3,4,5 --until-error 5 --summary -- exit '$ITEM'
returns
Total runs: 6 Successes: 1 Failures: 5 (-1, -2, -3, -4, -5)

I would expect to return
Total runs: 6 Successes: 1 Failures: 5 (1, 2, 3, 4, 5)

Continuous output during execution and refactoring

Hello @Miserlou

I used loop some times for running tests etc and it's very very useful. A missing feature for me has always been that the output is not printed immediately and just after the program exits. Furthermore the stdout and stderr is merged which is sometimes bad.

I tried to fix those things but ended up with a more or less rewrite of loop based on tokio for the io and child process handling. The CLI interface is almost the same. I pushed it and I'm using it since a couple of days. I probably needs some more polishing but in general works.
Let me know if you're interested in this branch.

Thanks for the missing loop command ;-)

Duration/Until Time Appears To Have An Extra First Iteration

~/Projects/Loop/looper $ loop 'date' --for-duration 8s --every 2s
Mon Feb  4 16:12:33 EST 2019
Mon Feb  4 16:12:35 EST 2019
Mon Feb  4 16:12:37 EST 2019
Mon Feb  4 16:12:39 EST 2019
Mon Feb  4 16:12:41 EST 2019
~/Projects/Loop/looper $ loop 'date -u' --until-time '2018-05-25 20:50:00' --every 5s
Mon Feb  4 21:13:01 UTC 2019

Again, I think this was caused by blindly accepting that "refactor" to make the code "better"

Better example/support for reading lines from a file

This command gives weird behavior:

cargo run "echo $ITEM" --for "`cat README.md`"

It'd be great to have a better example for this use case, either a) fixing this behavior, b) explicitly adding the ability to read in a file from stdin c) adding explicit reading of a file or d) all of the above.

Loop over JSON input

Maybe something like..

$ loop 'echo $VALUE > $KEY' --for-dict "{'hello', 'world'}"
$ cat hello
world

Loop `until` Options

A number of options I want here:

  • --until-contains: loops until output contains a string
  • --until-match: loops until output matches a pattern
  • --until-error: loops until there is a non-success error code
  • --until-success: loops until there is a success error code

Commit cargo.lock

The official recommendation is that this should be committed into the repository. Since it's a binary, compatibility with other versions of libraries isn't important and having the lock file around can potentially help avoid annoying breakages in the future.

Only show final output

Curious what you think of this feature request. With the --until-* options, sometimes I only care about the output of the last command. It would be nice if there was a flag that enabled this behaviour. I'd imagine it would work by redirecting standard error and standard output to files and then printing the files after the last command runs.

README out of date

The README makes it seem that --until-error does not require an argument:

Or until it fails with --until-error (which also accepts an optional error code):

But when I try it without an argument, I get this:

error: The argument '--until-error <until_error>' requires a value but none was supplied

USAGE:
    loop <input> --count-by <count_by> --every <every> --offset <offset> --until-error <until_error>

So I think that maybe --until-fail is what I want, based on this:

Or, if you have a list of files but need to find the one which causes your program to fail:
$ ls | loop './my_program $ITEM' --until-fail;

But I get this:

error: Found argument '--until-fail' which wasn't expected, or isn't valid in this context

And I still don't know how to run a command until it fails. Seems like it is currently impossible.

Errors running `cargo test`

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/foobar/.rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.63.0 (4b91a6ea7 2022-08-08)
$ cargo test

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 11 tests
test item ... ok
test no_of_iterations ... ok
test only_last ... ok
test summary ... FAILED
test until_changes ... ok
test until_error ... FAILED
test until_contains ... ok
test until_fail ... FAILED
test until_success ... FAILED
test until_same ... FAILED
test counter ... ok

failures:

---- summary stdout ----
thread 'summary' panicked at 'Unexpected stdout, failed diff original var
├── original: Total runs:	3
│   Successes:	2
│   Failures:	1 (-1)
├── diff:
│   --- 	orig
│   +++ 	var
│   @@ -3 +3 @@
│   -Failures:	1 (-1)
│   +Failures:	1 (1)
└── var as str: Total runs:	3
    Successes:	2
    Failures:	1 (1)

command=`"/home/foobar/src/contrib/Loop/target/debug/loop" "--for=true,false,true" "--summary" "--" "$ITEM"`
code=0
stdout=```"Total runs:\t3\nSuccesses:\t2\nFailures:\t1 (1)\n"```
stderr=```""```
', /home/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/assert_cmd-1.0.8/src/assert.rs:124:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- until_error stdout ----
thread 'until_error' panicked at 'Unexpected failure.
code-1
stderr=```"error: The argument \'--until-error <until_error>\' requires a value but none was supplied\n\nUSAGE:\n    loop --count-by <count_by> --every <every> --for <ffor> --offset <offset> --summary --until-error <until_error>\n\nFor more information try --help\n"```
command=`"/home/foobar/src/contrib/Loop/target/debug/loop" "--for=true,true,false,true,true,true" "--until-error" "--summary" "--" "$ITEM"`
code=1
stdout=```""```
stderr=```"error: The argument \'--until-error <until_error>\' requires a value but none was supplied\n\nUSAGE:\n    loop --count-by <count_by> --every <every> --for <ffor> --offset <offset> --summary --until-error <until_error>\n\nFor more information try --help\n"```
', /home/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/assert_cmd-1.0.8/src/assert.rs:124:9

---- until_fail stdout ----
thread 'until_fail' panicked at 'Unexpected stdout, failed diff original var
├── original: Total runs:	3
│   Successes:	2
│   Failures:	1 (-1)
├── diff:
│   --- 	orig
│   +++ 	var
│   @@ -3 +3 @@
│   -Failures:	1 (-1)
│   +Failures:	1 (1)
└── var as str: Total runs:	3
    Successes:	2
    Failures:	1 (1)

command=`"/home/foobar/src/contrib/Loop/target/debug/loop" "--for=true,true,false,true,true,true" "--until-fail" "--summary" "--" "$ITEM"`
code=0
stdout=```"Total runs:\t3\nSuccesses:\t2\nFailures:\t1 (1)\n"```
stderr=```""```
', /home/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/assert_cmd-1.0.8/src/assert.rs:124:9

---- until_success stdout ----
thread 'until_success' panicked at 'Unexpected stdout, failed diff original var
├── original: Total runs:	4
│   Successes:	1
│   Failures:	3 (-1, -1, -1)
├── diff:
│   --- 	orig
│   +++ 	var
│   @@ -3 +3 @@
│   -Failures:	3 (-1, -1, -1)
│   +Failures:	3 (1, 1, 1)
└── var as str: Total runs:	4
    Successes:	1
    Failures:	3 (1, 1, 1)

command=`"/home/foobar/src/contrib/Loop/target/debug/loop" "--for=false,false,false,true,false,false" "--until-success" "--summary" "--" "$ITEM"`
code=0
stdout=```"Total runs:\t4\nSuccesses:\t1\nFailures:\t3 (1, 1, 1)\n"```
stderr=```""```
', /home/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/assert_cmd-1.0.8/src/assert.rs:124:9

---- until_same stdout ----
thread 'until_same' panicked at 'Unexpected stdout, failed diff original var
├── original: 5
├── diff:
│   --- 	orig
│   +++ 	var
│   @@ -1 +1 @@
│   -5
│   +7
└── var as str: 7

command=`"/home/foobar/src/contrib/Loop/target/debug/loop" "--for=1,2,3,4,5,5,6,7" "--until-same" "--only-last" "--" "echo $ITEM"`
code=0
stdout=```"7\n"```
stderr=```""```
', /home/foobar/.cargo/registry/src/github.com-1ecc6299db9ec823/assert_cmd-1.0.8/src/assert.rs:124:9


failures:
    summary
    until_error
    until_fail
    until_same
    until_success

test result: FAILED. 6 passed; 5 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

Compilation errors in Debian 9

Ran $ cargo build and rustc (ver 1.24.1) output the following:

   Compiling loop-rs v0.4.0 (file:///home/um-li/Downloads/Loop)
error: non-reference pattern used to match a reference (see issue #42640)
  --> src/main.rs:99:20
   |
99 |             if let Some(string) = &opt.until_contains {
   |                    ^^^^^^^^^^^^ help: consider using a reference: `&Some(string)`

error: non-reference pattern used to match a reference (see issue #42640)
   --> src/main.rs:106:20
    |
106 |             if let Some(regex) = &opt.until_match {
    |                    ^^^^^^^^^^^ help: consider using a reference: `&Some(regex)`

error: non-reference pattern used to match a reference (see issue #42640)
   --> src/main.rs:114:16
    |
114 |         if let Some(error_code) = &opt.until_error {
    |                ^^^^^^^^^^^^^^^^ help: consider using a reference: `&Some(error_code)`

error: non-reference pattern used to match a reference (see issue #42640)
   --> src/main.rs:116:17
    |
116 |                 ErrorCode::Any => if !result.exit_status.success() {
    |                 ^^^^^^^^^^^^^^ help: consider using a reference: `&ErrorCode::Any`

error: non-reference pattern used to match a reference (see issue #42640)
   --> src/main.rs:119:17
    |
119 |                 ErrorCode::Code(code) =>  {
    |                 ^^^^^^^^^^^^^^^^^^^^^ help: consider using a reference: `&ErrorCode::Code(code)`

error: aborting due to 5 previous errors

error: Could not compile `loop-rs`.

Add support for unquoted command strings after `--`

via this comment:

Lovely idea. I have a small amount of "issue" with the way you're doing the command line though. It's more typical to see commandlines of the form:

loop --every 15s --until-success --num 5 ./do_thing.sh

i.e. where you give the command "last" and where if you want to give that command arguments, you use -- to separate:

loop --until-success -- ping -c5 myserver

As a long-time CLI user, having to put the command, and its arguments, first just feels wrong.

Well done on your project though, and +1 for using clap :-)

`--until-changes` for when you wait for the stdout to alter

A feature request that would be immensely useful to me since I often find myself waiting for something to change.

Let's say I want to be notified when my packages are finally synced to maven. Then I could do
loop --until-changes 'curl https://repo1.maven.org/maven2/com/github/dkhalansky/paradisenglib_2.12.3/'
This invocation would then first run the specified curl command, remembering some hash of the output, and then run the command periodically until the hash of the output changes. After that, the execution would end.

Or I could wait for anyone to log into my system or log out of it. Then I could do loop --until-changes 'w -hs'.

If multiple non-option arguments are passed, treat them as a command

find and xargs allow to pass to them commands in such ways:
find . -exec ls -l ';'
xargs echo 3 4 5
This is arguably better than find . -exec "ls -l" because this way you don't have to think as much about the nested strings that can already be a pain when using the shell.

So it would greatly simplify life in some complex cases if loop supported syntax like loop [options here] -- command arg1 arg.

v0.6.1 on crates.io fails to compile

Attempting to install via cargo install loop-rs gives the following compilation errors:

error[E0631]: type mismatch in function arguments
   --> /Users/wmcgann/.cargo/registry/src/github.com-1ecc6299db9ec823/loop-rs-0.6.1/src/main.rs:216:10
    |
216 | #[derive(StructOpt, Debug)]
    |          ^^^^^^^^^ expected signature of `fn(&str) -> _`
...
322 | fn get_values(input: &&str) -> Vec<String> {
    | ------------------------------------------ found signature of `for<'r, 's> fn(&'r &'s str) -> _`

error[E0631]: type mismatch in function arguments
   --> /Users/wmcgann/.cargo/registry/src/github.com-1ecc6299db9ec823/loop-rs-0.6.1/src/main.rs:216:10
    |
216 | #[derive(StructOpt, Debug)]
    |          ^^^^^^^^^ expected signature of `fn(&str) -> _`
...
314 | fn get_error_code(input: &&str) -> ErrorCode {
    | -------------------------------------------- found signature of `for<'r, 's> fn(&'r &'s str) -> _`

error: aborting due to 2 previous errors
$ cargo version && rustc --version
cargo 1.35.0 (6f3e9c367 2019-04-04)
rustc 1.35.0 (3c235d560 2019-05-20)

Cloning and buliding/installing the master branch works without issue.

offset and count-by are not working as expected.

Readme includes this:

$ loop 'echo $COUNT' --count-by 2 --offset 10
10
12
14
[ .. ]

When I run it on Mac OS X 10.12.6 with loop 0.3.3 installed per brew instructions I get...

$ loop 'echo $COUNT' --count-by 2 --offset 10
0
1
2
3
4
5
6
7
8
9
10
11
[..]

offset and count-by are not working as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.