-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Malo Polese <[email protected]>
- Loading branch information
1 parent
915d73b
commit 1053c8a
Showing
8 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ Cargo.lock | |
.idea | ||
*.tar.gz | ||
.vscode | ||
ctr-bundle | ||
ctr-bundle | ||
quardle* | ||
lumper* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::{error::Error, fs::File, io::BufReader, path::Path}; | ||
|
||
use serde::Deserialize; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Deserialize, Debug)] | ||
pub struct QuarkConfig { | ||
pub quardle: String, | ||
pub kernel: String, | ||
pub initramfs: String, | ||
pub kernel_cmdline: String, | ||
pub image: String, | ||
pub kaps: String, | ||
pub offline: bool, | ||
pub bundle: String, | ||
} | ||
|
||
pub fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<QuarkConfig, Box<dyn Error>> { | ||
let file = File::open(path)?; | ||
let reader = BufReader::new(file); | ||
|
||
// Read the JSON contents of the file as an instance of `QuarkConfig`. | ||
let config = serde_json::from_reader(reader)?; | ||
|
||
Ok(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use flate2::read::GzDecoder; | ||
use log::info; | ||
use std::{fs::File, io::Result, path::Path}; | ||
use tar::Archive; | ||
|
||
/// Extract quardle archive to the output directory | ||
pub fn extract_quardle(output: &str, quardle: &str) -> Result<()> { | ||
if !Path::new(output).exists() { | ||
let tar_gz = File::open(quardle)?; | ||
let tar = GzDecoder::new(tar_gz); | ||
let mut archive = Archive::new(tar); | ||
|
||
info!("Unpacking quardle..."); | ||
archive.unpack(output)?; | ||
info!("Done"); | ||
} else { | ||
info!("quardle already exists"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,38 @@ | ||
use clap::StructOpt; | ||
use cli::{Cli, Result}; | ||
use log::{log_enabled, Level, LevelFilter}; | ||
use std::io::Write; | ||
|
||
mod cli; | ||
mod config; | ||
mod helper; | ||
|
||
fn main() -> Result<()> { | ||
let cli: Cli = Cli::parse(); | ||
|
||
cli.command().handler()?; | ||
let mut builder = env_logger::Builder::new(); | ||
let logger = builder | ||
.filter_level(match cli.verbose { | ||
1 => LevelFilter::Debug, | ||
2 => LevelFilter::Trace, | ||
_ => LevelFilter::Info, | ||
}) | ||
.format(|buf, record| { | ||
if record.level() != Level::Info | ||
|| log_enabled!(Level::Trace) | ||
|| log_enabled!(Level::Debug) | ||
{ | ||
return writeln!( | ||
buf, | ||
"{}: {}", | ||
record.level().to_string().to_lowercase(), | ||
record.args() | ||
); | ||
} | ||
writeln!(buf, "{}", record.args()) | ||
}); | ||
|
||
cli.command().handler(logger)?; | ||
|
||
Ok(()) | ||
} |