Start noodling on cheat sheet

This commit is contained in:
Casey Rodarmor 2025-03-24 23:49:13 -07:00
parent b14a7b5098
commit cab096d773
7 changed files with 219 additions and 0 deletions

85
Cargo.lock generated
View file

@ -133,6 +133,20 @@ dependencies = [
"generic-array",
]
[[package]]
name = "boilerplate"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff9f82b3395618a18fdb7b586fe5cfac0c07af07d0aab300ff3dd64e4f3ec949"
dependencies = [
"darling",
"mime",
"new_mime_guess",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "bstr"
version = "1.11.3"
@ -323,6 +337,41 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "darling"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "derive-where"
version = "1.2.7"
@ -438,6 +487,12 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "generate-book"
version = "0.0.0"
@ -500,6 +555,12 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "html-escaper"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "459a0ca33ee92551e0a3bb1774f2d3bdd1c09fb6341845736662dd25e1fcb52a"
[[package]]
name = "iana-time-zone"
version = "0.1.61"
@ -523,6 +584,12 @@ dependencies = [
"cc",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "is_executable"
version = "1.0.4"
@ -560,6 +627,7 @@ version = "1.40.0"
dependencies = [
"ansi_term",
"blake3",
"boilerplate",
"camino",
"chrono",
"clap",
@ -572,6 +640,7 @@ dependencies = [
"edit-distance",
"executable-path",
"heck",
"html-escaper",
"is_executable",
"lexiclean",
"libc",
@ -655,6 +724,22 @@ dependencies = [
"libc",
]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "new_mime_guess"
version = "4.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02a2dfb3559d53e90b709376af1c379462f7fb3085a0177deb73e6ea0d99eff4"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "nix"
version = "0.29.0"

View file

@ -20,6 +20,7 @@ members = [".", "crates/*"]
[dependencies]
ansi_term = "0.12.0"
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
boilerplate = "1.0.1"
camino = "1.0.4"
chrono = "0.4.38"
clap = { version = "4.0.0", features = ["derive", "env", "wrap_help"] }
@ -31,6 +32,7 @@ dirs = "6.0.0"
dotenvy = "0.15"
edit-distance = "2.0.0"
heck = "0.5.0"
html-escaper = "0.2.0"
is_executable = "1.0.4"
lexiclean = "0.0.1"
libc = "0.2.0"

80
sheet.just Normal file
View file

@ -0,0 +1,80 @@
foo:
echo hello
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye
#
bar:
echo goodbye

View file

@ -58,6 +58,7 @@ mod cmd {
pub(crate) const LIST: &str = "LIST";
pub(crate) const MAN: &str = "MAN";
pub(crate) const REQUEST: &str = "REQUEST";
pub(crate) const SHEET: &str = "SHEET";
pub(crate) const SHOW: &str = "SHOW";
pub(crate) const SUMMARY: &str = "SUMMARY";
pub(crate) const VARIABLES: &str = "VARIABLES";
@ -548,6 +549,13 @@ impl Config {
)
.help_heading(cmd::REQUEST),
)
.arg(
Arg::new(cmd::SHEET)
.long("sheet")
.action(ArgAction::SetTrue)
.help("Print HTML cheet sheet")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::SHOW)
.short('s')
@ -732,6 +740,8 @@ impl Config {
request: serde_json::from_str(request)
.map_err(|source| ConfigError::RequestParse { source })?,
}
} else if matches.get_flag(cmd::SHEET) {
Subcommand::Sheet
} else if let Some(path) = matches.get_many::<String>(cmd::SHOW) {
Subcommand::Show {
path: Self::parse_module_path(path)?,

View file

@ -102,6 +102,7 @@ pub(crate) use {
clap::ValueEnum,
derive_where::derive_where,
edit_distance::edit_distance,
html_escaper::Escape,
lexiclean::Lexiclean,
libc::EXIT_FAILURE,
once_cell::sync::Lazy,

View file

@ -2,6 +2,11 @@ use {super::*, clap_mangen::Man};
const INIT_JUSTFILE: &str = "default:\n echo 'Hello, world!'\n";
#[derive(boilerplate::Boilerplate)]
struct SheetHtml {
examples: Vec<&'static str>,
}
fn backtick_re() -> &'static Regex {
static BACKTICK_RE: OnceLock<Regex> = OnceLock::new();
BACKTICK_RE.get_or_init(|| Regex::new("(`.*?`)|(`[^`]*$)").unwrap())
@ -42,6 +47,7 @@ pub(crate) enum Subcommand {
arguments: Vec<String>,
overrides: BTreeMap<String, String>,
},
Sheet,
Show {
path: ModulePath,
},
@ -89,6 +95,7 @@ impl Subcommand {
arguments,
overrides,
} => Self::run(config, loader, search, compilation, arguments, overrides)?,
Sheet => Self::sheet()?,
Show { path } => Self::show(config, justfile, path)?,
Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile),
@ -693,6 +700,20 @@ impl Subcommand {
}
}
fn sheet() -> RunResult<'static> {
println!(
"{}",
SheetHtml {
examples: include_str!("../sheet.just")
.split("\n#\n")
.map(|example| example.trim())
.collect(),
}
);
Ok(())
}
fn show<'src>(
config: &Config,
mut module: &Justfile<'src>,

20
templates/sheet.html Normal file
View file

@ -0,0 +1,20 @@
<!doctype html>
<html lang=en>
<head>
<meta name=format-detection content='telephone=no'>
<title>Just Cheat Sheet</title>
<style>
main {
columns: 3;
}
</style>
</head>
<body>
<h1>Just Cheat Sheet</h1>
<main>
%% for example in &self.examples {
<pre><code>{{example}}</code></pre>
%% }
</main>
</body>
</html>