Skip to content

Commit

Permalink
feat(cli): basic argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Apr 17, 2024
1 parent 98dcd68 commit ab8c8f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/fs-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.3", features = ["derive", "wrap_help", "string"] }
23 changes: 23 additions & 0 deletions src/fs-gen/src/cli_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::{env, path::PathBuf};

use clap::{command, Parser};
/// Convert an OCI image into a CPIO file
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// The name of the image to download
#[arg(short, long)]
pub image_name: String,

/// The path to the output file
#[arg(short, long, default_value=get_default_log_path().into_os_string())]
pub ouput_file: PathBuf,
}

/// Get the default output path for the cpio file.
fn get_default_log_path() -> PathBuf {
let mut path = env::current_exe().unwrap();
path.pop();
path.push("output.cpio");
path
}
9 changes: 8 additions & 1 deletion src/fs-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
use clap::Parser;

use crate::cli_args::CliArgs;

mod cli_args;

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

0 comments on commit ab8c8f0

Please sign in to comment.