Added mkdir and rmdir subcommands

This commit is contained in:
JandereDev 2021-09-28 15:53:30 +02:00 committed by Ben Schattinger
parent 5ce4d8a560
commit a08eb0b791

View file

@ -16,6 +16,8 @@ struct Opt {
#[derive(Clap, Debug)] #[derive(Clap, Debug)]
enum SubCommand { enum SubCommand {
Upload(Upload), Upload(Upload),
Mkdir(Mkdir),
Rmdir(Rmdir),
/// View license information /// View license information
License, License,
// Download(Download), // Download(Download),
@ -31,6 +33,20 @@ struct Upload {
dest: String, dest: String,
} }
// Create a directory
#[derive(Clap, Debug)]
struct Mkdir {
#[clap(required = true)]
path: String
}
// Delete a directory
#[derive(Clap, Debug)]
struct Rmdir {
#[clap(required = true)]
path: String
}
// /// Download files from the calculator // /// Download files from the calculator
// #[derive(Clap, Debug)] // #[derive(Clap, Debug)]
// struct Download { // struct Download {
@ -101,6 +117,34 @@ pub fn run() -> bool {
eprintln!("Couldn't find any device"); eprintln!("Couldn't find any device");
} }
} }
SubCommand::Mkdir(Mkdir { path }) => {
if let Some(handle) = get_dev() {
match handle.create_dir(&path) {
Ok(_) => {
println!("Create {}: Ok", path);
}
Err(error) => {
println!("Failed to create directory: {}", error);
}
}
} else {
eprintln!("Couldn't find any device");
}
}
SubCommand::Rmdir(Rmdir { path }) => {
if let Some(handle) = get_dev() {
match handle.delete_dir(&path) {
Ok(_) => {
println!("Remove {}: Ok", path);
}
Err(error) => {
println!("Failed to delete directory: {}", error);
}
}
} else {
eprintln!("Couldn't find any device");
}
}
SubCommand::License => { SubCommand::License => {
println!("{}", include_str!("../../LICENSE")); println!("{}", include_str!("../../LICENSE"));
println!(include_str!("NOTICE.txt"), env!("CARGO_PKG_REPOSITORY")); println!(include_str!("NOTICE.txt"), env!("CARGO_PKG_REPOSITORY"));