Skip to content

Commit

Permalink
Merge pull request #7 from ZanzyTHEbar/feature/rust
Browse files Browse the repository at this point in the history
Feature/rust
  • Loading branch information
ZanzyTHEbar authored May 25, 2023
2 parents a5b0a9e + a76f1a1 commit 0ec8a0a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"addReleases": "bottom",
"assets": [
{
"path": "./dist/**/*"
"path": "./dist/**/*.{msi,deb,rpm,AppImage,dmg,zip,sha256sum}"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "desktop_cleaner"
version = "1.2.1"
edition = "2021"
authors = ["DaOfficialWizard"]
description = "A simple program to clean your desktop"
author = "DaOfficialWizard"
description = "A simple CLI utility to organize your desktop (or a specified directory)"
license = "MIT"
repository = "https://github.com/ZanzyTHEbar/Desktop-Cleaner"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions desktop-cleaner.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"cSpell.words": [
"appimage",
"argb",
"Automagically",
"barapp",
"Deque",
Expand Down
12 changes: 6 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use clap::Parser;
pub struct DesktopCleanerArgs {
/// The directory to clean
pub directory: Option<String>,
/// Whether or not to include hidden files
#[clap(long, action)]
pub hidden: Option<bool>,
/// Whether or not to include subdirectories
#[clap(long, short, action)]
pub recursive: Option<bool>,
// Whether or not to include hidden files
//#[clap(long, action)]
//pub hidden: Option<bool>,
// Whether or not to include subdirectories
//#[clap(long, short, action)]
//pub recursive: Option<bool>,
}
39 changes: 21 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::logger::{dc_stderr, dc_stdout};
use crate::prelude::*;
use directories::ProjectDirs;
use opzioni::Config;
Expand Down Expand Up @@ -64,29 +65,32 @@ impl DesktopCleanerConfig {
fn create_config_dir() -> Result<()> {
if let Some(project_dirs) = ProjectDirs::from(QUALIFIERS[0], QUALIFIERS[1], QUALIFIERS[2]) {
let config_path = project_dirs.config_dir();
let config_file_path = config_path.join(CONFIG_FILE);
if config_file_path.exists() {
return Ok(());
}

if !config_path.exists() {
eprintln!(
dc_stderr!(f!(
"Config Directory Doesn't Exist - Creating it: {:?}",
config_path
);
));
std::fs::create_dir_all(config_path)?;
}

let config_path = project_dirs.config_dir().join(CONFIG_FILE);

eprintln!("Config File Path: {:?}", config_path);

if config_path.exists() {
return Ok(());
}

eprintln!("Config File Doesn't Exist - Creating it: {:?}", config_path);
if config_path.exists() && !config_file_path.exists() {
dc_stderr!(f!("Config File Path: {:?}", config_file_path));
dc_stderr!(f!(
"Config File Doesn't Exist - Creating it: {:?}",
CONFIG_FILE
));

let mut file = OpenOptions::new()
.write(true)
.create(true)
.open(&config_path)?;
.open(&config_file_path)?;

eprintln!("Config File Being Generated: {:?}", config_path);
dc_stderr!("Config File Being Generated");

let config = indoc::indoc! {"
[file_types]
Expand All @@ -98,15 +102,14 @@ impl DesktopCleanerConfig {
return Err(e.into());
}

eprintln!(
dc_stderr!(f!(
"Created config file at: {:?}",
config_path.join(CONFIG_FILE)
);
config_file_path.join(CONFIG_FILE)
));

return Ok(());
}
let config_path = project_dirs.config_dir().join(CONFIG_FILE);
eprintln!("Config Exists: {:?}", config_path);
dc_stderr!("Config Exists");
}
Ok(())
}
Expand Down
13 changes: 13 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ impl Log for DesktopCleanerLogger {

fn flush(&self) {}
}

#[macro_export]
macro_rules! dc_stderr {
($($arg:tt)+) => (eprintln!("[Desktop Cleaner]: {}", $($arg)+));
}

#[macro_export]
macro_rules! dc_stdout {
($($arg:tt)+) => (println!("[Desktop Cleaner]: {}", $($arg)+));
}

pub(crate) use dc_stderr;
pub(crate) use dc_stdout;
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ fn main() -> Result<()> {
}

match files_moved {
0 => println!("[Desktop Cleaner]: Nothing to Do"),
1 => println!("[Desktop Cleaner]: Moved 1 file"),
_ => println!("[Desktop Cleaner]: Moved {} files", files_moved),
0 => dc_stdout!("Nothing to Do"),
1 => dc_stdout!("Moved 1 file"),
_ => dc_stdout!(f!("Moved {} files", files_moved)),
}

Ok(())
Expand Down
2 changes: 0 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pub mod direntry_froms;


0 comments on commit 0ec8a0a

Please sign in to comment.