mirror of
https://github.com/lights0123/n-link.git
synced 2024-12-22 10:15:27 +00:00
Added mkdir
and rmdir
subcommands
This commit is contained in:
parent
5ce4d8a560
commit
a08eb0b791
|
@ -16,6 +16,8 @@ struct Opt {
|
|||
#[derive(Clap, Debug)]
|
||||
enum SubCommand {
|
||||
Upload(Upload),
|
||||
Mkdir(Mkdir),
|
||||
Rmdir(Rmdir),
|
||||
/// View license information
|
||||
License,
|
||||
// Download(Download),
|
||||
|
@ -31,6 +33,20 @@ struct Upload {
|
|||
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
|
||||
// #[derive(Clap, Debug)]
|
||||
// struct Download {
|
||||
|
@ -101,6 +117,34 @@ pub fn run() -> bool {
|
|||
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 => {
|
||||
println!("{}", include_str!("../../LICENSE"));
|
||||
println!(include_str!("NOTICE.txt"), env!("CARGO_PKG_REPOSITORY"));
|
||||
|
|
Loading…
Reference in a new issue