Skip to content

Commit 6e0944e

Browse files
committed
src:gnostr-traverse:apply cargo +nightly fmt
1 parent 36f1abc commit 6e0944e

File tree

8 files changed

+41
-100
lines changed

8 files changed

+41
-100
lines changed

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fn main() -> Result<(), Box<dyn Error>> {
6767
)
6868
} else if start == end {
6969
println!("No reduction in size!")
70-
} else {
7170
}
7271
}
7372

src/options.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//! Options parsing and configuration for command line interfaces.
2+
use crate::tasks::*;
23
use clap::{App, AppSettings, Arg};
34
use std::ffi::OsString;
45
use std::path::PathBuf;
56

6-
use crate::tasks::*;
7-
use crate::Path;
8-
97
/// Options struct to store configuration state.
108
pub struct Options {
119
pub(crate) tasks: Vec<Box<dyn Task>>,

src/tasks.rs

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ pub trait Task {
3434
fn is_program_in_path(program: &str) -> bool {
3535
if let Ok(path) = env::var("PATH") {
3636
for p in path.split(":") {
37+
println!("p={}", p);
3738
let p_str = format!("{}/{}", p, program);
3839
if fs::metadata(&p_str).is_ok() {
39-
println!("Trying: {}", p_str);
40+
println!("p_str={}", p_str);
4041
return true;
4142
}
4243
}
@@ -80,8 +81,12 @@ pub fn cmd(dir: &str, cmd: &str, args: &[&str]) -> io::Result<()> {
8081
fn is_directory(filepath: &str) -> io::Result<bool> {
8182
use std::path::Path;
8283
let path = Path::new(filepath);
84+
println!("path_to_string(path)={:?}", path_to_string(path).unwrap());
8385
match fs::metadata(path) {
84-
Ok(metadata) => Ok(metadata.is_dir()),
86+
Ok(metadata) => {
87+
println!("path_to_string(path)={:?}", path_to_string(path));
88+
Ok(metadata.is_dir())
89+
}
8590
Err(e) => Err(e),
8691
}
8792
}
@@ -91,70 +96,28 @@ fn path_to_string(path: &Path) -> Result<String, std::ffi::OsString> {
9196
path.as_os_str().to_os_string().into_string()
9297
}
9398

94-
/// Purges a location on disk, similar to `rm -rf`.
9599
pub fn filepath(parent: &str, child: &str) -> io::Result<()> {
96-
let dir_path = String::from(format!("{}/{}", parent, child));
97-
println!("{}", dir_path);
98-
99-
if let dir = is_directory(&dir_path.clone()) {
100-
println!("'{}' is a directory.", dir_path);
101-
println!("{:?}", dir);
102-
} else if let dir = !is_directory(&dir_path.clone()).expect("") {
103-
println!(
104-
"'{}' is not a directory (or the path doesn't exist).",
105-
dir_path
106-
);
107-
108-
println!("{}", dir);
109-
} else {
110-
}
111-
112-
// check for errors that we're ok with
113-
//if let Err(err) = fs::remove_dir_all(dir_path) {
114-
// // if already gone, happy days are upon us
115-
// if err.kind() == ErrorKind::NotFound {
116-
// return Ok(());
117-
// }
118-
// // if there's a permission error, we don't care
119-
// if err.kind() == ErrorKind::PermissionDenied {
120-
// return Ok(());
121-
// }
122-
// if err.kind() == ErrorKind::Other {
123-
// let file_path = format!("{}/{}", parent, child);
124-
// println!("{}", file_path);
125-
// // check for errors that we're ok with
126-
// if let Err(err) = fs::remove_file(file_path) {
127-
// // if already gone, happy days are upon us
128-
// if err.kind() == ErrorKind::NotFound {
129-
// return Ok(());
130-
// }
131-
132-
// // if there's a permission error, we don't care
133-
// if err.kind() == ErrorKind::PermissionDenied {
134-
// return Ok(());
135-
// }
136-
// if err.kind() == ErrorKind::Other {
137-
// return Ok(());
138-
// }
139-
140-
// // others, bad!
141-
// // return Err(err);
142-
// println!("{:?}", Some(err));
143-
// }
144-
145-
// return Ok(());
146-
// }
147-
148-
// // others, bad!
149-
// // return Err(err);
150-
// println!("{:?}", Some(err));
151-
//}
100+
let dir_path = format!("{}/{}", parent, child);
101+
println!("dir_path={}", dir_path);
152102

103+
if let Ok(dir) = is_directory(&dir_path.clone()) {
104+
println!("dir={}", dir);
105+
match dir {
106+
true => {
107+
println!("'{}' is a directory.", dir);
108+
}
109+
false => {
110+
println!("{:?} is NOT a directory!", dir);
111+
}
112+
}
113+
};
114+
//let dir = !is_directory(&dir_path.clone()).expect("");
153115
Ok(())
154116
}
155117

156118
/// Purges a location on disk, similar to `rm -rf`.
157119
pub fn del(parent: &str, child: &str) -> io::Result<()> {
120+
let _ = filepath(parent, child);
158121
let dir_path = format!("{}/{}", parent, child);
159122
println!("{}", dir_path);
160123

src/tasks/cargo.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ impl Task for CargoTask {
1212
}
1313

1414
fn job(&self, dir: &str) -> io::Result<()> {
15-
super::cmd(dir, "cargo", &["clean"])?;
16-
super::del(dir, "target")?;
17-
super::del(dir, "vendor") //?;
18-
//super::del(dir, ".cargo/registry")
15+
super::cmd(dir, "cargo", &["build"])?;
16+
super::cmd(dir, "cargo", &["+nightly", "fmt"])?;
17+
super::cmd(dir, "cargo", &["+nightly", "build"])?;
18+
//super::cmd(dir, "cargo", &["clean"])?;
19+
20+
//super::del(dir, "target")?;
21+
//super::del(dir, "vendor") //?;
22+
//super::del(dir, ".cargo/registry")
23+
24+
super::cmd(dir, "git", &["diff", "HEAD"])
1925
}
2026
}

src/tasks/git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl Task for GitTask {
1717

1818
/// Cleans the provided directory based on a Git structure.
1919
fn job(&self, dir: &str) -> io::Result<()> {
20-
let _ = super::cmd(dir, "git", &["status"])?;
21-
let _ = super::cmd(dir, "git", &["reflog", "expire", "--all", "--expire=now"])?;
20+
super::cmd(dir, "git", &["status"])?;
21+
super::cmd(dir, "git", &["reflog", "expire", "--all", "--expire=now"])?;
2222
super::cmd(dir, "git", &["gc", "--prune=now", "--aggressive"])
2323
}
2424
}

src/tasks/gradle.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/tasks/macos.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ impl Task for MacosTask {
2828

2929
/// Cleans the provided directory based on a certain criteria.
3030
fn job(&self, dir: &str) -> io::Result<()> {
31-
let _ = super::cmd(dir, "brew", &["cleanup"])?;
32-
let _ = super::cmd(dir, "brew", &["autoremove"])?;
33-
let _ = super::cmd(dir, "rm", &[".DS_Store"])?;
34-
let _ = super::cmd(dir, "rm", &["-rf", ".Trash"])?;
35-
31+
super::cmd(dir, "brew", &["cleanup"])?;
32+
super::cmd(dir, "brew", &["autoremove"])?;
33+
super::cmd(dir, "rm", &[".DS_Store"])?;
34+
super::cmd(dir, "rm", &["-rf", ".Trash"])?;
3635
super::del(dir, ".DS_Store")
3736
}
3837
}

src/tasks/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ impl Task for NodeTask {
2020
//super::del(dir, "node_modules")?;
2121
//super::del(dir, ".npm")
2222

23-
let _ = super::cmd(dir, "git", &["status"])?;
24-
let _ = super::cmd(dir, "git", &["reflog", "expire", "--all", "--expire=now"])?;
23+
super::cmd(dir, "git", &["status"])?;
24+
super::cmd(dir, "git", &["reflog", "expire", "--all", "--expire=now"])?;
2525
super::cmd(dir, "git", &["gc", "--prune=now", "--aggressive"])
2626
}
2727
}

0 commit comments

Comments
 (0)