generated from mschoi/template
Remove unused code and simplify main function
This commit is contained in:
0
src/lib.rs
Normal file
0
src/lib.rs
Normal file
50
src/main.rs
50
src/main.rs
@@ -1,6 +1,4 @@
|
||||
use clap::{ArgAction, Parser};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Represents the command-line arguments for the ls program
|
||||
#[derive(Parser)]
|
||||
@@ -267,52 +265,6 @@ struct Args {
|
||||
one_per_line: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
Io(std::io::Error),
|
||||
StripPrefix(std::path::StripPrefixError),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Error::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::path::StripPrefixError> for Error {
|
||||
fn from(e: std::path::StripPrefixError) -> Self {
|
||||
Error::StripPrefix(e)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_list<T>(path: T) -> Result<Vec<PathBuf>, Error>
|
||||
where
|
||||
T: AsRef<Path> + Copy,
|
||||
{
|
||||
match fs::metadata(&path) {
|
||||
Ok(md) => {
|
||||
if md.is_dir() {
|
||||
let entries = fs::read_dir(path)?;
|
||||
let mut list = Vec::new();
|
||||
for entry in entries {
|
||||
let entry_path = entry?.path();
|
||||
let relative = entry_path.strip_prefix(&path)?;
|
||||
list.push(relative.to_owned());
|
||||
}
|
||||
Ok(list)
|
||||
} else {
|
||||
Ok(vec![path.as_ref().to_owned()])
|
||||
}
|
||||
}
|
||||
Err(e) => Err(Error::Io(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Args::parse();
|
||||
// let list = get_list(&cli.input).unwrap();
|
||||
// for path in list {
|
||||
// println!("{}", path.display());
|
||||
// }
|
||||
println!("{}", cli.almost_all);
|
||||
let _cli = Args::parse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user