Fix for older builds

Rust 1.19 will be a requirement, however.
This commit is contained in:
Michael Aaron Murphy 2017-10-14 13:14:18 -04:00
parent 137fe2e697
commit fb1cd3a322
6 changed files with 29 additions and 18 deletions

View File

@ -44,13 +44,13 @@ matrix:
env: TARGET=x86_64-apple-darwin
# Minimum Rust supported channel.
- os: linux
rust: 1.16.0
rust: 1.19.0
env: TARGET=x86_64-unknown-linux-gnu
- os: linux
rust: 1.16.0
rust: 1.19.0
env: TARGET=x86_64-unknown-linux-musl
- os: osx
rust: 1.16.0
rust: 1.19.0
env: TARGET=x86_64-apple-darwin
notifications:

View File

@ -110,13 +110,16 @@ for generating commands is similar to that of GNU Parallel:
```sh
# Demonstration of parallel job execution
fd '*.flac' --exec 'sleep 1; echo $\{SHELL}: {}'
fd -e flac --exec 'sleep 1; echo $\{SHELL}: {}'
# This also works, because `SHELL` is not a valid token
fd '*.flac' --exec 'sleep 1; echo ${SHELL}: {}'
fd -e flac --exec 'sleep 1; echo ${SHELL}: {}'
# The token is optional -- it gets added at the end by default.
fd -e flac --exec 'echo'
# Real world example of converting flac files into opus files.
fd '*.flac' --type f --exec 'ffmpeg -i "{}" -c:a libopus "{.}.opus"'
fd -e flac --type f --exec 'ffmpeg -i "{}" -c:a libopus "{.}.opus"'
```
## Install

View File

@ -98,6 +98,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg(
arg("exec")
.long("exec")
.short("x")
.takes_value(true)
)
.arg(arg("pattern"))

View File

@ -1,5 +1,5 @@
use std::process::Command;
use std::env;
use std::process::Command;
lazy_static! {
/// On non-Windows systems, the `SHELL` environment variable will be used to determine the

View File

@ -57,7 +57,7 @@ impl TokenizedCommand {
text.push(character);
}
text.push(nchar);
}
},
// When a raw '{' is discovered, we will note it's position, and use that for a
// later comparison against valid placeholder tokens.
'{' if flags & OPEN == 0 => {
@ -67,24 +67,25 @@ impl TokenizedCommand {
append(&mut tokens, &text);
text.clear();
}
}
},
// If the `OPEN` bit is set, we will compare the contents between the discovered
// '{' and '}' characters against a list of valid tokens, then pushing the
// corresponding token onto the `tokens` vector.
'}' if flags & OPEN != 0 => {
flags ^= OPEN;
match &input[start+1..id] {
"" => {
tokens.push(Token::Placeholder);
flags |= PLACE;
}
"" => tokens.push(Token::Placeholder),
"." => tokens.push(Token::NoExt),
"/" => tokens.push(Token::Basename),
"//" => tokens.push(Token::Parent),
"/." => tokens.push(Token::BasenameNoExt),
_ => append(&mut tokens, &input[start..id+1]),
_ => {
append(&mut tokens, &input[start..id+1]);
continue
},
}
}
flags |= PLACE;
},
// We aren't collecting characters for a text string if the `OPEN` bit is set.
_ if flags & OPEN != 0 => (),
// Push the character onto the text buffer
@ -101,7 +102,7 @@ impl TokenizedCommand {
tokens.push(Token::Placeholder)
}
TokenizedCommand { tokens }
TokenizedCommand { tokens: tokens }
}
/// Generates a ticket that is required to execute the generated command.
@ -174,5 +175,11 @@ mod tests {
assert_eq!(TokenizedCommand::new("echo $\\{SHELL}: {}"), expected);
assert_eq!(TokenizedCommand::new("echo ${SHELL}:"), expected);
assert_eq!(TokenizedCommand::new("echo {.}"), TokenizedCommand {
tokens: vec![
Token::Text("echo ".into()),
Token::NoExt,
],
});
}
}

View File

@ -60,7 +60,7 @@ pub fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions
if let Some(ref cmd) = rx_config.command {
let shared_rx = Arc::new(Mutex::new(rx));
// This is safe because the `cmd` will exist beyond the end of this scope.
// This is safe because `cmd` will exist beyond the end of this scope.
// It's required to tell Rust that it's safe to share across threads.
let cmd = unsafe { Arc::from_raw(cmd as *const TokenizedCommand) };
@ -78,7 +78,7 @@ pub fn scan(root: &Path, pattern: Arc<Regex>, base: &Path, config: Arc<FdOptions
}
// Wait for all threads to exit before exiting the program.
handles.into_iter().for_each(|h| h.join().unwrap());
for h in handles { h.join().unwrap(); }
} else {
let start = time::Instant::now();