Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple dir #14

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ brew install k3ii/tap/qdir
```

**Check the [release page](https://github.com/k3ii/qdir/releases) to install the pre-built binaries.**

## Contributing

Contributions to Qdir are welcome! Please feel free to submit a Pull Request.

## Acknowledgments

* Inspired by Docker's naming generator for containers
* Thanks to all the scientists and technologists whose names are used in this project

## Support
If you encounter any problems or have any questions, please open an issue on the GitHub repository.
32 changes: 17 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,29 @@ pub fn random(length: usize) -> String {
.map(char::from)
.collect()
}

pub fn make_dir(depth: u8, name_length: usize, name: bool, pet: bool, tmp: bool) {
let mut path = if tmp {
pub fn make_dir(depth: u8, name_length: usize, name: bool, pet: bool, tmp: bool, multiple: usize) {
let base_path = if tmp {
std::env::temp_dir()
} else {
PathBuf::from(".")
};

let depth = if depth == 0 { 1 } else { depth };
let multiple = if multiple == 0 { 1 } else { multiple };

for _ in 0..depth {
let dir_name = if name {
get_random_name().unwrap().to_string()
} else if pet {
get_random_pet().unwrap().to_string()
} else {
random(name_length)
};
path.push(dir_name);
for _ in 0..multiple {
let mut path = base_path.clone();
for _ in 0..depth {
let dir_name = if name {
get_random_name().unwrap().to_string()
} else if pet {
get_random_pet().unwrap().to_string()
} else {
random(name_length)
};
path.push(dir_name);
}
fs::create_dir_all(&path).expect("Failed to create directory");
println!("{}", path.display());
}
fs::create_dir_all(&path).expect("Failed to create directory");

println!("{}", path.display());
}
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ fn main() {
.action(clap::ArgAction::SetTrue)
.help("Use the system's temporary directory"),
)
.arg(
Arg::new("multiple")
.short('m')
.long("multiple")
.value_parser(clap::value_parser!(usize))
.help("Create multiple directories at the same level")
.default_value("1"),
)
.group(
ArgGroup::new("name_or_pet_length")
.args(&["name", "pet", "length"])
Expand All @@ -56,10 +64,14 @@ fn main() {
.get_one::<usize>("length")
.copied()
.expect("Default length should be provided");
let multiple = matches
.get_one::<usize>("multiple")
.copied()
.expect("Default multiple should be provided");

let use_name = matches.get_flag("name");
let use_pet = matches.get_flag("pet");
let use_tmp = matches.get_flag("tmp");

make_dir(depth, length, use_name, use_pet, use_tmp);
make_dir(depth, length, use_name, use_pet, use_tmp, multiple);
}