Skip to content

Commit 73367ec

Browse files
author
Árni Dagur
committed
Run cargo fmt and enforce style using Travis CI
1 parent bc783ed commit 73367ec

122 files changed

Lines changed: 1451 additions & 1077 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ install:
5252
pip3 install $SPHINX_VERSIONED
5353
fi
5454
55+
before_script:
56+
- rustup component add rustfmt
57+
5558
script:
59+
# Check style
60+
- cargo fmt --all -- --check
61+
# Build
5662
- cargo build $CARGO_ARGS --features "$FEATURES"
63+
# Run tests
5764
- if [ ! $REDOX ]; then cargo test $CARGO_ARGS --features "$FEATURES" --no-fail-fast; fi
5865
- if [ -n "$TEST_INSTALL" ]; then mkdir installdir_test; DESTDIR=installdir_test make install; [ `ls installdir_test/usr/local/bin | wc -l` -gt 0 ]; fi
5966

build.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn main() {
1616
if val == "1" && key.starts_with(feature_prefix) {
1717
let krate = key[feature_prefix.len()..].to_lowercase();
1818
match krate.as_ref() {
19-
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic" | "windows"
20-
| "nightly" | "test_unimplemented" => continue,
19+
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic"
20+
| "windows" | "nightly" | "test_unimplemented" => continue,
2121
_ => {}
2222
}
2323
crates.push(krate.to_string());
@@ -35,7 +35,8 @@ pub fn main() {
3535
fn util_map() -> UtilityMap {
3636
let mut map: UtilityMap = HashMap::new();\n"
3737
.as_bytes(),
38-
).unwrap();
38+
)
39+
.unwrap();
3940

4041
for krate in crates {
4142
cf.write_all(format!("extern crate uu_{krate};\n", krate = krate).as_bytes())
@@ -59,14 +60,18 @@ pub fn main() {
5960
map.insert(\"shake128sum\", uu_hashsum::uumain);
6061
map.insert(\"shake256sum\", uu_hashsum::uumain);\n"
6162
.as_bytes(),
62-
).unwrap();
63+
)
64+
.unwrap();
6365
}
64-
_ => mf.write_all(
65-
format!(
66-
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
67-
krate = krate
68-
).as_bytes(),
69-
).unwrap(),
66+
_ => mf
67+
.write_all(
68+
format!(
69+
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
70+
krate = krate
71+
)
72+
.as_bytes(),
73+
)
74+
.unwrap(),
7075
}
7176
}
7277

mkmain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
2-
use std::io::Write;
32
use std::fs::File;
3+
use std::io::Write;
44
use std::path::Path;
55

66
static TEMPLATE: &'static str = "\

src/base32/base32.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use uucore::encoding::Format;
1616
mod base_common;
1717

1818
static SYNTAX: &str = "[OPTION]... [FILE]";
19-
static SUMMARY: &str =
20-
"Base32 encode or decode FILE, or standard input, to standard output.";
19+
static SUMMARY: &str = "Base32 encode or decode FILE, or standard input, to standard output.";
2120
static LONG_HELP: &str = "
2221
With no FILE, or when FILE is -, read standard input.
2322

src/base64/base64.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use uucore::encoding::Format;
1616
mod base_common;
1717

1818
static SYNTAX: &str = "[OPTION]... [FILE]";
19-
static SUMMARY: &str =
20-
"Base64 encode or decode FILE, or standard input, to standard output.";
19+
static SUMMARY: &str = "Base64 encode or decode FILE, or standard input, to standard output.";
2120
static LONG_HELP: &str = "
2221
With no FILE, or when FILE is -, read standard input.
2322

src/base64/base_common.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ pub fn execute(
3636
"COLS",
3737
)
3838
.parse(args);
39-
40-
let line_wrap = matches.opt_str("wrap").map(|s| {
41-
match s.parse() {
42-
Ok(n) => n,
43-
Err(e) => {
44-
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
45-
}
39+
40+
let line_wrap = matches.opt_str("wrap").map(|s| match s.parse() {
41+
Ok(n) => n,
42+
Err(e) => {
43+
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
4644
}
4745
});
4846
let ignore_garbage = matches.opt_present("ignore-garbage");
@@ -55,7 +53,13 @@ pub fn execute(
5553

5654
if matches.free.is_empty() || &matches.free[0][..] == "-" {
5755
let stdin_raw = stdin();
58-
handle_input(&mut stdin_raw.lock(), format, line_wrap, ignore_garbage, decode);
56+
handle_input(
57+
&mut stdin_raw.lock(),
58+
format,
59+
line_wrap,
60+
ignore_garbage,
61+
decode,
62+
);
5963
} else {
6064
let path = Path::new(matches.free[0].as_str());
6165
let file_buf = safe_unwrap!(File::open(&path));
@@ -73,8 +77,7 @@ fn handle_input<R: Read>(
7377
ignore_garbage: bool,
7478
decode: bool,
7579
) {
76-
let mut data = Data::new(input, format)
77-
.ignore_garbage(ignore_garbage);
80+
let mut data = Data::new(input, format).ignore_garbage(ignore_garbage);
7881
if let Some(wrap) = line_wrap {
7982
data = data.line_wrap(wrap);
8083
}
@@ -88,4 +91,4 @@ fn handle_input<R: Read>(
8891
Err(_) => crash!(1, "invalid input"),
8992
}
9093
}
91-
}
94+
}

src/cat/cat.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
168168
files.push("-".to_owned());
169169
}
170170

171-
let can_write_fast = !(show_tabs || show_nonprint || show_ends || squeeze_blank
171+
let can_write_fast = !(show_tabs
172+
|| show_nonprint
173+
|| show_ends
174+
|| squeeze_blank
172175
|| number_mode != NumberingMode::NumberNone);
173176

174177
let success = if can_write_fast {
@@ -190,7 +193,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
190193
write_lines(files, &options).is_ok()
191194
};
192195

193-
if success { 0 } else { 1 }
196+
if success {
197+
0
198+
} else {
199+
1
200+
}
194201
}
195202

196203
/// Classifies the `InputType` of file at `path` if possible
@@ -205,25 +212,13 @@ fn get_input_type(path: &str) -> CatResult<InputType> {
205212

206213
match metadata(path).context(path)?.file_type() {
207214
#[cfg(unix)]
208-
ft if ft.is_block_device() =>
209-
{
210-
Ok(InputType::BlockDevice)
211-
}
215+
ft if ft.is_block_device() => Ok(InputType::BlockDevice),
212216
#[cfg(unix)]
213-
ft if ft.is_char_device() =>
214-
{
215-
Ok(InputType::CharacterDevice)
216-
}
217+
ft if ft.is_char_device() => Ok(InputType::CharacterDevice),
217218
#[cfg(unix)]
218-
ft if ft.is_fifo() =>
219-
{
220-
Ok(InputType::Fifo)
221-
}
219+
ft if ft.is_fifo() => Ok(InputType::Fifo),
222220
#[cfg(unix)]
223-
ft if ft.is_socket() =>
224-
{
225-
Ok(InputType::Socket)
226-
}
221+
ft if ft.is_socket() => Ok(InputType::Socket),
227222
ft if ft.is_dir() => Ok(InputType::Directory),
228223
ft if ft.is_file() => Ok(InputType::File),
229224
ft if ft.is_symlink() => Ok(InputType::SymLink),
@@ -282,12 +277,14 @@ fn write_fast(files: Vec<String>) -> CatResult<()> {
282277

283278
for file in files {
284279
match open(&file[..]) {
285-
Ok(mut handle) => while let Ok(n) = handle.reader.read(&mut in_buf) {
286-
if n == 0 {
287-
break;
280+
Ok(mut handle) => {
281+
while let Ok(n) = handle.reader.read(&mut in_buf) {
282+
if n == 0 {
283+
break;
284+
}
285+
writer.write_all(&in_buf[..n]).context(&file[..])?;
288286
}
289-
writer.write_all(&in_buf[..n]).context(&file[..])?;
290-
},
287+
}
291288
Err(error) => {
292289
writeln!(&mut stderr(), "{}", error)?;
293290
error_count += 1;
@@ -404,7 +401,8 @@ fn write_file_lines(file: &str, options: &OutputOptions, state: &mut OutputState
404401

405402
// write***_to_end methods
406403
// Write all symbols till end of line or end of buffer is reached
407-
// Return the (number of written symbols + 1) or 0 if the end of buffer is reached
404+
// Return the (number of written symbols + 1) or 0 if the end of buffer is
405+
// reached
408406
fn write_to_end<W: Write>(in_buf: &[u8], writer: &mut W) -> usize {
409407
match in_buf.iter().position(|c| *c == b'\n') {
410408
Some(p) => {
@@ -421,10 +419,7 @@ fn write_to_end<W: Write>(in_buf: &[u8], writer: &mut W) -> usize {
421419
fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
422420
let mut count = 0;
423421
loop {
424-
match in_buf
425-
.iter()
426-
.position(|c| *c == b'\n' || *c == b'\t')
427-
{
422+
match in_buf.iter().position(|c| *c == b'\n' || *c == b'\t') {
428423
Some(p) => {
429424
writer.write_all(&in_buf[..p]).unwrap();
430425
if in_buf[p] == b'\n' {
@@ -458,7 +453,8 @@ fn write_nonprint_to_end<W: Write>(in_buf: &[u8], writer: &mut W, tab: &[u8]) ->
458453
128...159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
459454
160...254 => writer.write_all(&[b'M', b'-', byte - 128]),
460455
_ => writer.write_all(&[b'M', b'-', b'^', 63]),
461-
}.unwrap();
456+
}
457+
.unwrap();
462458
count += 1;
463459
}
464460
if count != in_buf.len() {

src/chgrp/chgrp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
#[macro_use]
1212
extern crate uucore;
13-
use uucore::libc::{self, gid_t, lchown};
1413
pub use uucore::entries;
1514
use uucore::fs::resolve_relative_path;
15+
use uucore::libc::{self, gid_t, lchown};
1616

1717
extern crate walkdir;
1818
use walkdir::WalkDir;
1919

20-
use std::io::Result as IOResult;
2120
use std::io::Error as IOError;
21+
use std::io::Result as IOResult;
2222

2323
use std::fs;
2424
use std::fs::Metadata;
@@ -183,12 +183,12 @@ struct Chgrper {
183183
}
184184

185185
macro_rules! unwrap {
186-
($m:expr, $e:ident, $err:block) => (
186+
($m:expr, $e:ident, $err:block) => {
187187
match $m {
188188
Ok(meta) => meta,
189189
Err($e) => $err,
190190
}
191-
)
191+
};
192192
}
193193

194194
impl Chgrper {

src/chmod/chmod.rs

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ extern crate uucore;
1919
use std::fs;
2020
use std::os::unix::fs::{MetadataExt, PermissionsExt};
2121
use std::path::Path;
22-
use walker::Walker;
22+
use uucore::fs::display_permissions_unix;
2323
#[cfg(not(windows))]
2424
use uucore::mode;
25-
use uucore::fs::display_permissions_unix;
25+
use walker::Walker;
2626

2727
const NAME: &str = "chmod";
2828
static SUMMARY: &str = "Change the mode of each FILE to MODE.
@@ -39,14 +39,31 @@ pub fn uumain(mut args: Vec<String>) -> i32 {
3939
NAME
4040
);
4141
let mut opts = new_coreopts!(&syntax, SUMMARY, LONG_HELP);
42-
opts.optflag("c", "changes", "like verbose but report only when a change is made")
43-
// TODO: support --silent (can be done using clap)
44-
.optflag("f", "quiet", "suppress most error messages")
45-
.optflag("v", "verbose", "output a diagnostic for every file processed")
46-
.optflag("", "no-preserve-root", "do not treat '/' specially (the default)")
47-
.optflag("", "preserve-root", "fail to operate recursively on '/'")
48-
.optopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE")
49-
.optflag("R", "recursive", "change files and directories recursively");
42+
opts.optflag(
43+
"c",
44+
"changes",
45+
"like verbose but report only when a change is made",
46+
)
47+
// TODO: support --silent (can be done using clap)
48+
.optflag("f", "quiet", "suppress most error messages")
49+
.optflag(
50+
"v",
51+
"verbose",
52+
"output a diagnostic for every file processed",
53+
)
54+
.optflag(
55+
"",
56+
"no-preserve-root",
57+
"do not treat '/' specially (the default)",
58+
)
59+
.optflag("", "preserve-root", "fail to operate recursively on '/'")
60+
.optopt(
61+
"",
62+
"reference",
63+
"use RFILE's mode instead of MODE values",
64+
"RFILE",
65+
)
66+
.optflag("R", "recursive", "change files and directories recursively");
5067

5168
// sanitize input for - at beginning (e.g. chmod -x testfile). Remove
5269
// the option and save it for later, after parsing is finished.
@@ -148,17 +165,19 @@ impl Chmoder {
148165
// on Windows OsStrings cannot be built out of non-UTF-8 chars. One
149166
// possible fix is to use CStrings rather than Strings in the args
150167
// to chmod() and chmod_file().
151-
r = self.chmod(
152-
walk_dir
153-
.filter_map(|x| match x {
154-
Ok(o) => match o.path().into_os_string().to_str() {
155-
Some(s) => Some(s.to_owned()),
156-
None => None,
157-
},
158-
Err(_) => None,
159-
})
160-
.collect(),
161-
).and(r);
168+
r = self
169+
.chmod(
170+
walk_dir
171+
.filter_map(|x| match x {
172+
Ok(o) => match o.path().into_os_string().to_str() {
173+
Some(s) => Some(s.to_owned()),
174+
None => None,
175+
},
176+
Err(_) => None,
177+
})
178+
.collect(),
179+
)
180+
.and(r);
162181
r = self.chmod_file(&file, filename).and(r);
163182
}
164183
} else {
@@ -230,7 +249,12 @@ impl Chmoder {
230249
fn change_file(&self, fperm: u32, mode: u32, file: &Path, path: &str) -> Result<(), i32> {
231250
if fperm == mode {
232251
if self.verbose && !self.changes {
233-
show_info!("mode of '{}' retained as {:o} ({})", file.display(), fperm, display_permissions_unix(fperm));
252+
show_info!(
253+
"mode of '{}' retained as {:o} ({})",
254+
file.display(),
255+
fperm,
256+
display_permissions_unix(fperm)
257+
);
234258
}
235259
Ok(())
236260
} else if let Err(err) =

0 commit comments

Comments
 (0)