Skip to content

Commit

Permalink
feat: account for directories in file path (waycrate#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
rachancheet and Shinyzenith authored Mar 23, 2024
1 parent f53e650 commit 2afa5b0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

14 changes: 9 additions & 5 deletions wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ 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 along with [OUTPUT] or stdout. Wayshot persists in the background to offer the image till the clipboard is overwritten.
#[arg(long)]
/// Copy image to clipboard along with [OUTPUT] or stdout.
/// Wayshot persists in the background to offer the image till the clipboard is overwritten.
#[arg(long, verbatim_doc_comment)]
pub clipboard: bool,

/// Log level to be used for printing to stderr
Expand All @@ -33,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 @@ -106,11 +106,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 2afa5b0

Please sign in to comment.