initial commit
This commit is contained in:
parent
212a05d71a
commit
e1427912f5
80 changed files with 8684 additions and 0 deletions
8
xtask/Cargo.toml
Normal file
8
xtask/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "xtask"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
linutil_core = { path = "../core" }
|
60
xtask/src/docgen.rs
Normal file
60
xtask/src/docgen.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use std::fs;
|
||||
|
||||
use linutil_core::Command;
|
||||
|
||||
use crate::path;
|
||||
use crate::DynError;
|
||||
|
||||
pub const USER_GUIDE: &str = "userguide.md";
|
||||
|
||||
pub fn userguide() -> Result<String, DynError> {
|
||||
let mut md = String::new();
|
||||
md.push_str("<!-- THIS FILE IS GENERATED BY cargo xtask docgen -->\n# Walkthrough\n");
|
||||
|
||||
let tabs = linutil_core::get_tabs(false).1;
|
||||
|
||||
for tab in tabs {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("Tab: {}", tab.name);
|
||||
|
||||
md.push_str(&format!("\n## {}\n\n", tab.name));
|
||||
|
||||
for entry in tab.tree {
|
||||
if entry.command == Command::None {
|
||||
#[cfg(debug_assertions)]
|
||||
println!(" Directory: {}", entry.name);
|
||||
|
||||
if entry.name != "root".to_string() {
|
||||
md.push_str(&format!("\n### {}\n\n", entry.name));
|
||||
}
|
||||
|
||||
/* let current_dir = &entry.name;
|
||||
|
||||
if *current_dir != "root".to_string() {
|
||||
md.push_str(&format!(
|
||||
"\n<details><summary>{}</summary>\n\n",
|
||||
current_dir
|
||||
));
|
||||
} */ // Commenting this for now, might be a good idea later
|
||||
} else {
|
||||
if !entry.description.is_empty() {
|
||||
#[cfg(debug_assertions)]
|
||||
println!(" Entry: {}", entry.name);
|
||||
#[cfg(debug_assertions)]
|
||||
println!(" Description: {}", entry.description);
|
||||
|
||||
md.push_str(&format!("- **{}**: {}\n", entry.name, entry.description));
|
||||
} /* else {
|
||||
md.push_str(&format!("- **{}**\n", entry.name));
|
||||
} */ // https://github.com/ChrisTitusTech/linutil/pull/753
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(md)
|
||||
}
|
||||
|
||||
pub fn write(file: &str, data: &str) {
|
||||
let path = path::docs().join(file);
|
||||
fs::write(path, data).unwrap_or_else(|_| panic!("Could not write to {}", file));
|
||||
}
|
40
xtask/src/main.rs
Normal file
40
xtask/src/main.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
mod docgen;
|
||||
mod path;
|
||||
|
||||
use std::{env, error::Error};
|
||||
|
||||
type DynError = Box<dyn Error>;
|
||||
|
||||
pub mod tasks {
|
||||
use crate::docgen::USER_GUIDE;
|
||||
use crate::docgen::{userguide, write};
|
||||
use crate::DynError;
|
||||
|
||||
pub fn docgen() -> Result<(), DynError> {
|
||||
write(USER_GUIDE, &userguide()?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_help() {
|
||||
println!(
|
||||
"
|
||||
Usage: `cargo xtask <task>`
|
||||
|
||||
Tasks:
|
||||
docgen: Generate Markdown files.
|
||||
"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), DynError> {
|
||||
let task = env::args().nth(1);
|
||||
match task {
|
||||
None => tasks::print_help(),
|
||||
Some(t) => match t.as_str() {
|
||||
"docgen" => tasks::docgen()?,
|
||||
invalid => return Err(format!("Invalid task: {}", invalid).into()),
|
||||
},
|
||||
};
|
||||
Ok(())
|
||||
}
|
12
xtask/src/path.rs
Normal file
12
xtask/src/path.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn project_root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
pub fn docs() -> PathBuf {
|
||||
project_root().join("docs/")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue