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

accounting for directories in file path #96

Merged
merged 6 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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".
///Provide a custom file path ( encoding format is inferred from the file extension ). If path provided is directory then the output image is saved to provided path with default naming scheme. Default path is ./ , `-` indicates writing to terminal (stdout).
#[arg(value_name = "OUTPUT")]
pub file: Option<PathBuf>,

Expand Down
9 changes: 7 additions & 2 deletions wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ fn main() -> Result<()> {
}

let file = match cli.file {
Some(pathbuf) => {
Some(mut pathbuf) => {
if pathbuf.to_string_lossy() == "-" {
None
} else {
Some(pathbuf)
if pathbuf.is_dir() {
pathbuf.push(utils::get_default_file_name(requested_encoding));
Some(pathbuf)
} else {
Some(pathbuf)
}
}
}
None => Some(utils::get_default_file_name(requested_encoding)),
Expand Down
Loading