From c9c379f55df9810b76c8a0f5de57d26d6d3a73ba Mon Sep 17 00:00:00 2001 From: Thomas Dickson Date: Tue, 18 Jun 2024 16:12:46 +1200 Subject: [PATCH] feat: add all single-letter curl options (with tests) --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69ce870..7eed78a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "ctow" -version = "0.1.5" +version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index d92edca..8af2382 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ctow" -version = "0.1.5" +version = "1.0.0" edition = "2021" license = "GPL-3.0-or-later" keywords = ["curl", "wget", "conversion"] diff --git a/README.md b/README.md index 64446a4..5597e57 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ctow can be used in two modes: command with arguments and as a command line inte You can simply pass `ctow [curl command]`, and ctow will print the converted command to stdout, with no formatting or anything when successful, so the output can be piped and manipulated into a command like `wget $(ctow [...])`, etc -Do note that when passing in a curl command, you do not explicitly need to include the leading `curl`, as it is discarded anyway. +Do note that when passing in a curl command, you do not explicitly need to include the leading `curl`, as it is discarded anyway. The options that curl uses (e.g. `-A User-Agent-Here`) __needs__ to have a space between the flag and its argument (this is a TODO). ### Command-Line Interface diff --git a/src/lib.rs b/src/lib.rs index 9ed61b8..cb36a86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,27 @@ pub fn convert_arg(arg: &str) -> Result { } else { // else, replace the curl with the wget match arg.split(' ').collect::>()[0] { + "-b" => Ok(arg.replace("-b ", "--load-cookies=")), + "-c" => Ok(arg.replace("-c ", "--save-cookies=")), + "-d" => Ok(arg.replace("-d ", "--post-data=")), + "-e" => Ok(arg.replace("-e ", "--header=\"Referer: ") + "\""), + "-g" => Ok(arg.replace("-g", "--no-glob")), + "-k" => Ok(arg.replace("-k", "--no-check-certificate")), + "-m" => Ok(arg.replace("-m ", "--timeout=")), + "-o" => Ok(arg.replace("-o ", "--output-document=")), + "-r" => Ok(arg.replace("-r ", "--header=\"Range: bytes=") + "\""), + "-s" => Ok(arg.replace("-s", "--quiet")), + "-u" => Ok(arg.replace("-u ", "--user=")), + "-z" => Ok(arg.replace("-z ", "--header=\"If-Modified-Since: ") + "\""), + + "-A" => Ok(arg.replace("-A ", "--header=\"User-Agent: ") + "\""), + "-C" => Ok(arg.replace("-C ", "--start-pos=")), + "-E" => Ok(arg.replace("-E ", "--certificate=")), "-H" => Ok(arg.replace("-H ", "--header '").replace('\\', "\\\\") + "'"), + "-I" => Ok(arg.replace("-I", "--method=HEAD")), + "-T" => Ok(arg.replace("-T ", "--method=PUT --body-file=")), + "-X" => Ok(arg.replace("-X ", "--method=")), + "--compressed" => Ok(arg.replace("--compressed", "--compression=auto")), "--connect-timeout" => Ok(arg.replace("--connect-timeout ", "--timeout=")), "--retry" => Ok(arg.replace("--retry ", "--tries=")), @@ -132,14 +152,83 @@ mod test { #[test] fn test_convert_args() { + // in this current format, ctow does not support -