Skip to content

Commit ba0a1fb

Browse files
authored
fix: documenation to be more comprehensive
Update documentation
2 parents 580a87a + f09e6d2 commit ba0a1fb

20 files changed

Lines changed: 127 additions & 15 deletions

File tree

.github/workflows/lambda-repo-security.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
# documentation.
55
# rust-clippy is a tool that runs a bunch of lints to catch common
66
# mistakes in your Rust code and help improve your Rust code.
7-
# More details at https://github.com/rust-lang/rust-clippy
7+
# More details at https://github.com/rust-lang/rust-clippy
88
# and https://rust-lang.github.io/rust-clippy/
99

1010
name: rust fmt + clippy analyze
1111

1212
on:
1313
push:
14-
branches: [ "main" ]
14+
branches: ["main"]
1515
pull_request:
1616
# The branches below must be a subset of the branches above
17-
branches: [ "main" ]
17+
branches: ["main"]
1818
schedule:
19-
- cron: '41 10 * * 5'
19+
- cron: "41 10 * * 5"
2020

2121
jobs:
2222
rust-clippy-analyze:
@@ -25,7 +25,7 @@ jobs:
2525
permissions:
2626
contents: read
2727
security-events: write
28-
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
28+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
2929
steps:
3030
- name: Checkout code
3131
uses: actions/checkout@v4
@@ -42,7 +42,9 @@ jobs:
4242
run: cargo install clippy-sarif sarif-fmt
4343

4444
- name: Check formatting
45-
run: cargo fmt --all --check
45+
run: |
46+
rustup component add rustfmt --toolchain nightly-2025-09-26
47+
cargo +nightly-2025-09-26 fmt --all --check
4648
4749
- name: Run rust-clippy
4850
run: |

crates/lambda-rs-args/src/lib.rs

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::needless_return)]
12
//! # Lambda Args
23
//! Lambda Args is a simple argument parser for Rust. It is designed to be
34
//! simple to use and primarily for use in lambda command line applications.
@@ -7,6 +8,18 @@ use std::{
78
fmt,
89
};
910

