Permalink
Browse files

Further rustfmt improvements

  • Loading branch information...
mmstick committed Sep 21, 2017
1 parent 4b90fbc commit a61f0ec9bfc4e9d3a6900b6fc363a431edca1816
Showing with 593 additions and 708 deletions.
  1. +2 −2 build.rs
  2. +8 −3 rustfmt.toml
  3. +1 −4 src/ascii_helpers.rs
  4. +1 −1 src/builtins/calc.rs
  5. +4 −4 src/builtins/echo.rs
  6. +12 −35 src/builtins/exists.rs
  7. +2 −2 src/builtins/ion.rs
  8. +8 −13 src/builtins/job_control.rs
  9. +25 −28 src/builtins/mod.rs
  10. +6 −8 src/builtins/set.rs
  11. +21 −43 src/builtins/test.rs
  12. +15 −15 src/builtins/variables.rs
  13. +2 −2 src/parser/arguments.rs
  14. +8 −13 src/parser/assignments/actions.rs
  15. +2 −2 src/parser/assignments/keys.rs
  16. +7 −7 src/parser/assignments/splitter.rs
  17. +1 −1 src/parser/loops/for_grammar.rs
  18. +11 −11 src/parser/pipelines/collector.rs
  19. +3 −4 src/parser/quotes.rs
  20. +1 −4 src/parser/shell_expand/braces.rs
  21. +17 −39 src/parser/shell_expand/mod.rs
  22. +13 −12 src/parser/shell_expand/ranges.rs
  23. +67 −78 src/parser/shell_expand/words.rs
  24. +5 −5 src/parser/statement/case.rs
  25. +12 −14 src/parser/statement/parse.rs
  26. +4 −4 src/parser/statement/splitter.rs
  27. +76 −78 src/shell/assignments.rs
  28. +13 −15 src/shell/binary.rs
  29. +8 −7 src/shell/colors.rs
  30. +22 −23 src/shell/completer.rs
  31. +24 −28 src/shell/directory_stack.rs
  32. +23 −22 src/shell/flow.rs
  33. +39 −39 src/shell/flow_control.rs
  34. +14 −15 src/shell/history.rs
  35. +4 −6 src/shell/job.rs
  36. +16 −11 src/shell/mod.rs
  37. +8 −9 src/shell/pipe_exec/job_control.rs
  38. +23 −27 src/shell/pipe_exec/mod.rs
  39. +3 −3 src/shell/plugins/library_iter/unix.rs
  40. +6 −10 src/shell/plugins/methods/unix.rs
  41. +8 −11 src/shell/plugins/namespaces/unix.rs
  42. +2 −1 src/shell/plugins/string.rs
  43. +2 −1 src/shell/signals.rs
  44. +27 −34 src/shell/variables/mod.rs
  45. +7 −6 src/sys/redox.rs
  46. +10 −8 src/sys/unix.rs
