From 4896ad6b2ab5d358abdb33d34b438388774f3fc1 Mon Sep 17 00:00:00 2001 From: Himadu2000 <49078336+Himadu2000@users.noreply.github.com> Date: Sat, 8 May 2021 07:52:37 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88Initial=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 20 ++++++++++++++++++++ .gitignore | 1 + Cargo.lock | 5 +++++ Cargo.toml | 9 +++++++++ README.md | 9 ++++++++- src/confirm.rs | 11 +++++++++++ src/delete.rs | 17 +++++++++++++++++ src/main.rs | 17 +++++++++++++++++ src/path.rs | 14 ++++++++++++++ 9 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/confirm.rs create mode 100644 src/delete.rs create mode 100644 src/main.rs create mode 100644 src/path.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6731f77 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +on: + release: + types: [created] + +jobs: + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: [x86_64-pc-windows-gnu, x86_64-unknown-linux-musl] + steps: + - uses: actions/checkout@master + - name: Compile and release + uses: rust-build/rust-build.action@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUSTTARGET: ${{ matrix.target }} + EXTRA_FILES: "README.md LICENSE" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..0a5955c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "deleter" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..845ee36 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "deleter" +version = "0.1.0" +authors = ["Himadu2000 <49078336+Himadu2000@users.noreply.github.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/README.md b/README.md index 56488fa..1fb30ea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # Deleter - A delete program. Use with caution! + +A folder delete program. Use with caution! + +# How to use + +open deleter.exe, +enter folder path to delete, Ex: C:/hello +enter yes and voilĂ . diff --git a/src/confirm.rs b/src/confirm.rs new file mode 100644 index 0000000..915ad41 --- /dev/null +++ b/src/confirm.rs @@ -0,0 +1,11 @@ +use std::io; + +pub fn request_confirmation(location: &str) -> String { + println!("Are you sure delete, {} | Write (yes)", location); + let mut anwser = String::new(); + io::stdin() + .read_line(&mut anwser) + .expect("Failed to read line"); + let anwser = anwser.trim(); + return anwser.to_string(); +} diff --git a/src/delete.rs b/src/delete.rs new file mode 100644 index 0000000..d1cc878 --- /dev/null +++ b/src/delete.rs @@ -0,0 +1,17 @@ +use std::fs; + +pub fn delete(path: &str) { + match remove_directory(path) { + Ok(_value) => { + println!("Your folder: {} has been deleted!", path); + } + Err(error) => { + println!("{}", error) + } + } +} + +fn remove_directory(path: &str) -> std::io::Result<()> { + fs::remove_dir_all(path)?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..abd5e3c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +use std::process; +mod confirm; +mod delete; +mod path; + +fn main() { + loop { + let path = path::get_path(); + if path == "exit" { + process::exit(0); + } + let confirmation = confirm::request_confirmation(&path); + if confirmation == "yes" { + delete::delete(&path); + } + } +} diff --git a/src/path.rs b/src/path.rs new file mode 100644 index 0000000..ce24f6b --- /dev/null +++ b/src/path.rs @@ -0,0 +1,14 @@ +use std::io; + +pub fn get_path() -> String { + println!("Please input your folder location to delete. Write exit to quit."); + + let mut location = String::new(); + + io::stdin() + .read_line(&mut location) + .expect("Failed to read line"); + + let location = location.trim(); + return location.to_string(); +}