Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mitnk committed Sep 27, 2024
1 parent 2e78b7d commit 584a5ac
Show file tree
Hide file tree
Showing 40 changed files with 441 additions and 559 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
large-error-threshold = 256
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition = "2021"
build = "src/build.rs"
name = "cicada"
version = "0.9.40"
version = "0.9.41"
authors = ["Hugo Wang <[email protected]>"]

description = "A simple Bash-like Unix shell."
Expand Down
4 changes: 2 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ There are a few ways to install cicada into your system.

### Alpine Linux

[https://pkgs.alpinelinux.org/package/edge/testing/x86_64/cicada](https://pkgs.alpinelinux.org/package/edge/testing/x86_64/cicada)
[https://pkgs.alpinelinux.org/package/edge/community/x86_64/cicada](https://pkgs.alpinelinux.org/package/edge/community/x86_64/cicada)

```
$ apk add cicada -X https://dl-cdn.alpinelinux.org/alpine/edge/testing/
$ sudo apk add cicada -X https://dl-cdn.alpinelinux.org/alpine/edge/community/
```

### Arch Linux
Expand Down
33 changes: 15 additions & 18 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use time::OffsetDateTime;

fn main() {
match Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(["rev-parse", "--short", "HEAD"])
.output()
{
Ok(x) => {
Expand All @@ -17,7 +17,7 @@ fn main() {
}

match Command::new("git")
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
.args(["rev-parse", "--abbrev-ref", "HEAD"])
.output()
{
Ok(x) => {
Expand All @@ -30,7 +30,7 @@ fn main() {
}

match Command::new("git")
.args(&["status", "--porcelain"])
.args(["status", "--porcelain"])
.output()
{
Ok(x) => {
Expand All @@ -42,7 +42,7 @@ fn main() {
}
}

match Command::new("rustc").args(&["-V"]).output() {
match Command::new("rustc").args(["-V"]).output() {
Ok(x) => {
let output = String::from_utf8_lossy(&x.stdout);
println!("cargo:rustc-env=BUILD_RUSTC_VERSION={}", output);
Expand All @@ -52,19 +52,16 @@ fn main() {
}
}

match OffsetDateTime::now_local() {
Ok(dt) => {
let dt_str = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}",
dt.year(),
dt.month() as u8,
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.millisecond(),
);
println!("cargo:rustc-env=BUILD_DATE={}", dt_str);
}
Err(_) => { }
if let Ok(dt) = OffsetDateTime::now_local() {
let dt_str = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}",
dt.year(),
dt.month() as u8,
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.millisecond(),
);
println!("cargo:rustc-env=BUILD_DATE={}", dt_str);
}
}
7 changes: 3 additions & 4 deletions src/builtins/bg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,

let mut job_id = -1;
if tokens.len() == 1 {
for (gid, _) in sh.jobs.iter() {
if let Some((gid, _)) = sh.jobs.iter().next() {
job_id = *gid;
break;
}
}

Expand Down Expand Up @@ -71,12 +70,12 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
}
None => {
let info = "cicada: bg: not such job";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}
}
}

jobc::mark_job_as_running(sh, gid, true);
return cr;
cr
}
2 changes: 1 addition & 1 deletion src/builtins/cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn run(sh: &mut shell::Shell, cl: &CommandLine, cmd: &Command,
};

if dir_to == "-" {
if sh.previous_dir == "" {
if sh.previous_dir.is_empty() {
let info = "no previous dir";
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
Expand Down
7 changes: 3 additions & 4 deletions src/builtins/fg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,

let mut job_id = -1;
if tokens.len() == 1 {
for (gid, _) in sh.jobs.iter() {
if let Some((gid, _)) = sh.jobs.iter().next() {
job_id = *gid;
break;
}
}

Expand Down Expand Up @@ -52,7 +51,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
{
let mut result = sh.get_job_by_id(job_id);
// fall back to find job by using prcess group id
if let None = result {
if result.is_none() {
result = sh.get_job_by_gid(job_id);
}

Expand Down Expand Up @@ -89,6 +88,6 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
log!("failed to give term to back to shell : {}", gid_shell);
}

return cr;
cr
}
}
24 changes: 11 additions & 13 deletions src/builtins/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
let path = Path::new(hfile.as_str());
if !path.exists() {
let info = "no history file";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}
let conn = match Conn::open(&hfile) {
Expand Down Expand Up @@ -98,12 +98,12 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
let info = format!("deleted {} items", _count);
print_stdout_with_capture(&info, &mut cr, cl, cmd, capture);
}
return cr;
cr
}
Some(SubCommand::Add {timestamp: ts, input}) => {
let ts = ts.unwrap_or(0 as f64);
add_history(sh, ts, &input);
return cr;
cr
}
None => {
let (str_out, str_err) = list_current_history(sh, &conn, &opt);
Expand All @@ -113,7 +113,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
if !str_err.is_empty() {
print_stderr_with_capture(&str_err, &mut cr, cl, cmd, capture);
}
return cr;
cr
}
}
}
Expand All @@ -126,7 +126,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
cr.status = 1;
}
return cr;
cr
}
}
}
Expand All @@ -144,7 +144,7 @@ fn list_current_history(sh: &Shell, conn: &Conn,
let history_table = history::get_history_table();
let mut sql = format!("SELECT ROWID, inp, tsb FROM {} WHERE ROWID > 0",
history_table);
if opt.pattern.len() > 0 {
if !opt.pattern.is_empty() {
sql = format!("{} AND inp LIKE '%{}%'", sql, opt.pattern)
}
if opt.session {
Expand Down Expand Up @@ -202,9 +202,9 @@ fn list_current_history(sh: &Shell, conn: &Conn,
};

if opt.no_id {
lines.push(format!("{}", inp));
lines.push(inp.to_string());
} else if opt.only_id {
lines.push(format!("{}", row_id));
lines.push(row_id.to_string());
} else if opt.show_date {
let tsb: f64 = match row.get(2) {
Ok(x) => x,
Expand Down Expand Up @@ -240,12 +240,10 @@ fn delete_history_item(conn: &Conn, rowid: usize) -> bool {
let history_table = history::get_history_table();
let sql = format!("DELETE from {} where rowid = {}", history_table, rowid);
match conn.execute(&sql, []) {
Ok(_) => {
return true;
}
Ok(_) => true,
Err(e) => {
log!("history: prepare error - {:?}", e);
return false;
log!("history: error when delete: {:?}", e);
false
}
}
}
8 changes: 4 additions & 4 deletions src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
Ok(opt) => {
if opt.exit_on_error {
sh.exit_on_error = true;
return cr;
cr
} else {
let info = "cicada: set: option not implemented";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
return cr;
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
cr
}
}
Err(e) => {
Expand All @@ -41,7 +41,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
cr.status = 1;
}
return cr;
cr
}
}
}
4 changes: 2 additions & 2 deletions src/builtins/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,
capture: bool) -> CommandResult {
let mut cr = CommandResult::new();
let tokens = &cmd.tokens;
let args = parsers::parser_line::tokens_to_args(&tokens);
let args = parsers::parser_line::tokens_to_args(tokens);

if args.len() < 2 {
let info = "cicada: source: no file specified";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}

Expand Down
34 changes: 12 additions & 22 deletions src/builtins/ulimit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@ pub fn run(_sh: &mut Shell, cl: &CommandLine, cmd: &Command,
println_stderr!("cicada: clap: {}", e);
}
}
print!("\n");
println!();
return CommandResult::new();
}

