From 70a8b850a8253712387f7b164b2015550d4f7cce Mon Sep 17 00:00:00 2001 From: rachancheet <55895940+rachancheet@users.noreply.github.com> Date: Sat, 23 Mar 2024 23:00:26 +0530 Subject: [PATCH] feat: account for directories in file path (#96) Signed-off-by: Shinyzenith --------- Signed-off-by: Shinyzenith Authored-by: rachancheet Co-authored-by: Shinyzenith --- wayshot/src/cli.rs | 9 ++++++--- wayshot/src/wayshot.rs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index a441b748..0ad61c23 100644 --- a/wayshot/src/cli.rs +++ b/wayshot/src/cli.rs @@ -11,8 +11,11 @@ use clap::builder::TypedValueParser; #[derive(Parser)] #[command(version, about)] pub struct Cli { - /// Where to save the screenshot, "-" for stdout. Defaults to "$UNIX_TIMESTAMP-wayshot.$EXTENSION" unless --clipboard is present. - #[arg(value_name = "OUTPUT")] + /// Custom output path can be of the following types: + /// 1. Directory (Default naming scheme is used for the image output). + /// 2. Path (Encoding is automatically inferred from the extension). + /// 3. `-` (Indicates writing to terminal [stdout]). + #[arg(value_name = "OUTPUT", verbatim_doc_comment)] pub file: Option, /// Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout. @@ -34,7 +37,7 @@ pub struct Cli { /// Set image encoder, by default uses the file extension from the OUTPUT /// positional argument. Otherwise defaults to png. - #[arg(long, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION")] + #[arg(long, verbatim_doc_comment, visible_aliases = ["extension", "format", "output-format"], value_name = "FILE_EXTENSION")] pub encoding: Option, /// List all valid outputs diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 5340765f..04b20649 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -107,11 +107,14 @@ fn main() -> Result<()> { let mut stdout_print = false; let file = match cli.file { - Some(pathbuf) => { + Some(mut pathbuf) => { if pathbuf.to_string_lossy() == "-" { stdout_print = true; None } else { + if pathbuf.is_dir() { + pathbuf.push(utils::get_default_file_name(requested_encoding)); + } Some(pathbuf) } }