@@ -7,7 +7,7 @@ use version_check::is_nightly;
// Specifies the minimum version needed to compile Ion.
// NOTE: 1.19 is required due to the usage of `break` with values for
// `loop` (RFC 1624, rust-lang/rust GitHub issue #37339).
//const MIN_VERSION: &'static str = "1.19.0";
// const MIN_VERSION: &'static str = "1.19.0";
use std::env;
use std::fs::File;
@@ -43,7 +43,7 @@ fn main() {
Red.bold().paint("Error:"),
White.paint("Ion requires nighlty to build.")
);
//print_version_err(&*version_string);
// print_version_err(&*version_string);
printerr!(
"{}{}{}",
Blue.paint("Use `"),
@@ -1,14 +1,19 @@
chain_one_line_max = 100
comment_width = 100
condense_wildcard_suffixes = true
error_on_line_overflow = false
fn_call_width = 80
fn_call_width = 100
fn_single_line = true
format_strings = true
imports_indent = "Block"
match_pattern_separator_break_point = "Front"
max_width = 100
normalize_comments = true
reorder_imported_names = true
reorder_imports = true
reorder_imports_in_group = true
single_line_if_else_max_width = 80
single_line_if_else_max_width = 100
struct_field_align_threshold = 30
trailing_semicolon = false
where_style = "legacy"
wrap_comments = true
write_mode = "overwrite"
@@ -24,10 +24,7 @@ impl AsciiReplaceInPlace for str {
// I tried replacing these `assert!` calls with `debug_assert!` but it looks
// like they get const-folded away anyway since it doesn't affect the speed
fn ascii_replace_in_place(&mut self, needle: char, haystack: char) {
assert!(
needle.is_ascii(),
"AsciiReplace functions can only be used for ascii characters"
);
assert!(needle.is_ascii(), "AsciiReplace functions can only be used for ascii characters");
assert!(
haystack.is_ascii(),
"AsciiReplace functions can only be used for ascii characters"
@@ -24,7 +24,7 @@ pub fn calc(args: &[&str]) -> Result<(), String> {
let mut input = String::new();
let _ = io::stdin().read_line(&mut input);
if input.is_empty() {
break
break;
} else {
match input.trim() {
"" => (),
@@ -39,7 +39,7 @@ OPTIONS
\r carriage return
\t horizontal tab (HT)
\v vertical tab (VT)
"#; /* @MANEND */
"#; // @MANEND
pub fn echo(args: &[&str]) -> Result<(), io::Error> {
let mut flags = Flags::empty();
@@ -63,7 +63,7 @@ pub fn echo(args: &[&str]) -> Result<(), io::Error> {
'h' => short_flags |= HELP,
_ => {
is_opts = false;
break
break;
}
}
}
@@ -84,7 +84,7 @@ pub fn echo(args: &[&str]) -> Result<(), io::Error> {
if flags.contains(HELP) {
buffer.write_all(MAN_PAGE.as_bytes())?;
buffer.flush()?;
return Ok(())
return Ok(());
}
let mut first = true;
@@ -114,7 +114,7 @@ pub fn echo(args: &[&str]) -> Result<(), io::Error> {
}
b'c' if check => {
buffer.flush()?;
return Ok(())
return Ok(());
}
b'e' if check => {
buffer.write_all(&[27u8])?; // escape
@@ -68,7 +68,7 @@ EXAMPLES
AUTHOR
Written by Fabian Würfl.
Heavily based on implementation of the test builtin, which was written by Michael Murph.
"#; /* @MANEND */
"#; // @MANEND
pub fn exists(args: &[&str], shell: &Shell) -> Result<bool, String> {
let stdout = io::stdout();
@@ -86,9 +86,7 @@ fn evaluate_arguments<W: io::Write>(
match arguments.first() {
Some(&"--help") => {
// not handled by the second case, so that we don't have to pass the buffer around
buffer
.write_all(MAN_PAGE.as_bytes())
.map_err(|x| x.description().to_owned())?;
buffer.write_all(MAN_PAGE.as_bytes()).map_err(|x| x.description().to_owned())?;
buffer.flush().map_err(|x| x.description().to_owned())?;
Ok(true)
}
@@ -143,16 +141,12 @@ fn match_option_argument(option: &str, argument: &str, shell: &Shell) -> bool {
/// Returns true if the file is a regular file
fn path_is_file(filepath: &str) -> bool {
fs::metadata(filepath)
.ok()
.map_or(false, |metadata| metadata.file_type().is_file())
fs::metadata(filepath).ok().map_or(false, |metadata| metadata.file_type().is_file())
}
/// Returns true if the file is a directory
fn path_is_directory(filepath: &str) -> bool {
fs::metadata(filepath)
.ok()
.map_or(false, |metadata| metadata.file_type().is_dir())
fs::metadata(filepath).ok().map_or(false, |metadata| metadata.file_type().is_dir())
}
/// Returns true if the binary is found in path (and is executable)
@@ -166,7 +160,7 @@ fn binary_is_in_path(binaryname: &str, shell: &Shell) -> bool {
let fname = format!("{}/{}", dir, binaryname);
if let Ok(metadata) = fs::metadata(&fname) {
if metadata.is_file() && file_has_execute_permission(&fname) {
return true
return true;
}
}
}
@@ -246,9 +240,7 @@ fn test_evaluate_arguments() {
// check `exists -a`
// no argument means we treat it as a string
assert_eq!(evaluate_arguments(&["-a"], &mut sink, &shell), Ok(true));
shell
.variables
.set_array("emptyarray", SmallVec::from_vec(Vec::new()));
shell.variables.set_array("emptyarray", SmallVec::from_vec(Vec::new()));
assert_eq!(evaluate_arguments(&["-a", "emptyarray"], &mut sink, &shell), Ok(false));
let mut vec = Vec::new();
vec.push("element".to_owned());
@@ -261,10 +253,7 @@ fn test_evaluate_arguments() {
// TODO: see test_binary_is_in_path()
// no argument means we treat it as a string
assert_eq!(evaluate_arguments(&["-b"], &mut sink, &shell), Ok(true));
let oldpath = shell
.variables
.get_var("PATH")
.unwrap_or("/usr/bin".to_owned());
let oldpath = shell.variables.get_var("PATH").unwrap_or("/usr/bin".to_owned());
shell.variables.set_var("PATH", "testing/");
assert_eq!(evaluate_arguments(&["-b", "executable_file"], &mut sink, &shell), Ok(true));
@@ -342,10 +331,7 @@ fn test_match_flag_argument() {
let shell = Shell::new(&builtins);
// we don't really care about the passed values, as long as both sited return the same value
assert_eq!(
match_flag_argument('a', "ARRAY", &shell),
array_var_is_not_empty("ARRAY", &shell)
);
assert_eq!(match_flag_argument('a', "ARRAY", &shell), array_var_is_not_empty("ARRAY", &shell));
assert_eq!(match_flag_argument('b', "binary", &shell), binary_is_in_path("binary", &shell));
assert_eq!(match_flag_argument('d', "path", &shell), path_is_directory("path"));
assert_eq!(match_flag_argument('f', "file", &shell), path_is_file("file"));
@@ -361,10 +347,7 @@ fn test_match_option_argument() {
let shell = Shell::new(&builtins);
// we don't really care about the passed values, as long as both sited return the same value
assert_eq!(
match_option_argument("fn", "FUN", &shell),
array_var_is_not_empty("FUN", &shell)
);
assert_eq!(match_option_argument("fn", "FUN", &shell), array_var_is_not_empty("FUN", &shell));
// Any option which is not implemented
assert_eq!(match_option_argument("foo", "ARG", &shell), false);
@@ -419,16 +402,12 @@ fn test_array_var_is_not_empty() {
let builtins = Builtin::map();
let mut shell = Shell::new(&builtins);
shell
.variables
.set_array("EMPTY_ARRAY", SmallVec::from_vec(Vec::new()));
shell.variables.set_array("EMPTY_ARRAY", SmallVec::from_vec(Vec::new()));
assert_eq!(array_var_is_not_empty("EMPTY_ARRAY", &shell), false);
let mut not_empty_vec = Vec::new();
not_empty_vec.push("array not empty".to_owned());
shell
.variables
.set_array("NOT_EMPTY_ARRAY", SmallVec::from_vec(not_empty_vec));
shell.variables.set_array("NOT_EMPTY_ARRAY", SmallVec::from_vec(not_empty_vec));
assert_eq!(array_var_is_not_empty("NOT_EMPTY_ARRAY", &shell), true);
// test for array which does not even exist
@@ -454,9 +433,7 @@ fn test_string_var_is_not_empty() {
// string_var_is_not_empty should NOT match for arrays with the same name
let mut vec = Vec::new();
vec.push("not-empty".to_owned());
shell
.variables
.set_array("ARRAY_NOT_EMPTY", SmallVec::from_vec(vec));
shell.variables.set_array("ARRAY_NOT_EMPTY", SmallVec::from_vec(vec));
assert_eq!(string_var_is_not_empty("ARRAY_NOT_EMPTY", &shell), false);
// test for a variable which does not even exist
@@ -9,12 +9,12 @@ const DOCPATH: &str = "/usr/share/ion/docs/index.html";
pub fn ion_docs(_: &[&str], shell: &mut Shell) -> i32 {
if !Path::new(DOCPATH).exists() {
eprintln!("ion: ion shell documentation is not installed");
return FAILURE
return FAILURE;
}
if let Some(cmd) = shell.variables.get_var("BROWSER".into()) {
if let Ok(_) = Command::new(&cmd).arg(DOCPATH).spawn() {
return SUCCESS
return SUCCESS;
}
} else {
eprintln!("ion: BROWSER variable isn't defined");
@@ -7,7 +7,8 @@ use shell::status::*;
use std::io::{stderr, Write};
/// Disowns given process job IDs, and optionally marks jobs to not receive SIGHUP signals.
/// The `-a` flag selects all jobs, `-r` selects all running jobs, and `-h` specifies to mark SIGHUP ignoral.
/// The `-a` flag selects all jobs, `-r` selects all running jobs, and `-h` specifies to mark
/// SIGHUP ignoral.
pub fn disown(shell: &mut Shell, args: &[&str]) -> i32 {
let stderr = stderr();
let mut stderr = stderr.lock();
@@ -26,7 +27,7 @@ pub fn disown(shell: &mut Shell, args: &[&str]) -> i32 {
Ok(jobspec) => jobspecs.push(jobspec),
Err(_) => {
let _ = writeln!(stderr, "ion: disown: invalid jobspec: '{}'", arg);
return FAILURE
return FAILURE;
}
},
}
@@ -96,7 +97,7 @@ pub fn fg(shell: &mut Shell, args: &[&str]) -> i32 {
} else {
let stderr = stderr();
let _ = writeln!(stderr.lock(), "ion: fg: job {} does not exist", njob);
return FAILURE
return FAILURE;
}
// Bring the process into the foreground and wait for it to finish.
@@ -141,27 +142,21 @@ pub fn fg(shell: &mut Shell, args: &[&str]) -> i32 {
/// Resumes a stopped background process, if it was stopped.
pub fn bg(shell: &mut Shell, args: &[&str]) -> i32 {
fn bg_job(shell: &mut Shell, njob: u32) -> bool {
if let Some(job) = shell
.background
.lock()
.unwrap()
.iter_mut()
.nth(njob as usize)
{
if let Some(job) = shell.background.lock().unwrap().iter_mut().nth(njob as usize) {
match job.state {
ProcessState::Running => {
eprintln!("ion: bg: job {} is already running", njob);
return true
return true;
}
ProcessState::Stopped => signals::resume(job.pid),
ProcessState::Empty => {
eprintln!("ion: bg: job {} does not exist", njob);
return true
return true;
}
}
} else {
eprintln!("ion: bg: job {} does not exist", njob);
return true
return true;
}
false
}
Oops, something went wrong.

0 comments on commit a61f0ec

Please sign in to comment.