let matches;
match app.try_get_matches_from(&args) {
Ok(x) => {
matches = x;
}
let matches = match app.try_get_matches_from(&args) {
Ok(x) => x,
Err(e) => {
let info = format!("ulimit error: {}", e);
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
return cr;
}
}
};

let open_files;
match matches.value_of_t("open_files") {
Expand Down Expand Up @@ -99,7 +96,7 @@ pub fn run(_sh: &mut Shell, cl: &CommandLine, cmd: &Command,
}

let for_hard = matches.is_present("for_hard");
if matches.is_present("report_all") || options.len() == 0 {
if matches.is_present("report_all") || options.is_empty() {
let (_out, _err) = report_all(for_hard);
if !_out.is_empty() {
print_stdout_with_capture(&_out, &mut cr, cl, cmd, capture);
Expand Down Expand Up @@ -198,7 +195,7 @@ fn get_limit(limit_name: &str, single_print: bool,
limit_id = libc::RLIMIT_CORE;
} else {
let info = "ulimit: error: invalid limit name";
result_stderr.push_str(&info);
result_stderr.push_str(info);
return (result_stdout, result_stderr);
}

Expand All @@ -212,12 +209,7 @@ fn get_limit(limit_name: &str, single_print: bool,
return (result_stdout, result_stderr);
}

let to_print;
if for_hard {
to_print = rlp.rlim_max;
} else {
to_print = rlp.rlim_cur;
}
let to_print = if for_hard { rlp.rlim_max } else { rlp.rlim_cur };

if single_print {
if to_print == libc::RLIM_INFINITY {
Expand All @@ -226,14 +218,12 @@ fn get_limit(limit_name: &str, single_print: bool,
let info = format!("{}\n", to_print);
result_stdout.push_str(&info);
}
} else if to_print == libc::RLIM_INFINITY {
let info = format!("{}\t\tunlimited\n", desc);
result_stdout.push_str(&info);
} else {
if to_print == libc::RLIM_INFINITY {
let info = format!("{}\t\tunlimited\n", desc);
result_stdout.push_str(&info);
} else {
let info = format!("{}\t\t{}\n", desc, to_print);
result_stdout.push_str(&info);
}
let info = format!("{}\t\t{}\n", desc, to_print);
result_stdout.push_str(&info);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/builtins/unalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,

if tokens.len() != 2 {
let info = "cicada: unalias: syntax error";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/builtins/unpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,

if tokens.len() != 2 {
let info = "cicada: unpath: syntax error";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/builtins/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command,

if tokens.len() != 2 {
let info = "cicada: unset: syntax error";
print_stderr_with_capture(&info, &mut cr, cl, cmd, capture);
print_stderr_with_capture(info, &mut cr, cl, cmd, capture);
return cr;
}

Expand Down
Loading

0 comments on commit 584a5ac

Please sign in to comment.