Skip to content

Commit

Permalink
cleanup: make it cleaner for a PR
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTheWolff authored and Mathias-Boulay committed Apr 17, 2024
1 parent a64a0db commit fccee09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/fs-gen/src/cli_args.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{env, path::PathBuf};
//! Command-line interface arguments and their management
use std::{env, path::PathBuf};
use clap::{command, Parser};
use regex::Regex;

use once_cell::sync::Lazy;
use validator::Validate;

// So, for any of you who may be scared, this is the regex from the OCI Distribution Sepcification for the image name + the tag
/// Official regex from the OCI Distribution Sepcification (image name and tag)
static RE_IMAGE_NAME: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(\/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*:[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}").unwrap()
});
Expand All @@ -16,7 +16,6 @@ static RE_IMAGE_NAME: Lazy<Regex> = Lazy::new(|| {
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// The name of the image to download
#[arg(short, long)]
#[validate(regex(path = *RE_IMAGE_NAME))]
pub image_name: String,
Expand All @@ -33,7 +32,7 @@ impl CliArgs {

let validation = args.validate();
if validation.is_err() {
panic!("Invalid arguments: {}", validation.expect_err("wut"));
panic!("Invalid arguments: {}", validation.expect_err("Invalid arguments given"));
}

args
Expand Down
4 changes: 3 additions & 1 deletion src/fs-gen/src/image_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::path::{Path, PathBuf};
//! Image builder module
use std::path::{Path, PathBuf};
use vfs::{FileSystem, OverlayFS, PhysicalFS, VfsPath};

/// Builds a new initramfs from path blobs and places it into a given destination folder
pub fn build_new_image(blob_paths: &Vec<PathBuf>, output_folder: &Path) {
let virtual_paths = blob_paths
.iter()
Expand Down
7 changes: 3 additions & 4 deletions src/fs-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//! Main module for the initramfs tarball generation
use std::{
path::{Path, PathBuf},
path::PathBuf,
str::FromStr,
};

use clap::Parser;

use crate::{cli_args::CliArgs, image_builder::build_new_image};

mod cli_args;
mod image_builder;

fn main() {
let args = CliArgs::get_args();
println!("Hello, world!, {:?}", args);

let paths: Vec<PathBuf> =
vec![PathBuf::from_str("../../image-gen/blobs/sha256/layer_1").unwrap()];
Expand Down

0 comments on commit fccee09

Please sign in to comment.