Skip to content

Commit 1c4e62f

Browse files
authoredMay 7, 2023
Merge pull request #15 from sebastienrousseau/feat/libmake
feat(libmake): replacing `curl` with `reqwest` to remove the HTTP headers in downloaded template files
2 parents 90b2a6c + b7d599e commit 1c4e62f

18 files changed

+38
-34
lines changed
 

‎Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0"
1414
name = "libmake"
1515
repository = "https://github.com/sebastienrousseau/libmake.git"
1616
rust-version = "1.69.0"
17-
version = "0.1.7"
17+
version = "0.1.8"
1818
include = [
1919
"/CONTRIBUTING.md",
2020
"/LICENSE-APACHE",
@@ -45,6 +45,7 @@ assert_cmd = "2.0.11"
4545
clap = "4.2.7"
4646
csv = "1.2.1"
4747
figlet-rs = "0.1.5"
48+
reqwest = { version = "0.11.17", features = ["blocking"] }
4849
serde = { version = "1.0.162", features = ["derive"] }
4950
serde_json = "1.0.96"
5051
serde_yaml = "0.9.21"

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,6 @@ this project.
332332
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/libmake?style=for-the-badge&token=Q9KJ6XXL67 'Codecov'
333333
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge 'Crates.io Badge'
334334
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge 'Docs.rs Badge'
335-
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.7-orange.svg?style=for-the-badge 'Lib.rs Badge'
335+
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.8-orange.svg?style=for-the-badge 'Lib.rs Badge'
336336
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge 'License Badge'
337337
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust Badge'

‎TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ The library is designed to be used as a command-line tool. It is available on [C
5151
[9]: https://lib.rs/crates/libmake
5252
[14]: https://codecov.io/github/sebastienrousseau/libmake?branch=main
5353

54-
[banner]: https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/libmake/logo/logo-libmake.svg "libmake Banner"
54+
[banner]: https://kura.pro/libmake/images/banners/banner-libmake.svg "LibMake Banner"
5555
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/libmake?style=for-the-badge&token=Q9KJ6XXL67 'Codecov'
5656
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge 'Crates.io Badge'
5757
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge 'Docs.rs Badge'
58-
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.7-orange.svg?style=for-the-badge 'Lib.rs Badge'
58+
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.8-orange.svg?style=for-the-badge 'Lib.rs Badge'
5959
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge 'License Badge'
6060
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust Badge'

‎src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn build_cli() -> Result<ArgMatches, Error> {
147147
)
148148
.arg(
149149
Arg::new("version")
150-
.default_value("0.1.7")
150+
.default_value("0.1.8")
151151
.help("Sets the version of the library")
152152
.long("version")
153153
.short('v')

‎src/generator.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::interface::replace_placeholders;
2-
use assert_cmd::Command;
2+
use reqwest::blocking::get;
3+
// use assert_cmd::Command;
34
use serde::{Deserialize, Serialize};
45
use serde_json;
56
use serde_yaml;
@@ -217,22 +218,24 @@ pub fn create_template_folder() -> io::Result<()> {
217218
for file in &files {
218219
let file_url = format!("{}{}", url, file);
219220
let file_path = template_dir_path.join(file);
220-
let output = Command::new("curl")
221-
.arg("-s")
222-
.arg("-L")
223-
.arg("-o")
224-
.arg(file_path.as_os_str())
225-
.arg(file_url)
226-
.output()?;
227-
if !output.status.success() {
228-
return Err(io::Error::new(
221+
let response = get(&file_url).map_err(|e| {
222+
io::Error::new(
229223
io::ErrorKind::Other,
230-
format!(
231-
"Failed to download template file: {}",
232-
String::from_utf8_lossy(&output.stderr)
233-
),
234-
));
235-
}
224+
format!("Failed to download template file: {}", e),
225+
)
226+
})?;
227+
let file_contents = response.text().map_err(|e| {
228+
io::Error::new(
229+
io::ErrorKind::Other,
230+
format!("Failed to read response body: {}", e),
231+
)
232+
})?;
233+
std::fs::write(
234+
&file_path,
235+
file_contents
236+
.trim_start_matches('\n')
237+
.trim_end_matches('\n'),
238+
)?;
236239
}
237240
Ok(())
238241
}

‎src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//!
1414
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org)
1515
//! [![Crates.io](https://img.shields.io/crates/v/libmake.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/libmake)
16-
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.1.7-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/libmake)
16+
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.1.8-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/libmake)
1717
//! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/libmake)
1818
//! [![License](https://img.shields.io/crates/l/libmake.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT)
1919
//!

