Skip to content

Commit

Permalink
fix extension copy cli
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Mar 19, 2024
1 parent 81a0661 commit fc404d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use sdk::{dto::FileUrlPath, util::crypto::KeyNonce};
use std::path::PathBuf;

use crate::parse::{
parse_auth, parse_destination, parse_expire_time, parse_file_url_path, parse_key_nonce,
parse_source_file,
parse_auth, parse_destination, parse_expire_time, parse_file_name, parse_file_url_path,
parse_key_nonce, parse_source_file,
};

const HELP_ENCRYPT :&str = "The encrypt format should be `key:nonce`, with the key being 32 characters in length and the nonce being 19 characters.";
Expand Down Expand Up @@ -51,7 +51,7 @@ pub enum SubCommand {
},
#[clap(about = "Copy text data from standard input (stdin) to the server")]
Copy {
#[clap(short, long)]
#[clap(short, long,value_parser = parse_file_name)]
file_name: Option<PathBuf>,
#[clap(short, long)]
code_length: Option<usize>,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ async fn main() {
file_name.unwrap_or_else(|| add_extension(generate_random_string(FILE_NAME_LENGTH), "txt"))
}
.file_name()
.expect("Invalid file name")
.unwrap()
.to_str()
.unwrap()
.to_owned();

let content_type = get_content_type(&file_name).expect("Unknown content type");
let content_type = get_content_type(&file_name).unwrap();
let args = CopyArguments {
server_addr,
auth: args.auth,
Expand Down
8 changes: 8 additions & 0 deletions cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ pub fn parse_source_file(source_file: &str) -> anyhow::Result<PathBuf> {
}
}

pub fn parse_file_name(file_name: &str) -> anyhow::Result<PathBuf> {
let source_file = PathBuf::from(file_name);
if source_file.extension().is_none() {
return Err(anyhow!("The file name should include an extension."));
}
Ok(source_file)
}

pub fn parse_destination(destination: &str) -> anyhow::Result<PathBuf> {
let destination = PathBuf::from(destination);
if let Some(file_name) = destination.file_name() {
Expand Down

0 comments on commit fc404d8

Please sign in to comment.