Skip to content

Commit

Permalink
some more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Sep 27, 2023
1 parent 0546c22 commit 0dc939e
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 97 deletions.
4 changes: 4 additions & 0 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub fn add_args(cmd: Command) -> Command {
)
}

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

Expand Down
4 changes: 4 additions & 0 deletions bin/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub fn add_args(cmd: Command) -> Command {
)
}

/// Execute the dev command
///
/// # Errors
/// [`Error`] depending on the modules
pub fn execute(matches: &ArgMatches, launch_optionals: &[String]) -> Result<Context, Error> {
let all_optionals = matches.get_one::<bool>("optionals") == Some(&true);
let optionals = matches
Expand Down
8 changes: 6 additions & 2 deletions bin/src/commands/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub fn cli() -> Command {
}

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

let launch_config = matches
.get_one::<String>("config")
.expect("a config to be set");
.map_or_else(|| String::from("default"), std::string::ToString::to_string);
let launch = config
.hemtt()
.launch(launch_config)
.launch(&launch_config)
.ok_or(Error::LaunchConfigNotFound(launch_config.to_string()))?;

let Some(arma3dir) =
Expand Down
7 changes: 7 additions & 0 deletions bin/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub fn cli() -> Command {
)
}

/// Execute the new command
///
/// # Errors
/// [`Error`] depending on the modules
///
/// # Panics
/// If a name is not provided, but this is usually handled by clap
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
if !std::io::stdin().is_terminal() {
return Err(Error::NewNoInput);
Expand Down
4 changes: 4 additions & 0 deletions bin/src/commands/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub fn cli() -> Command {
)
}

/// Execute the release command
///
/// # Errors
/// [`Error`] depending on the modules
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
let ctx = Context::new(std::env::current_dir()?, "release")?;
let mut executor = Executor::new(&ctx);
Expand Down
7 changes: 7 additions & 0 deletions bin/src/commands/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ pub fn add_args(cmd: Command) -> Command {
)
}

/// Execute the script command
///
/// # Errors
/// [`Error`] depending on the modules
///
/// # Panics
/// If a name is not provided, but this is usually handled by clap
pub fn execute(matches: &ArgMatches) -> Result<(), Error> {
let all_optionals = matches.get_one::<bool>("optionals") == Some(&true);
let optionals = matches
Expand Down
2 changes: 1 addition & 1 deletion bin/src/config/project/version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{mem::MaybeUninit, path::Path};
use std::mem::MaybeUninit;

use git2::Repository;
use hemtt_common::version::Version;
Expand Down
12 changes: 11 additions & 1 deletion bin/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ pub struct Context {
}

impl Context {
/// Create a new context
///
/// # Errors
/// [`Error::ConfigNotFound`] if the project.toml is not found
/// [`Error::Io`] if the temporary folder fails to be created
/// [`Error::Git`] if the git hash is invalid
/// [`Error::Version`] if the version is invalid
///
/// # Panics
/// If the project folder is not a valid [`OsStr`] (UTF-8)
pub fn new(root: PathBuf, folder: &str) -> Result<Self, Error> {
let config = {
let path = root.join(".hemtt").join("project.toml");
Expand All @@ -42,7 +52,7 @@ impl Context {
.skip(2)
.collect::<PathBuf>()
.to_str()
.unwrap()
.expect("valid utf-8")
.replace(['\\', '/'], "_"),
);
trace!("using temporary folder: {:?}", tmp.display());
Expand Down
10 changes: 10 additions & 0 deletions bin/src/modules/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use std::fs::create_dir_all;

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

/// Creates the release zips
///
/// # Errors
/// [`Error`] depending on the modules
/// [`Error::Zip`] if the zip fails to create
/// [`Error::Io`] if the zip fails to write
/// [`Error::Version`] if the version is invalid
///
/// # Panics
/// If we are somehow not in the HEMTT folder
pub fn release(ctx: &Context) -> Result<(), Error> {
let output = ctx.project_folder().join("releases");
trace!("using releases folder: {:?}", output.display());
Expand Down
22 changes: 22 additions & 0 deletions bin/src/modules/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use super::Module;
mod libraries;
mod time;

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

impl Hooks {
/// Run a folder of hooks
///
/// # Errors
/// [`Error::ScriptNotFound`] if the script does not exist
/// [`Error::HookFatal`] if the script calls `fatal`
/// [`Error::Rhai`] if the script is invalid
///
/// # Panics
/// If a file path is not a valid [`OsStr`] (UTF-8)
pub fn run_folder(self, ctx: &Context, name: &str, vfs: bool) -> Result<(), Error> {
if !self.0 {
return Ok(());
Expand Down Expand Up @@ -110,6 +123,15 @@ impl Hooks {
Ok(())
}

/// Run a script
///
/// # Errors
/// [`Error::ScriptNotFound`] if the script does not exist
/// [`Error::HookFatal`] if the script calls `fatal`
/// [`Error::Rhai`] if the script is invalid
///
/// # Panics
/// If a file path is not a valid [`OsStr`] (UTF-8)
pub fn run_file(ctx: &Context, name: &str) -> Result<(), Error> {
let mut path = ctx.hemtt_folder().join("scripts").join(name);
path.set_extension("rhai");
Expand Down
4 changes: 4 additions & 0 deletions bin/src/modules/new/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub struct Licenses;

impl Licenses {
#[must_use]
/// Has the user select a license
///
/// # Panics
/// If there is a problem with dialoguer
pub fn select(author: &str) -> Option<String> {
let licenses = vec![
"Arma Public License Share Alike (APL-SA)",
Expand Down
8 changes: 8 additions & 0 deletions bin/src/modules/pbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub enum Collapse {
No,
}

/// Builds the PBOs
///
/// # Errors
/// [`Error`] depending on the modules
/// [`Error::Io`] if the PBO fails to write
/// [`Error::Version`] if the version is invalid
/// [`Error::Git`] if the git hash is invalid
/// [`Error::Pbo`] if the PBO fails to write
pub fn build(ctx: &Context, collapse: Collapse) -> Result<(), Error> {
let version = ctx.config().version().get(ctx.workspace().vfs())?;
let git_hash = {
Expand Down
Loading

0 comments on commit 0dc939e

Please sign in to comment.