feat(cli): wanderbooks licenses prints the notices compiled into the program

The notices must reach the person holding the binary, not only the
repository: THIRD-PARTY-NOTICES.txt is compiled in with include_str!,
so `wanderbooks licenses` prints the program's version line and then
every crate's and font's licence without opening books or reading a
file. A closed pipe (`| head`) is ignored, not a panic.

Tests check the version line, the notices required in the output, that
the bytes after the header are exactly the repository's file, and that
the mode takes no arguments and must come first like every other.

Docs: the testing table says what `just notices` writes and how
`notices-check` fails on a stale file; the architecture's list of modes
names licenses.

Co-Authored-By: DeepSeek V4.1 Flash
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-09 21:17:56 -07:00
1 parent 7f87ccd3d3
commit 9baf71b2a5
4 files changed
+128 -11

No files matched your search

+51 -10
View File
@@ -11,8 +11,14 @@
//! agent).
use std::env;
use std::io::Write;
use std::path::PathBuf;
/// Every third-party licence the program must travel with, built into it
/// by the build (`just notices`; scripts/notices.sh). `wanderbooks
/// licenses` prints it.
const NOTICES: &str = include_str!("../../../THIRD-PARTY-NOTICES.txt");
fn print_usage() {
eprintln!("usage: wanderbooks setup [--root PATH] [--home DIR]");
eprintln!(" wanderbooks gui [BOOK | --root PATH --book ID]");
@@ -29,6 +35,7 @@ fn print_usage() {
eprintln!(" wanderbooks download --book ID [--token NAME] ATTACHMENT --to FOLDER");
eprintln!(" wanderbooks serve | close | doctor");
eprintln!(" wanderbooks update [--check] | rollback");
eprintln!(" wanderbooks licenses");
eprintln!();
eprintln!(" setup make the books' private folder (only your account can open it)");
eprintln!(" gui open the live, read-only view of the books (a book of the data root)");
@@ -45,6 +52,7 @@ fn print_usage() {
eprintln!(" close close the books now: everything holding them lets go");
eprintln!(" doctor whether the books are open, what holds them, what went wrong");
eprintln!(" update bring this program to the newest release (`rollback` goes back)");
eprintln!(" licenses the licences of the libraries and fonts this program includes");
}
/// The viewer's arguments for `wanderbooks gui ARGS` (plan 3.6): a lone
@@ -381,6 +389,25 @@ fn run_server(args: Vec<String>) -> i32 {
}
}
/// `wanderbooks licenses`: the third-party notices compiled into the
/// program. It opens no books and reads no file: what it prints is part of
/// this binary. A pipe that closes early (`| head`) is how the reader
/// finished, not an error, so a write error is ignored.
fn run_licenses(args: Vec<String>) -> i32 {
if !args.is_empty() {
eprintln!("usage: wanderbooks licenses");
return 2;
}
let mut out = std::io::stdout().lock();
let header = format!(
"wanderbooks {} is licensed under MIT OR Apache-2.0.\n\n",
env!("CARGO_PKG_VERSION")
);
let _ = out.write_all(header.as_bytes());
let _ = out.write_all(NOTICES.as_bytes());
0
}
/// The modes that open and hold the books (plan 3.9): the host, the
/// agents' bridge, and the owner's commands.
fn run_local(mode: &str, args: Vec<String>) -> i32 {
@@ -478,6 +505,7 @@ fn main() {
Some("gui") => std::process::exit(run_gui(all.collect())),
Some("setup") => std::process::exit(run_setup(all.collect())),
Some("server") => std::process::exit(run_server(all.collect())),
Some("licenses") => std::process::exit(run_licenses(all.collect())),
Some(
mode @ ("host" | "mcp" | "serve" | "close" | "books" | "doctor" | "token" | "connect"
| "passphrase" | "update" | "rollback"),
@@ -499,16 +527,29 @@ fn main() {
std::process::exit(2);
}
// A mode named after a flag: it must come first.
match words
.iter()
.map(String::as_str)
.find(|w| !w.starts_with('-'))
{
Some(
mode @ ("gui" | "setup" | "server" | "host" | "mcp" | "serve" | "connect" | "close"
| "books" | "doctor" | "token" | "passphrase" | "update" | "rollback"
| "upload" | "download"),
) => {
match words.iter().map(String::as_str).find(|w| {
matches!(
*w,
"gui"
| "setup"
| "server"
| "host"
| "mcp"
| "serve"
| "connect"
| "close"
| "books"
| "doctor"
| "token"
| "passphrase"
| "update"
| "rollback"
| "upload"
| "download"
| "licenses"
)
}) {
Some(mode) => {
eprintln!("`{mode}` must come first: wanderbooks {mode} [its own flags]");
std::process::exit(2);
}