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

feat(libmake): replacing curl with reqwest to remove the HTTP he… #15

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0"
name = "libmake"
repository = "https://github.com/sebastienrousseau/libmake.git"
rust-version = "1.69.0"
version = "0.1.7"
version = "0.1.8"
include = [
"/CONTRIBUTING.md",
"/LICENSE-APACHE",
Expand Down Expand Up @@ -45,6 +45,7 @@ assert_cmd = "2.0.11"
clap = "4.2.7"
csv = "1.2.1"
figlet-rs = "0.1.5"
reqwest = { version = "0.11.17", features = ["blocking"] }
serde = { version = "1.0.162", features = ["derive"] }
serde_json = "1.0.96"
serde_yaml = "0.9.21"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,6 @@ this project.
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/libmake?style=for-the-badge&token=Q9KJ6XXL67 'Codecov'
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge 'Crates.io Badge'
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge 'Docs.rs Badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.7-orange.svg?style=for-the-badge 'Lib.rs Badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.8-orange.svg?style=for-the-badge 'Lib.rs Badge'
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge 'License Badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust Badge'
4 changes: 2 additions & 2 deletions TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ The library is designed to be used as a command-line tool. It is available on [C
[9]: https://lib.rs/crates/libmake
[14]: https://codecov.io/github/sebastienrousseau/libmake?branch=main

[banner]: https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/libmake/logo/logo-libmake.svg "libmake Banner"
[banner]: https://kura.pro/libmake/images/banners/banner-libmake.svg "LibMake Banner"
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/libmake?style=for-the-badge&token=Q9KJ6XXL67 'Codecov'
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge 'Crates.io Badge'
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge 'Docs.rs Badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.7-orange.svg?style=for-the-badge 'Lib.rs Badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.1.8-orange.svg?style=for-the-badge 'Lib.rs Badge'
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge 'License Badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust Badge'
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn build_cli() -> Result<ArgMatches, Error> {
)
.arg(
Arg::new("version")
.default_value("0.1.7")
.default_value("0.1.8")
.help("Sets the version of the library")
.long("version")
.short('v')
Expand Down
35 changes: 19 additions & 16 deletions src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::interface::replace_placeholders;
use assert_cmd::Command;
use reqwest::blocking::get;
// use assert_cmd::Command;
use serde::{Deserialize, Serialize};
use serde_json;
use serde_yaml;
Expand Down Expand Up @@ -217,22 +218,24 @@ pub fn create_template_folder() -> io::Result<()> {
for file in &files {
let file_url = format!("{}{}", url, file);
let file_path = template_dir_path.join(file);
let output = Command::new("curl")
.arg("-s")
.arg("-L")
.arg("-o")
.arg(file_path.as_os_str())
.arg(file_url)
.output()?;
if !output.status.success() {
return Err(io::Error::new(
let response = get(&file_url).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!(
"Failed to download template file: {}",
String::from_utf8_lossy(&output.stderr)
),
));
}
format!("Failed to download template file: {}", e),
)
})?;
let file_contents = response.text().map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed to read response body: {}", e),
)
})?;
std::fs::write(
&file_path,
file_contents
.trim_start_matches('\n')
.trim_end_matches('\n'),
)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//!
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org)
//! [![Crates.io](https://img.shields.io/crates/v/libmake.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/libmake)
//! [![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)
//! [![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)
//! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/libmake)
//! [![License](https://img.shields.io/crates/l/libmake.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT)
//!
Expand Down
2 changes: 1 addition & 1 deletion template/README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ providing a lot of useful suggestions on how to improve this project.
[docs-badge]: https://img.shields.io/docsrs/{name}.svg?style=for-the-badge 'Docs.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v{version}-orange.svg?style=for-the-badge 'Lib.rs badge'
[license-badge]: https://img.shields.io/crates/l/{name}.svg?style=for-the-badge 'License badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
2 changes: 1 addition & 1 deletion template/TEMPLATE.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ align="right"
[docs-badge]: https://img.shields.io/docsrs/{name}.svg?style=for-the-badge 'Docs.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v{version}-orange.svg?style=for-the-badge 'Lib.rs badge'
[license-badge]: https://img.shields.io/crates/l/{name}.svg?style=for-the-badge 'License badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
2 changes: 1 addition & 1 deletion template/criterion.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ criterion_group!(
{name}_join_benchmark,
{name}_benchmark
);
criterion_main!({name}_macros_benchmark);
criterion_main!({name}_macros_benchmark);
2 changes: 1 addition & 1 deletion template/macros.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ macro_rules! {name}_print_vec {
println!("{}", v);
}
}};
}
}
2 changes: 1 addition & 1 deletion template/main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fn main() {
eprintln!("Error running {name}: {}", err);
std::process::exit(1);
}
}
}
2 changes: 1 addition & 1 deletion template/test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod tests {
let {name} = {name}::new();
assert_eq!({name}, {name}::default());
}
}
}
2 changes: 1 addition & 1 deletion tests/data/mylibrary.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
author,build,categories,description,documentation,edition,email,homepage,keywords,license,name,output,readme,repository,rustversion,version,website
Me,build.rs,"['category 1', 'category 2']",A library for doing things,https://lib.rs/crates/my_library,2021,[email protected],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
Me,build.rs,"['category 1', 'category 2']",A library for doing things,https://lib.rs/crates/my_library,2021,[email protected],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
2 changes: 1 addition & 1 deletion tests/data/mylibrary.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"readme": "README.md",
"repository": "https://github.com/test/test",
"rustversion": "1.69.0",
"version": "0.1.7",
"version": "0.1.8",
"website": "https://test.com"
}
2 changes: 1 addition & 1 deletion tests/data/mylibrary.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ output = "my_library"
readme = "README.md"
repository = "https://github.com/test/test"
rustversion = "1.69.0"
version = "0.1.7"
version = "0.1.8"
website = "https://test.com"
2 changes: 1 addition & 1 deletion tests/data/mylibrary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ output: my_library
readme: README.md
repository: https://github.com/test/test
rustversion: '1.69.0'
version: '0.1.7'
version: '0.1.8'
website: https://test.com
2 changes: 1 addition & 1 deletion tests/test_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod tests {
("readme", "README.md"),
("repository", "https://github.com/test/test"),
("rustversion", "1.69.0"),
("version", "0.1.7"),
("version", "0.1.8"),
("website", "https://test.com"),
];

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod tests {
);
assert_eq!(
get_csv_field(Some(file_path), 15),
Some(vec!["0.1.7".to_string()])
Some(vec!["0.1.8".to_string()])
);
assert_eq!(
get_csv_field(Some(file_path), 16),
Expand Down