aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorHenrik Tjäder <henrik@tjaders.com>2023-02-25 00:28:45 +0100
committerHenrik Tjäder <henrik@tjaders.com>2023-03-01 00:35:27 +0100
commit14457da4f831c57e7a2b1c54e1c37adb8354c8d5 (patch)
tree41ffb5d1aa2cd996ce451cb7a2525e3363dcb571 /xtask
parent8b3aa7f346f87a75c6fa2b5240edebe62b10a811 (diff)
xtask: Add book building
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/command.rs37
-rw-r--r--xtask/src/main.rs24
2 files changed, 54 insertions, 7 deletions
diff --git a/xtask/src/command.rs b/xtask/src/command.rs
index 4cf387f..e43c936 100644
--- a/xtask/src/command.rs
+++ b/xtask/src/command.rs
@@ -71,6 +71,9 @@ pub enum CargoCommand<'a> {
cargoarg: &'a Option<&'a str>,
features: Option<&'a str>,
},
+ Book {
+ mdbookarg: &'a Option<&'a str>,
+ },
ExampleSize {
cargoarg: &'a Option<&'a str>,
example: &'a str,
@@ -91,6 +94,24 @@ impl<'a> CargoCommand<'a> {
CargoCommand::Clippy { .. } => "clippy",
CargoCommand::Format { .. } => "fmt",
CargoCommand::Doc { .. } => "doc",
+ CargoCommand::Book { .. } => "build",
+ // TODO
+ // CargoCommand::Test { .. } => "test",
+ }
+ }
+ pub fn command(&self) -> &str {
+ match self {
+ CargoCommand::Run { .. }
+ | CargoCommand::Qemu { .. }
+ | CargoCommand::ExampleCheck { .. }
+ | CargoCommand::Check { .. }
+ | CargoCommand::ExampleBuild { .. }
+ | CargoCommand::Build { .. }
+ | CargoCommand::ExampleSize { .. }
+ | CargoCommand::Clippy { .. }
+ | CargoCommand::Format { .. }
+ | CargoCommand::Doc { .. } => "cargo",
+ CargoCommand::Book { .. } => "mdbook",
// TODO
// CargoCommand::Test { .. } => "test",
}
@@ -230,6 +251,18 @@ impl<'a> CargoCommand<'a> {
}
args
}
+ CargoCommand::Book { mdbookarg } => {
+ let mut args = vec![];
+
+ args.extend_from_slice(&[self.name()]);
+
+ if let Some(arg) = mdbookarg {
+ args.extend_from_slice(&[arg]);
+ }
+
+ args.extend_from_slice(&["book/en"]);
+ args
+ }
CargoCommand::Format {
cargoarg,
package,
@@ -324,10 +357,6 @@ impl<'a> CargoCommand<'a> {
}
}
}
-
- pub fn command(&self) -> &str {
- "cargo"
- }
}
impl BuildMode {
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 2c37f82..d881224 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -154,6 +154,9 @@ enum Commands {
/// Build docs
Doc,
+
+ /// Build books with mdbook
+ Book,
}
#[derive(Args, Debug)]
@@ -400,6 +403,10 @@ fn main() -> anyhow::Result<()> {
info!("Running cargo doc on backend: {backend:?}");
cargo_doc(&cargologlevel, backend)?;
}
+ Commands::Book => {
+ info!("Running mdbook build");
+ cargo_book(&cargologlevel)?;
+ }
}
Ok(())
@@ -534,6 +541,16 @@ fn cargo_doc(cargoarg: &Option<&str>, backend: Backends) -> anyhow::Result<()> {
Ok(())
}
+fn cargo_book(cargoarg: &Option<&str>) -> anyhow::Result<()> {
+ command_parser(
+ &CargoCommand::Book {
+ mdbookarg: cargoarg,
+ },
+ false,
+ )?;
+ Ok(())
+}
+
fn run_test(
cargoarg: &Option<&str>,
backend: Backends,
@@ -680,13 +697,14 @@ fn command_parser(command: &CargoCommand, overwrite: bool) -> anyhow::Result<()>
}
Ok(())
}
- CargoCommand::ExampleBuild { .. }
+ CargoCommand::Format { .. }
| CargoCommand::ExampleCheck { .. }
- | CargoCommand::Build { .. }
+ | CargoCommand::ExampleBuild { .. }
| CargoCommand::Check { .. }
+ | CargoCommand::Build { .. }
| CargoCommand::Clippy { .. }
| CargoCommand::Doc { .. }
- | CargoCommand::Format { .. }
+ | CargoCommand::Book { .. }
| CargoCommand::ExampleSize { .. } => {
let cargo_result = run_command(command)?;
if let Some(exit_code) = cargo_result.exit_status.code() {