From 48f0a44eaa4754a04e9a0b47f736021807a06936 Mon Sep 17 00:00:00 2001 From: quirinecker Date: Mon, 6 Feb 2023 17:40:40 +0100 Subject: [PATCH] now using the bytes package --- Cargo.lock | 1 + Cargo.toml | 3 ++- src/app/commands/setup.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a56d0cd..bab985b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,6 +115,7 @@ dependencies = [ name = "docki" version = "0.2.0" dependencies = [ + "bytes", "regex", "reqwest", "zip-extract", diff --git a/Cargo.toml b/Cargo.toml index f3a855f..90a4e0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license-file = "LICENSE.txt" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bytes = "1.4.0" regex = "1.7.1" -reqwest = {version = "0.11.14", features = ["blocking"]} +reqwest = { version = "0.11.14", features = ["blocking"] } zip-extract = "0.1.1" diff --git a/src/app/commands/setup.rs b/src/app/commands/setup.rs index b5cf014..fcfca35 100644 --- a/src/app/commands/setup.rs +++ b/src/app/commands/setup.rs @@ -1,12 +1,13 @@ -use std::{collections::HashMap, env, fs::File, io::Write, fmt::format}; +use std::{collections::HashMap, env, fs::File, io::Write}; use super::traits::Command; +use bytes::Bytes; pub struct Setup; impl Command for Setup { fn execute(&self, _args: &HashMap) -> Result<(), String> { - println!("setting up"); + Self::setup(); return Ok(()) } @@ -24,10 +25,10 @@ impl Setup { let reveal_bin_url = format!("https://github.com/asciidoctor/asciidoctor-reveal.js/releases/download/v5.0.0-rc.1/asciidoctor-revealjs-{os}"); let reveal_bin = Self::donwload(&reveal_bin_url).expect("could not download asciidoctor binary"); let mut reveal_file = File::create("/usr/local/bin/asciidoctor").expect("could not save asciidoctor binary"); - reveal_file.write_all(reveal_bin); + reveal_file.write_all(&reveal_bin).expect("could not save asciidoctor binary"); } - fn donwload(url: &str) -> Result<&[u8], ()> { + fn donwload(url: &str) -> Result { let Ok(response) = reqwest::blocking::get(url) else { return Err(()); }; @@ -36,7 +37,7 @@ impl Setup { return Err(()); }; - return Ok(&data) + return Ok(data) } }