11+
/// Configurable command‑line argument parser for Lambda tools and examples.
12+
///
13+
/// Features:
14+
/// - Long/short flags with aliases (e.g., "-o", "--output")
15+
/// - Positional arguments in declaration order
16+
/// - Type‑aware parsing (`string`, `integer`, `float`, `boolean`, `count`, lists)
17+
/// - Optional environment variable and config‑file integration
18+
/// - Mutually exclusive groups and simple requires relationships
19+
/// - Subcommands with their own parsers
20+
///
21+
/// Use the builder to register arguments and then call `parse` with a slice of
22+
/// tokens (usually `std::env::args().collect()`).
1023
pub struct ArgumentParser {
1124
name: String,
1225
description: String,
@@ -24,20 +37,32 @@ pub struct ArgumentParser {
2437
}
2538

2639
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
40+
/// Supported value types for an argument definition.
2741
pub enum ArgumentType {
42+
/// `true`/`false` (or implied by presence when compiled as a flag).
2843
Boolean,
44+
/// 64‑bit signed integer.
2945
Integer,
46+
/// 32‑bit floating point number.
3047
Float,
48+
/// 64‑bit floating point number.
3149
Double,
50+
/// UTF‑8 string.
3251
String,
52+
/// Count of flag occurrences (e.g., `-vvv` => 3).
3353
Count,
54+
/// One or more strings (space‑separated tokens).
3455
StringList,
56+
/// One or more integers.
3557
IntegerList,
58+
/// One or more 32‑bit floats.
3659
FloatList,
60+
/// One or more 64‑bit floats.
3761
DoubleList,
3862
}
3963

4064
#[derive(Debug, Clone, PartialEq, PartialOrd)]
65+
/// Parsed value container used in results and defaults.
4166
pub enum ArgumentValue {
4267
None,
4368
Boolean(bool),
@@ -88,6 +113,7 @@ impl Into<f64> for ArgumentValue {
88113
}
89114

90115
#[derive(Debug)]
116+
/// Declarative definition for a single CLI argument or positional parameter.
91117
pub struct Argument {
92118
name: String,
93119
description: String,
@@ -99,7 +125,11 @@ pub struct Argument {
99125
}
100126

101127
impl Argument {
102-
/// Creates a new argument where the name represents
128+
/// Create a new argument definition.
129+
///
130+
/// The `name` should be the canonical identifier used in help/usage output
131+
/// (for example, `--output` or `--count`). For positional parameters call
132+
/// `as_positional()` when building.
103133
pub fn new(name: &str) -> Self {
104134
return Argument {
105135
name: name.to_string(),
@@ -118,13 +148,13 @@ impl Argument {
118148
return self;
119149
}
120150

121-
/// Sets the type for the ArgumentParser to parse the arguments value into.
151+
/// Sets the type the parser should use when converting the raw value.
122152
pub fn with_type(mut self, arg_type: ArgumentType) -> Self {
123153
self.arg_type = arg_type;
124154
return self;
125155
}
126156

127-
/// Sets the description (Help string) of the argument for
157+
/// Set a human‑readable description used in help/usage output.
128158
pub fn with_description(mut self, description: &str) -> Self {
129159
self.description = description.to_string();
130160
return self;
@@ -167,27 +197,33 @@ impl Argument {
167197
return self.arg_type.clone();
168198
}
169199

200+
/// Canonical name used for matching and display (e.g., `--output`).
170201
pub fn name(&self) -> &str {
171202
return self.name.as_ref();
172203
}
173204

205+
/// Default value used when the argument is not present.
174206
pub fn default_value(&self) -> ArgumentValue {
175207
return self.default_value.clone();
176208
}
177209

210+
/// Description shown in `usage()` output.
178211
pub fn description(&self) -> &str {
179212
return self.description.as_ref();
180213
}
181214

215+
/// Declared aliases that resolve to this argument (e.g., `-o`).
182216
pub fn aliases(&self) -> &Vec<String> {
183217
&self.aliases
184218
}
219+
/// Whether the argument is positional (no leading `-`/`--`).
185220
pub fn is_positional(&self) -> bool {
186221
self.positional
187222
}
188223
}
189224

190225
#[derive(Debug, Clone)]
226+
/// A single parsed argument result as `(name, value)`.
191227
pub struct ParsedArgument {
192228
name: String,
193229
value: ArgumentValue,
@@ -205,6 +241,7 @@ impl ParsedArgument {
205241
return self.name.clone();
206242
}
207243

244+
/// Return a clone of the parsed value.
208245
pub fn value(&self) -> ArgumentValue {
209246
return self.value.clone();
210247
}
@@ -240,17 +277,20 @@ impl ArgumentParser {
240277
return self.args.len();
241278
}
242279

280+
/// Add an author string displayed in `usage()`.
243281
pub fn with_author(mut self, author: &str) -> Self {
244282
self.authors.push(author.to_string());
245283
self
246284
}
247285

248286
// TODO(vmarcella): Add description to the name
287+
/// Add a human‑readable description shown in `usage()`.
249288
pub fn with_description(mut self, description: &str) -> Self {
250289
self.description = description.to_string();
251290
self
252291
}
253292

293+
/// Register an argument definition with the parser.
254294
pub fn with_argument(mut self, argument: Argument) -> Self {
255295
let idx = self.args.len();
256296
let name = argument.name().to_string();
@@ -264,7 +304,7 @@ impl ArgumentParser {
264304
return self;
265305
}
266306

267-
/// Set an environment variable prefix (e.g., "OBJ_LOADER").
307+
/// Set an environment variable prefix to read defaults (e.g., "OBJ_LOADER").
268308
pub fn with_env_prefix(mut self, prefix: &str) -> Self {
269309
self.env_prefix = Some(prefix.to_string());
270310
self
@@ -290,13 +330,13 @@ impl ArgumentParser {
290330
self
291331
}
292332

293-
/// Merge values from a simple key=value config file (optional).
333+
/// Merge values from a simple `key=value` config file (optional).
294334
pub fn with_config_file(mut self, path: &str) -> Self {
295335
self.config_path = Some(path.to_string());
296336
self
297337
}
298338

299-
/// Add a subcommand parser.
339+
/// Add a subcommand parser which activates on a matching first token.
300340
pub fn with_subcommand(mut self, mut sub: ArgumentParser) -> Self {
301341
sub.is_subcommand = true;
302342
let key = sub.name.clone();
@@ -717,7 +757,7 @@ impl ArgumentParser {
717757
})
718758
}
719759

720-
/// Backwards-compatible panicking API. Prefer `parse` for non-panicking behavior.
760+
/// Backwardscompatible panicking API. Prefer `parse` for nonpanicking use.
721761
pub fn compile(self, args: &[String]) -> Vec<ParsedArgument> {
722762
match self.parse(args) {
723763
Ok(parsed) => parsed.into_vec(),
@@ -791,16 +831,23 @@ fn parse_value(arg: &Argument, raw: &str) -> Result<ArgumentValue, ArgsError> {
791831
}
792832

793833
#[derive(Debug)]
834+
/// Errors that may occur during argument parsing.
794835
pub enum ArgsError {
836+
/// An unknown flag or option was encountered.
795837
UnknownArgument(String),
838+
/// The same flag/option was specified more than once when not allowed.
796839
DuplicateArgument(String),
840+
/// A flag/option expecting a value did not receive one.
797841
MissingValue(String),
842+
/// A provided value could not be parsed into the expected type.
798843
InvalidValue {
799844
name: String,
800845
expected: String,
801846
value: String,
802847
},
848+
/// A required option or positional argument was not provided.
803849
MissingRequired(String),
850+
/// Help was requested; contains a preformatted usage string.
804851
HelpRequested(String),
805852
}
806853

@@ -831,25 +878,28 @@ impl fmt::Display for ArgsError {
831878

832879
impl std::error::Error for ArgsError {}
833880

834-
/// A parsed arguments wrapper with typed getters.
881+
/// Parsed arguments with typed getters and subcommand support.
835882
#[derive(Debug, Clone)]
836883
pub struct ParsedArgs {
837884
values: Vec<ParsedArgument>,
838885
subcommand: Option<(String, Box<ParsedArgs>)>,
839886
}
840887

841888
impl ParsedArgs {
889+
/// Convert into the raw underlying `(name, value)` vector.
842890
pub fn into_vec(self) -> Vec<ParsedArgument> {
843891
self.values
844892
}
845893

894+
/// True if the named argument is present (and not `None`).
846895
pub fn has(&self, name: &str) -> bool {
847896
self
848897
.values
849898
.iter()
850899
.any(|p| p.name == name && !matches!(p.value, ArgumentValue::None))
851900
}
852901

902+
/// Get a `String` value by name, if present and typed as string.
853903
pub fn get_string(&self, name: &str) -> Option<String> {
854904
self
855905
.values
@@ -861,6 +911,7 @@ impl ParsedArgs {
861911
})
862912
}
863913

914+
/// Get an `i64` value by name, if present and typed as integer.
864915
pub fn get_i64(&self, name: &str) -> Option<i64> {
865916
self
866917
.values
@@ -872,6 +923,7 @@ impl ParsedArgs {
872923
})
873924
}
874925

926+
/// Get an `f32` value by name, if present and typed as float.
875927
pub fn get_f32(&self, name: &str) -> Option<f32> {
876928
self
877929
.values
@@ -883,6 +935,7 @@ impl ParsedArgs {
883935
})
884936
}
885937

938+
/// Get an `f64` value by name, if present and typed as double.
886939
pub fn get_f64(&self, name: &str) -> Option<f64> {
887940
self
888941
.values
@@ -894,6 +947,7 @@ impl ParsedArgs {
894947
})
895948
}
896949

950+
/// Get a `bool` value by name, if present and typed as boolean.
897951
pub fn get_bool(&self, name: &str) -> Option<bool> {
898952
self
899953
.values

crates/lambda-rs-logging/src/handler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use std::{
99

1010
use crate::LogLevel;
1111

12+
/// Pluggable sink for log records emitted by the `Logger`.
13+
///
14+
/// Implementors decide how to format and where to deliver messages for each
15+
/// severity level.
1216
pub trait Handler {
1317
fn trace(&mut self, message: String);
1418
fn debug(&mut self, message: String);
@@ -102,6 +106,7 @@ impl Handler for FileHandler {
102106
}
103107

104108
#[derive(Debug, Clone, PartialEq, PartialOrd)]
109+
/// A handler that prints colored log lines to stdout.
105110
pub struct ConsoleHandler {
106111
name: String,
107112
}

crates/lambda-rs-logging/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::needless_return)]
12
//! A simple logging library for lambda-rs crates.
23
34
use std::fmt::Debug;

crates/lambda-rs-platform/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#![allow(clippy::needless_return)]
2+
//! Cross‑platform abstractions and utilities used by Lambda.
3+
//!
4+
//! This crate hosts thin wrappers around `winit` (windowing) and `wgpu`
5+
//! (graphics) that provide consistent defaults and ergonomic builders, along
6+
//! with shader compilation backends and small helper modules (e.g., OBJ
7+
//! loading and random number generation).
18
pub mod obj;
29
pub mod rand;
310
pub mod shader;

crates/lambda-rs-platform/src/obj/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Minimal helpers for loading Wavefront OBJ assets.
2+
//!
3+
//! These functions are thin wrappers around the `obj` crate used by examples
4+
//! and tooling to import meshes.
15
use std::{
26
fs::File,
37
io::BufReader,

crates/lambda-rs-platform/src/rand/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Random number utilities used by examples and tests.
2+
//!
3+
//! Functions here delegate to the `rand` crate to generate simple random
4+
//! values and uniformly distributed sequences.
15
use rand::Rng;
26

37
/// Generate a random float within any given range.

crates/lambda-rs-platform/src/winit/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ pub struct WindowSize {
8181
pub physical: PhysicalSize<u32>,
8282
}
8383

84+
/// Aggregated window handle with cached sizing and monitor metadata.
8485
pub struct WindowHandle {
8586
pub window_handle: Window,
8687
pub size: WindowSize,
8788
pub monitor_handle: MonitorHandle,
8889
}
8990

9091
// Should we take the loop as a field right here? Probably a ref or something? IDK
92+
/// Builder for constructing a `WindowHandle` from window properties.
9193
pub struct WindowHandleBuilder {
9294
window_handle: Option<Window>,
9395
size: WindowSize,

crates/lambda-rs/examples/minimal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::needless_return)]
12
//! Minimal application which configures a window & render context before
23
//! starting the runtime. You can use this as a starting point for your own
34
//! applications or to verify that your system is configured to run lambda

crates/lambda-rs/examples/push_constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::needless_return)]
2+
13
use lambda::{
24
component::Component,
35
events::WindowEvent,

0 commit comments

Comments
 (0)