Skip to content

Commit 0dc939e

Browse files
committed
some more docs
1 parent 0546c22 commit 0dc939e

File tree

13 files changed

+183
-97
lines changed

13 files changed

+183
-97
lines changed

bin/src/commands/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub fn add_args(cmd: Command) -> Command {
3333
)
3434
}
3535

36+
/// Execute the build command
37+
///
38+
/// # Errors
39+
/// [`Error`] depending on the modules
3640
pub fn execute(matches: &ArgMatches, executor: &mut Executor) -> Result<(), Error> {
3741
executor.collapse(Collapse::No);
3842

bin/src/commands/dev.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ pub fn add_args(cmd: Command) -> Command {
4242
)
4343
}
4444

45+
/// Execute the dev command
46+
///
47+
/// # Errors
48+
/// [`Error`] depending on the modules
4549
pub fn execute(matches: &ArgMatches, launch_optionals: &[String]) -> Result<Context, Error> {
4650
let all_optionals = matches.get_one::<bool>("optionals") == Some(&true);
4751
let optionals = matches

bin/src/commands/launch.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub fn cli() -> Command {
3232
}
3333

3434
#[allow(clippy::too_many_lines)]
35+
/// Execute the launch command
36+
///
37+
/// # Errors
38+
/// [`Error`] depending on the modules
3539
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
3640
let config = Configuration::from_file(&Path::new(".hemtt").join("project.toml"))?;
3741
let Some(mainprefix) = config.mainprefix() else {
@@ -42,10 +46,10 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
4246

4347
let launch_config = matches
4448
.get_one::<String>("config")
45-
.expect("a config to be set");
49+
.map_or_else(|| String::from("default"), std::string::ToString::to_string);
4650
let launch = config
4751
.hemtt()
48-
.launch(launch_config)
52+
.launch(&launch_config)
4953
.ok_or(Error::LaunchConfigNotFound(launch_config.to_string()))?;
5054

5155
let Some(arma3dir) =

bin/src/commands/new.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ pub fn cli() -> Command {
1818
)
1919
}
2020

21+
/// Execute the new command
22+
///
23+
/// # Errors
24+
/// [`Error`] depending on the modules
25+
///
26+
/// # Panics
27+
/// If a name is not provided, but this is usually handled by clap
2128
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
2229
if !std::io::stdin().is_terminal() {
2330
return Err(Error::NewNoInput);

bin/src/commands/release.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub fn cli() -> Command {
2525
)
2626
}
2727

28+
/// Execute the release command
29+
///
30+
/// # Errors
31+
/// [`Error`] depending on the modules
2832
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
2933
let ctx = Context::new(std::env::current_dir()?, "release")?;
3034
let mut executor = Executor::new(&ctx);

bin/src/commands/script.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ pub fn add_args(cmd: Command) -> Command {
3333
)
3434
}
3535

36+
/// Execute the script command
37+
///
38+
/// # Errors
39+
/// [`Error`] depending on the modules
40+
///
41+
/// # Panics
42+
/// If a name is not provided, but this is usually handled by clap
3643
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
3744
let all_optionals = matches.get_one::<bool>("optionals") == Some(&true);
3845
let optionals = matches

bin/src/config/project/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{mem::MaybeUninit, path::Path};
1+
use std::mem::MaybeUninit;
22

33
use git2::Repository;
44
use hemtt_common::version::Version;

bin/src/context.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ pub struct Context {
2121
}
2222

2323
impl Context {
24+
/// Create a new context
25+
///
26+
/// # Errors
27+
/// [`Error::ConfigNotFound`] if the project.toml is not found
28+
/// [`Error::Io`] if the temporary folder fails to be created
29+
/// [`Error::Git`] if the git hash is invalid
30+
/// [`Error::Version`] if the version is invalid
31+
///
32+
/// # Panics
33+
/// If the project folder is not a valid [`OsStr`] (UTF-8)
2434
pub fn new(root: PathBuf, folder: &str) -> Result<Self, Error> {
2535
let config = {
2636
let path = root.join(".hemtt").join("project.toml");
@@ -42,7 +52,7 @@ impl Context {
4252
.skip(2)
4353
.collect::<PathBuf>()
4454
.to_str()
45-
.unwrap()
55+
.expect("valid utf-8")
4656
.replace(['\\', '/'], "_"),
4757
);
4858
trace!("using temporary folder: {:?}", tmp.display());

bin/src/modules/archive.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ use std::fs::create_dir_all;
22

33
use crate::{context::Context, error::Error};
44

5+
/// Creates the release zips
6+
///
7+
/// # Errors
8+
/// [`Error`] depending on the modules
9+
/// [`Error::Zip`] if the zip fails to create
10+
/// [`Error::Io`] if the zip fails to write
11+
/// [`Error::Version`] if the version is invalid
12+
///
13+
/// # Panics
14+
/// If we are somehow not in the HEMTT folder
515
pub fn release(ctx: &Context) -> Result<(), Error> {
616
let output = ctx.project_folder().join("releases");
717
trace!("using releases folder: {:?}", output.display());

bin/src/modules/hook/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use super::Module;
1414
mod libraries;
1515
mod time;
1616

17+
/// Creates a sccope for a Rhai script
18+
///
19+
/// # Errors
20+
/// [`Error::Version`] if the version is not a valid semver version
1721
pub fn scope(ctx: &Context, vfs: bool) -> Result<Scope, Error> {
1822
let mut scope = Scope::new();
1923
scope.push_constant("HEMTT_VERSION", env!("CARGO_PKG_VERSION"));
@@ -69,6 +73,15 @@ impl Default for Hooks {
6973
}
7074

7175
impl Hooks {
76+
/// Run a folder of hooks
77+
///
78+
/// # Errors
79+
/// [`Error::ScriptNotFound`] if the script does not exist
80+
/// [`Error::HookFatal`] if the script calls `fatal`
81+
/// [`Error::Rhai`] if the script is invalid
82+
///
83+
/// # Panics
84+
/// If a file path is not a valid [`OsStr`] (UTF-8)
7285
pub fn run_folder(self, ctx: &Context, name: &str, vfs: bool) -> Result<(), Error> {
7386
if !self.0 {
7487
return Ok(());
@@ -110,6 +123,15 @@ impl Hooks {
110123
Ok(())
111124
}
112125

126+
/// Run a script
127+
///
128+
/// # Errors
129+
/// [`Error::ScriptNotFound`] if the script does not exist
130+
/// [`Error::HookFatal`] if the script calls `fatal`
131+
/// [`Error::Rhai`] if the script is invalid
132+
///
133+
/// # Panics
134+
/// If a file path is not a valid [`OsStr`] (UTF-8)
113135
pub fn run_file(ctx: &Context, name: &str) -> Result<(), Error> {
114136
let mut path = ctx.hemtt_folder().join("scripts").join(name);
115137
path.set_extension("rhai");

0 commit comments

Comments
 (0)