Skip to content

Commit e7634fc

Browse files
Document all public items of the CLI (#388)
It got discussed in the [CLI working-group ](https://discord.com/channels/691052431525675048/1278871953721262090/1364297693182300312) that the Bevy editor also uses the CLI as a library. To make it easier for them, we should "stabilize" our public interface for `0.1.0` and add some short comments on the public types. --------- Co-authored-by: TimJentzsch <[email protected]>
1 parent 5cc3047 commit e7634fc

File tree

10 files changed

+43
-9
lines changed

10 files changed

+43
-9
lines changed

src/bin/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ pub struct Cli {
5454
/// Available subcommands for the Bevy CLI.
5555
#[command(subcommand)]
5656
pub subcommand: Subcommands,
57+
/// Use verbose output.
58+
///
59+
/// Logs commands that are executed and more information on the actions being performed.
5760
#[arg(long, short = 'v', global = true)]
5861
pub verbose: bool,
5962
}

src/build/args.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
},
99
};
1010

11+
/// Arguments for building a Bevy project.
1112
#[derive(Debug, Args)]
1213
pub struct BuildArgs {
1314
/// The subcommands available for the build command.
@@ -94,13 +95,15 @@ impl BuildArgs {
9495
}
9596
}
9697

98+
/// The subcommands available for the build command.
9799
#[derive(Debug, Subcommand)]
98100
pub enum BuildSubcommands {
99101
/// Build your app for the browser.
100102
#[cfg(feature = "web")]
101103
Web(BuildWebArgs),
102104
}
103105

106+
/// Additional Arguments for building a Bevy web project.
104107
#[derive(Debug, Args)]
105108
pub struct BuildWebArgs {
106109
// Bundle all web artifacts into a single folder.

src/build/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Provides functionalities to build a Bevy app targeting either native or web platforms.
2+
13
use args::BuildArgs;
24

35
#[cfg(feature = "web")]
@@ -6,6 +8,11 @@ use crate::{bin_target::select_run_binary, config::CliConfig, external_cli::carg
68

79
pub mod args;
810

11+
/// Tries to build the project with the given [`BuildArgs`].
12+
///
13+
/// # Errors
14+
///
15+
/// will error if the build process can not be completed
916
pub fn build(args: &mut BuildArgs) -> anyhow::Result<()> {
1017
let metadata = cargo::metadata::metadata()?;
1118

src/config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Configuration used by the `bevy_cli`, defined in `Cargo.toml` under `package.metadata.bevy_cli`.
12
use std::fmt::Display;
23

34
use anyhow::{Context, bail};
@@ -6,6 +7,13 @@ use serde_json::{Map, Value};
67

78
use crate::external_cli::cargo::metadata::{Metadata, Package};
89

10+
/// Configuration for the `bevy_cli`.
11+
///
12+
/// Allows customizing:
13+
/// - Target platform
14+
/// - Enabled features
15+
/// - Whether to enable default features
16+
/// - Additional Rust compiler flags
917
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
1018
pub struct CliConfig {
1119
/// The platform to target with the build.

src/external_cli/arg_builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl ArgBuilder {
1313
///
1414
/// # Example
1515
///
16-
/// ```
16+
/// ```ignore
1717
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
1818
/// ArgBuilder::new().arg("--release");
1919
/// ```
@@ -29,7 +29,7 @@ impl ArgBuilder {
2929
///
3030
/// # Example
3131
///
32-
/// ```
32+
/// ```ignore
3333
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
3434
/// ArgBuilder::new().add_with_value("--bin", "bevy");
3535
/// ```
@@ -45,7 +45,7 @@ impl ArgBuilder {
4545
///
4646
/// # Example
4747
///
48-
/// ```
48+
/// ```ignore
4949
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
5050
/// let is_release = true;
5151
/// ArgBuilder::new().add_flag_if("--release", is_release);
@@ -63,7 +63,7 @@ impl ArgBuilder {
6363
///
6464
/// # Example
6565
///
66-
/// ```
66+
/// ```ignore
6767
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
6868
/// let maybe_name = Some("bevy");
6969
/// ArgBuilder::new().add_opt_value("--bin", &maybe_name);
@@ -84,7 +84,7 @@ impl ArgBuilder {
8484
///
8585
/// # Example
8686
///
87-
/// ```
87+
/// ```ignore
8888
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
8989
/// let features = ["dev", "file_watcher"];
9090
/// ArgBuilder::new().add_value_list("--features", features);
@@ -108,7 +108,7 @@ impl ArgBuilder {
108108
///
109109
/// # Example
110110
///
111-
/// ```
111+
/// ```ignore
112112
/// # use bevy_cli::external_cli::arg_builder::ArgBuilder;
113113
/// let features = ["dev", "file_watcher"];
114114
/// ArgBuilder::new().add_values_separately("--features", features);

src/external_cli/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cargo::install::AutoInstall;
1010
use semver::VersionReq;
1111
use tracing::{Level, debug, error, info, trace, warn};
1212

13-
pub mod arg_builder;
13+
pub(crate) mod arg_builder;
1414
pub(crate) mod cargo;
1515
#[cfg(feature = "rustup")]
1616
pub(crate) mod rustup;
@@ -53,6 +53,7 @@ impl CommandExt {
5353
///
5454
/// If the command fails and the package is missing,
5555
/// it can be installed automatically via `cargo install`.
56+
#[cfg(feature = "web")]
5657
pub fn require_package<S: AsRef<OsStr>>(&mut self, name: S, version: VersionReq) -> &mut Self {
5758
self.package = Some(Package {
5859
name: name.as_ref().to_owned(),
@@ -65,6 +66,7 @@ impl CommandExt {
6566
///
6667
/// If the command fails and the target is missing,
6768
/// it can be installed automatically via `rustup`.
69+
#[cfg(feature = "web")]
6870
pub fn maybe_require_target<S: AsRef<OsStr>>(&mut self, target: Option<S>) -> &mut Self {
6971
if let Some(target) = target {
7072
self.target = Some(target.as_ref().to_owned());

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
pub(crate) mod bin_target;
44
pub mod build;
5-
pub mod config;
6-
pub mod external_cli;
5+
pub(crate) mod config;
6+
pub(crate) mod external_cli;
77
pub mod lint;
88
pub mod run;
99
pub mod template;

src/lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helper functions to run `bevy_lint`.
2+
13
use anyhow::{Context, anyhow, ensure};
24
use std::{env, path::PathBuf};
35

src/run/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Provides functionalities to run a Bevy app targeting either native or web platforms.
2+
13
#[cfg(feature = "web")]
24
use crate::web::run::run_web;
35
use crate::{bin_target::select_run_binary, config::CliConfig, external_cli::cargo};
@@ -6,6 +8,11 @@ pub use self::args::RunArgs;
68

79
pub mod args;
810

11+
/// Tries to run the project with the given [`RunArgs`].
12+
///
13+
/// # Errors
14+
///
15+
/// will error if the build process can not be completed
916
pub fn run(args: &mut RunArgs) -> anyhow::Result<()> {
1017
let metadata = cargo::metadata::metadata()?;
1118

src/template.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilities to create a new Bevy project with `cargo-generate`
2+
13
use cargo_generate::{GenerateArgs, TemplatePath};
24
use regex::Regex;
35
use reqwest::blocking::Client;

0 commit comments

Comments
 (0)