Skip to content

Commit

Permalink
feat: account for directories in file path (#96)
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>

---------

Signed-off-by: Shinyzenith <[email protected]>
Authored-by: rachancheet <[email protected]>
Co-authored-by: Shinyzenith <[email protected]>
  • Loading branch information
2 people authored and CheerfulPianissimo committed Mar 24, 2024
1 parent 72b4a42 commit 70a8b85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout.
Expand All @@ -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<EncodingFormat>,

/// List all valid outputs
Expand Down
5 changes: 4 additions & 1 deletion wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 70a8b85

Please sign in to comment.