Skip to content

Commit a2fb4cd

Browse files
committed
start impl copy and paste command
1 parent abbfb74 commit a2fb4cd

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

cli/src/args.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum SubCommand {
5454
},
5555
#[clap(about = "Copy data from stdin to the server")]
5656
Copy {
57+
#[clap(short, long)]
58+
file_name: String,
5759
#[clap(short, long)]
5860
code_length: Option<usize>,
5961
#[clap(short, long,value_parser = parse_expire_time)]
@@ -88,6 +90,13 @@ pub enum SubCommand {
8890
#[clap(long, value_parser = parse_key_nonce, help = HELP_DECRYPT)]
8991
key_nonce: Option<KeyNonce>,
9092
},
93+
#[clap(about = "Paste a file from the server")]
94+
Paste {
95+
#[arg(short, long, value_parser = parse_file_url_path)]
96+
url_path: FileUrlPath,
97+
#[clap(long, value_parser = parse_key_nonce, help = HELP_DECRYPT)]
98+
key_nonce: Option<KeyNonce>,
99+
},
91100
#[clap(about = "Encrypt a file before uploading to the server")]
92101
Encrypt {
93102
#[clap(short, long, value_parser = parse_source_file)]

cli/src/command.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use url::Url;
1111

1212
use crate::{args::UploadOutput, client::CommandLineClient, util::crypto::KeyNonce};
1313

14+
#[derive(Debug)]
1415
pub struct UploadArguments {
1516
pub server_addr: String,
1617
pub auth: Option<(String, String)>,
@@ -24,9 +25,11 @@ pub struct UploadArguments {
2425
pub key_nonce: Option<KeyNonce>,
2526
}
2627

28+
#[derive(Debug)]
2729
pub struct CopyArguments {
2830
pub server_addr: String,
2931
pub auth: Option<(String, String)>,
32+
pub file_name: String,
3033
pub code_length: Option<usize>,
3134
pub expire: Option<u64>,
3235
pub allow_manual_deletion: Option<bool>,
@@ -75,7 +78,17 @@ pub async fn upload(args: UploadArguments) {
7578
};
7679
}
7780

78-
pub async fn copy(_args: CopyArguments) {}
81+
pub async fn copy(args: CopyArguments) {
82+
let _client = CommandLineClient::new(args.server_addr);
83+
let _param = UploadQueryParam {
84+
max_download: args.max_download,
85+
code_length: args.code_length,
86+
expire_secs: args.expire,
87+
allow_manual_deletion: args.allow_manual_deletion,
88+
qr_code_format: None,
89+
};
90+
todo!()
91+
}
7992

8093
fn show_upload_response(resp: ApiResponseResult<UploadResponse>, output: UploadOutput) {
8194
match resp {
@@ -128,6 +141,16 @@ pub async fn download(
128141
}
129142
}
130143

144+
pub async fn paste(
145+
server_addr: String,
146+
_auth: Option<(String, String)>,
147+
_url_path: FileUrlPath,
148+
_key_nonce: Option<KeyNonce>,
149+
) {
150+
let _client = CommandLineClient::new(server_addr);
151+
todo!()
152+
}
153+
131154
pub async fn info(server_addr: String, url_path: FileUrlPath, auth: Option<(String, String)>) {
132155
let client = CommandLineClient::new(server_addr);
133156
let (_, resp) = client.info(&url_path, auth).await.unwrap();

cli/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async fn main() {
4242
command::upload(args).await;
4343
}
4444
SubCommand::Copy {
45+
file_name,
4546
code_length,
4647
expire,
4748
allow_manual_deletion,
@@ -53,6 +54,7 @@ async fn main() {
5354
let args = CopyArguments {
5455
server_addr,
5556
auth: args.auth,
57+
file_name,
5658
code_length,
5759
expire,
5860
allow_manual_deletion,
@@ -79,6 +81,13 @@ async fn main() {
7981
)
8082
.await;
8183
}
84+
SubCommand::Paste {
85+
url_path,
86+
key_nonce,
87+
} => {
88+
let server_addr = args.server_addr.expect("Server address should be set.");
89+
command::paste(server_addr, args.auth, url_path, key_nonce).await;
90+
}
8291
SubCommand::Info { url_path } => {
8392
let server_addr = args.server_addr.expect("Server address should be set.");
8493
command::info(server_addr, url_path, args.auth).await

cli/tests/cli/upload_and_download_cli_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ async fn test_upload_encrypt_and_download_decrypt_command(ctx: &mut CliTestConte
7575
&ctx.server_addr,
7676
"download",
7777
"--url-path",
78-
&url_path.to_string(),
78+
url_path,
7979
"--destination",
8080
destination_dir.to_str().unwrap(),
8181
"--key-nonce",
8282
key_nonce,
8383
])
8484
.assert()
8585
.success();
86-
86+
// TODO check encrypt file is not exist
8787
let destination_file_path = destination_dir.join(file.file_name().unwrap());
8888
let actual_content = tokio::fs::read_to_string(destination_file_path)
8989
.await

0 commit comments

Comments
 (0)