Skip to content

Commit

Permalink
fixed panic on no args
Browse files Browse the repository at this point in the history
  • Loading branch information
elliot40404 committed Oct 6, 2022
1 parent 833222c commit efad0eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bonky"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Elliot40404"]
description = "The blazingly fast touch alternative written in rust. Made for the sole purpose to create files."
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use std::{env, fs};

fn check_if_dir(dir: &str) -> bool {
dir.contains("\\") || dir.contains("/")
dir.contains('\\') || dir.contains('/')
}

fn print_help() {
Expand All @@ -24,28 +24,28 @@ Example:
}

fn main() {
if (env::args().nth(1).unwrap() == "-h") || (env::args().nth(1).unwrap() == "--help") {
if (env::args().len() == 1 || env::args().nth(1).unwrap() == "-h")
|| (env::args().nth(1).unwrap() == "--help")
{
print_help();
return;
}
let args = env::args_os()
.map(|x| PathBuf::from(x))
.map(PathBuf::from)
.skip(1)
.collect::<Vec<_>>();
for arg in &args {
if check_if_dir(arg.to_str().unwrap()) {
if arg.to_str().unwrap().ends_with("/") || arg.to_str().unwrap().ends_with("\\") {
if arg.to_str().unwrap().ends_with('/') || arg.to_str().unwrap().ends_with('\\') {
fs::create_dir_all(arg).expect("Failed to create directory");
} else {
fs::create_dir_all(arg.parent().unwrap()).expect("Failed to create directory");
if !arg.exists() {
File::create(arg.to_owned()).expect("failed to create file");
File::create(arg).expect("failed to create file");
}
}
} else {
if !arg.exists() {
File::create(arg.to_owned()).expect("failed to create file");
}
} else if !arg.exists() {
File::create(arg).expect("failed to create file");
}
}
}

0 comments on commit efad0eb

Please sign in to comment.