‎template/README.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ providing a lot of useful suggestions on how to improve this project.
194194
[docs-badge]: https://img.shields.io/docsrs/{name}.svg?style=for-the-badge 'Docs.rs badge'
195195
[libs-badge]: https://img.shields.io/badge/lib.rs-v{version}-orange.svg?style=for-the-badge 'Lib.rs badge'
196196
[license-badge]: https://img.shields.io/crates/l/{name}.svg?style=for-the-badge 'License badge'
197-
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
197+
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'

‎template/TEMPLATE.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ align="right"
6464
[docs-badge]: https://img.shields.io/docsrs/{name}.svg?style=for-the-badge 'Docs.rs badge'
6565
[libs-badge]: https://img.shields.io/badge/lib.rs-v{version}-orange.svg?style=for-the-badge 'Lib.rs badge'
6666
[license-badge]: https://img.shields.io/crates/l/{name}.svg?style=for-the-badge 'License badge'
67-
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
67+
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'

‎template/criterion.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ criterion_group!(
4747
{name}_join_benchmark,
4848
{name}_benchmark
4949
);
50-
criterion_main!({name}_macros_benchmark);
50+
criterion_main!({name}_macros_benchmark);

‎template/macros.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ macro_rules! {name}_print_vec {
117117
println!("{}", v);
118118
}
119119
}};
120-
}
120+
}

‎template/main.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ fn main() {
88
eprintln!("Error running {name}: {}", err);
99
std::process::exit(1);
1010
}
11-
}
11+
}

‎template/test.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ mod tests {
88
let {name} = {name}::new();
99
assert_eq!({name}, {name}::default());
1010
}
11-
}
11+
}

‎tests/data/mylibrary.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
author,build,categories,description,documentation,edition,email,homepage,keywords,license,name,output,readme,repository,rustversion,version,website
2-
Me,build.rs,"['category 1', 'category 2']",A library for doing things,https://lib.rs/crates/my_library,2021,test@test.com,https://test.com,"['keyword1', 'keyword2']",MIT OR Apache-2.0,my_library,my_library,README.md,https://github.com/test/test,1.69.0,0.1.7,https://test.com
2+
Me,build.rs,"['category 1', 'category 2']",A library for doing things,https://lib.rs/crates/my_library,2021,test@test.com,https://test.com,"['keyword1', 'keyword2']",MIT OR Apache-2.0,my_library,my_library,README.md,https://github.com/test/test,1.69.0,0.1.8,https://test.com

‎tests/data/mylibrary.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"readme": "README.md",
1515
"repository": "https://github.com/test/test",
1616
"rustversion": "1.69.0",
17-
"version": "0.1.7",
17+
"version": "0.1.8",
1818
"website": "https://test.com"
1919
}

‎tests/data/mylibrary.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ output = "my_library"
1313
readme = "README.md"
1414
repository = "https://github.com/test/test"
1515
rustversion = "1.69.0"
16-
version = "0.1.7"
16+
version = "0.1.8"
1717
website = "https://test.com"

‎tests/data/mylibrary.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ output: my_library
1313
readme: README.md
1414
repository: https://github.com/test/test
1515
rustversion: '1.69.0'
16-
version: '0.1.7'
16+
version: '0.1.8'
1717
website: https://test.com

‎tests/test_cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod tests {
2222
("readme", "README.md"),
2323
("repository", "https://github.com/test/test"),
2424
("rustversion", "1.69.0"),
25-
("version", "0.1.7"),
25+
("version", "0.1.8"),
2626
("website", "https://test.com"),
2727
];
2828

‎tests/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ mod tests {
105105
);
106106
assert_eq!(
107107
get_csv_field(Some(file_path), 15),
108-
Some(vec!["0.1.7".to_string()])
108+
Some(vec!["0.1.8".to_string()])
109109
);
110110
assert_eq!(
111111
get_csv_field(Some(file_path), 16),

0 commit comments

Comments
 (0)
Please sign in to comment.