Skip to content

Commit

Permalink
added base to the command line argument parser
Browse files Browse the repository at this point in the history
  • Loading branch information
waridh committed Sep 9, 2024
1 parent 05f4b0e commit d51cbd0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.86"
clap = { version = "4.5.17", features = ["derive"] }
indicatif = { version = "*", features = ["rayon"] }
rand = "0.8.5"
rayon = "1.10.0"
33 changes: 31 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::{anyhow, Result};
use material::Lambertian;
use vec3::Vec3;

Expand All @@ -11,6 +12,19 @@ mod material;
mod ray;
mod sphere;
mod vec3;
use clap::Parser;
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(name = "raytracerust")]
#[command(version = "0.1.0")]
#[command(about="CLI program that generates a ray tracing image", long_about=None)]
pub struct Args {
/// Output destination path. If not provided, the program will send the
/// output into stdout
#[arg(short = 'o', long, value_name = "OUTPUT")]
output: Option<PathBuf>,
}

/// Basic world configuration used in the ray tracing in a weekend book
#[allow(dead_code)]
Expand Down Expand Up @@ -125,7 +139,9 @@ fn make_random_world() -> hittable::HittableList {
world
}

fn main() {
fn run(args: &Args) -> Result<()> {
// Configure camera
// TODO: Move this logic out to its own function
let mut camera_builder = camera::Camera::builder();
camera_builder.aspect_ratio = 5. / 4.;
camera_builder.image_width = 1200;
Expand All @@ -142,5 +158,18 @@ fn main() {
let world = make_random_world();
let mut camera = camera_builder.build();

camera.render(&world);
match &args.output {
None => {
camera.render(&world);
Ok(())
}
Some(x) => Err(anyhow!("Not implemented yet")),
}
}

fn main() {
if let Err(e) = run(&Args::parse()) {
eprintln!("{e}");
std::process::exit(1);
}
}

0 comments on commit d51cbd0

Please sign in to comment.