From a08eb0b7919c07c311f2a1669183bb4694b12ed0 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Tue, 28 Sep 2021 15:53:30 +0200 Subject: [PATCH] Added `mkdir` and `rmdir` subcommands --- desktop/src-tauri/src/cli.rs | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/desktop/src-tauri/src/cli.rs b/desktop/src-tauri/src/cli.rs index abca724..7f97ee8 100644 --- a/desktop/src-tauri/src/cli.rs +++ b/desktop/src-tauri/src/cli.rs @@ -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"));