gd_cli ====== .. rust:crate:: gd_cli :synopsis: The guidedog command line as a library: it reads a command line, does what it asks, reports on standard error, and returns the exit status. cmd/guidedog is a call to run; a program with plugins linked in calls run_with with its registry. The ``guidedog`` command line as a library: it reads a command line, does what it asks, reports on standard error, and returns the exit status. ``cmd/guidedog`` is a call to :rust:fn:`run `; a program with plugins linked in calls :rust:fn:`run_with ` with its registry. .. code-block:: rust fn main() -> std::process::ExitCode { let linked = gd_plugins::Registry::new(Vec::new()).unwrap_or_default(); gd_cli::run_with(linked) } The staged path: :rust:fn:`parse_command ` turns words into a typed :rust:enum:`Command ` (plain data, checked, with Elm-style usage problems), and :rust:fn:`run_in ` runs one command line with the streams given, which is how tests capture what a command prints. Exit statuses: 0 success, 1 invalid content or a failed build, 2 usage or configuration, 3 limits and memory, 4 files and programs, 5 internal, 6 and 7 for publications not confirmed or unknown, 130 cancelled. .. rubric:: Structs .. rust:struct:: pub struct MigrateCommand ``guidedog migrate [conf.py|DIR]``. .. rubric:: Fields .. rust:field:: pub input: PathBuf The conf.py, or the folder holding it. .. rust:field:: pub output: MigrateOutput ``-o``. .. rust:field:: pub force: bool ``--force``: replace an existing conf.toml. .. rust:struct:: pub struct BuildCommand ``guidedog build``: what to load, what to build, and how. .. rubric:: Fields .. rust:field:: pub dir: PathBuf The project folder (the sphinx-build forms: the source folder). .. rust:field:: pub kind: BuilderKind The builder. .. rust:field:: pub load: LoadOptions ``-c``, ``-C``, ``-D``, and the sphinx-build forms' folders. .. rust:field:: pub options: BuildOptions ``-a``, ``-E``, ``-n``, ``-W``, ``--keep-going``, ``--untrusted``, ``-j``, ``-t``, the limits, the budget, and the output folder of the sphinx-build forms. ``on_budget`` and ``now`` are set when the build runs. .. rust:field:: pub memory: MemoryMode ``--memory``. .. rust:field:: pub verbose: u32 ``-v``, repeatable: show notes too. .. rust:field:: pub typst: Option ``--typst``: overrides ``typst`` in conf.toml. .. rust:field:: pub peak_memory_file: Option ``--peak-memory-file``: where to write the process's peak memory in bytes when the build ends (GDS 0020). .. rust:struct:: pub struct CleanCommand ``guidedog clean [PROJECT]``. .. rubric:: Fields .. rust:field:: pub dir: PathBuf The project folder. .. rust:struct:: pub struct ConvertCommand ``guidedog convert INPUT``: one file to HTML or PDF, without a project. The formats are resolved from the options and the file suffixes while parsing. .. rubric:: Fields .. rust:field:: pub input: String The input path, or ``-`` for standard input. .. rust:field:: pub output: String The output path, or ``-`` for standard output. .. rust:field:: pub from: Format The input's markup. .. rust:field:: pub to: Target The artifact to write. .. rust:field:: pub emit_typst: Option ``--emit-typst``: where to write the generated Typst too. .. rust:field:: pub force: bool ``--force``: replace an existing output. .. rust:field:: pub raw: ContentPolicy ``--raw``: what happens to raw HTML or Typst content. .. rust:field:: pub strict: bool ``--strict``: warnings fail the conversion. .. rust:field:: pub title: String ``--title``. .. rust:field:: pub lang: String ``--lang``. .. rust:field:: pub fragment: bool ``--fragment``: the body only. .. rust:field:: pub number_sections: bool ``--number-sections``. .. rust:field:: pub math: MathOutput ``--math``: how HTML shows formulas. .. rust:field:: pub embed_pictures: bool ``--embed-pictures``: draw graphs, Typst diagrams and scores into the HTML. .. rust:field:: pub max_pictures: Option ``--max-pictures``: how many pictures ``--embed-pictures`` embeds. .. rust:field:: pub max_picture_kib: Option ``--max-picture-kib``: the size of all embedded pictures together, in KiB. .. rust:field:: pub keep_going: bool ``--keep-going``: write the output although the content has errors. .. rust:field:: pub typst: String ``--typst``: the Typst program, ``typst`` for the embedded compiler. .. rust:field:: pub font_paths: Vec ``--font-path``, repeatable. .. rust:field:: pub package_cache: Option ``--package-cache``. .. rust:field:: pub offline: bool ``--offline``. .. rust:field:: pub embedded_fonts_only: bool ``--embedded-fonts-only``. .. rust:field:: pub budget_mib: Option ``--budget``, in MiB. .. rust:field:: pub max_depth: Option ``--max-depth``. .. rust:field:: pub max_nodes: Option ``--max-nodes``. .. rust:field:: pub stack_kib: Option ``--stack-kib``. .. rust:struct:: pub struct CapabilitiesCommand ``guidedog capabilities``. .. rubric:: Fields .. rust:field:: pub json: bool ``--json`` or ``--format=json`` instead of the summary. .. rust:field:: pub project: Option The project whose configuration decides what is enabled; ``None`` reports a project without configuration. .. rust:struct:: pub struct FormatsCommand ``guidedog formats``. .. rubric:: Fields .. rust:field:: pub json: bool ``--format=json`` instead of the table. .. rust:field:: pub typst: String ``--typst``: the Typst program to describe. .. rust:struct:: pub struct IntlCommand ``guidedog intl update|stat [PROJECT]``, with sphinx-intl's options. .. rubric:: Fields .. rust:field:: pub action: IntlAction update or stat. .. rust:field:: pub dir: PathBuf The project folder. .. rust:field:: pub load: LoadOptions ``-c`` and ``-D``. .. rust:field:: pub languages: Vec ``-l``, repeatable. .. rust:field:: pub pot_dir: Option ``-p``: the templates; ``None`` for ``_build/gettext``. .. rust:field:: pub locale_dir: Option ``-d``: the catalogs; ``None`` for the first of ``locale_dirs``. .. rust:field:: pub line_width: usize ``-w`` (default 76). .. rust:field:: pub obsolete: bool Keep messages the templates no longer have (``--no-obsolete`` clears it). .. rust:struct:: pub struct ExtensionCommand A command a plugin adds, as a command line names it. .. rubric:: Fields .. rust:field:: pub extension: crate::Extension The command and the plugin that contributes it. .. rust:field:: pub args: Vec The command line without the command's words, for the plugin to read. .. rust:field:: pub help: bool ``--help`` or ``-h`` was given (before ``--``): guidedog shows the command's help. .. rust:struct:: pub struct QuickstartCommand ``guidedog quickstart [DIR]``: the answers given as options; a terminal asks for the rest unless ``quiet``. .. rubric:: Fields .. rust:field:: pub dir: PathBuf Where to create the project. .. rust:field:: pub quiet: bool ``-q``: ask nothing. .. rust:field:: pub project: String ``-p``. .. rust:field:: pub author: String ``-a``. .. rust:field:: pub version: String ``-v``: the short version; the release when empty. .. rust:field:: pub release: String ``-r``. .. rust:field:: pub language: String ``-l``; empty for ``en`` (or the answer). .. rust:field:: pub suffix: String ``--suffix``; empty for ``.rst``. .. rust:field:: pub separate: Option ``--sep`` (``Some(true)``) or ``--no-sep`` (``Some(false)``); ``None`` asks. .. rust:struct:: pub struct ServeCommand ``guidedog serve``: the HTML build it repeats, and the listen address. .. rubric:: Fields .. rust:field:: pub build: BuildCommand The build to run first and on every change (always ``html``). .. rust:field:: pub host: std::net::IpAddr ``--host`` (default 127.0.0.1). .. rust:field:: pub port: u16 ``--port`` (default 8000). .. rust:struct:: pub struct Output How the command reports, whatever it runs: ``--color``, ``--diagnostics``, ``-q``. .. rubric:: Fields .. rust:field:: pub color: ColorMode ``--color``. .. rust:field:: pub diagnostics: Diagnostics ``--diagnostics``. .. rust:field:: pub quiet: bool ``-q``: no success messages; warnings and errors still show. .. rust:struct:: pub struct Parsed A parsed command line: how to report, and the command, or the usage problem that stopped parsing (reported as ``output`` asks). .. rubric:: Fields .. rust:field:: pub output: Output How to report. .. rust:field:: pub command: Result The command to run, or why the command line is not one. .. rust:struct:: pub struct PluginCommand ``guidedog plugin ...``. .. rubric:: Fields .. rust:field:: pub action: PluginAction The subcommand. .. rust:field:: pub project: Option ``--project``: the project the checks use (default: the current folder). .. rust:field:: pub config: Option ``--config``: the plugin's configuration, relative to the project. .. rust:field:: pub timeout: Option ``--timeout``, in seconds (default 60). .. rust:field:: pub yes: bool ``--yes``: register without asking. .. rust:struct:: pub struct PublishCommand ``guidedog publish --publisher=ID --config=FILE``. .. rubric:: Fields .. rust:field:: pub publisher: String ``--publisher``. .. rust:field:: pub config: String ``--config``. .. rust:field:: pub dry_run: bool ``--dry-run``: build and plan, publish nothing. .. rust:field:: pub wait: Option ``--wait``, in seconds; ``None`` for the publisher's default. .. rust:field:: pub timeout: Option ``--timeout``, in seconds; ``None`` for 300. .. rust:field:: pub verbose: bool ``--verbose``: list every change of the plan. .. rust:struct:: pub struct Streams<'a> The streams a command line runs with, borrowed for the run. .. rubric:: Fields .. rust:field:: pub out: &'a mut dyn Write Results: tables, converted output, success messages. .. rust:field:: pub err: &'a mut dyn Write Reports, problems, progress, and questions. .. rust:field:: pub input: &'a mut dyn BufRead Answers to questions, one per line. .. rust:field:: pub terminals: Terminals Which streams are terminals. .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Debug for Streams<'_> :noindex: :for: Streams<'_> :trait: std::fmt::Debug .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rust:struct:: pub struct Terminals Whether each standard stream is a terminal: colors (``--color=auto``) and questions (only a person at a terminal is asked) depend on it. .. rubric:: Fields .. rust:field:: pub stdin: bool Standard input is a terminal. .. rust:field:: pub stdout: bool Standard output is a terminal. .. rust:field:: pub stderr: bool Standard error is a terminal. .. rubric:: Implementations .. rust:impl:: impl Terminals :noindex: :for: Terminals .. rust:method:: pub fn detect() -> Terminals The process's own streams. .. rust:struct:: pub struct Extension A command a plugin adds to guidedog's command line, and the plugin that runs it. .. rubric:: Fields .. rust:field:: pub plugin: String The ID of the plugin that contributes it. .. rust:field:: pub info: CommandInfo Its name, summary, help and options, as the plugin declares them. .. rust:field:: pub linked: bool The plugin is linked into this program (not a registered program). .. rubric:: Implementations .. rust:impl:: impl Extension :noindex: :for: Extension .. rust:method:: pub fn name(&self) -> String The command's name, such as ``pages workflow``. .. rubric:: Enums .. rust:enum:: pub enum ColorMode When the command styles its output with colors. .. rubric:: Variants .. rust:variant:: Auto Only on a terminal, unless ``NO_COLOR`` is set or ``TERM`` is ``dumb``. .. rust:variant:: Always Always. .. rust:variant:: Never Never. .. rust:enum:: pub enum Command What a command line asks for. .. rubric:: Variants .. rust:variant:: Help(Option<&'static str>) Show help: the overview (``None``) or a command's. .. rust:variant:: Version { typst: String } ``--version``, with the Typst program to describe. .. rust:field:: typst: String ``--typst``. .. rust:variant:: Licenses ``--licenses``. .. rust:variant:: Formats(FormatsCommand) ``formats``. .. rust:variant:: Capabilities(CapabilitiesCommand) ``capabilities``. .. rust:variant:: Convert(Box) ``convert``. .. rust:variant:: Quickstart(QuickstartCommand) ``quickstart``. .. rust:variant:: Build(Box) ``build`` (and the sphinx-build forms). .. rust:variant:: Serve(Box) ``serve``. .. rust:variant:: Clean(CleanCommand) ``clean``. .. rust:variant:: Migrate(MigrateCommand) ``migrate``. .. rust:variant:: Intl(IntlCommand) ``intl update`` and ``intl stat``. .. rust:variant:: Plugin(PluginCommand) ``plugin ...``. .. rust:variant:: Publish(PublishCommand) ``publish --publisher=ID``. .. rust:variant:: Extension(ExtensionCommand) A command a plugin adds, such as ``pages workflow`` or ``publish pages``. .. rust:variant:: ExtensionHelp(String) ``WORD --help``, where WORD begins only commands plugins add: their list. .. rust:enum:: pub enum Diagnostics How problems and reports are written on standard error. .. rubric:: Variants .. rust:variant:: Text Explained, Elm-style reports. .. rust:variant:: Json One JSON object per report. .. rust:enum:: pub enum IntlAction The two ``intl`` commands. .. rubric:: Variants .. rust:variant:: Update Create or merge the catalogs from the templates. .. rust:variant:: Stat Count what is translated. .. rust:enum:: pub enum MemoryMode What a build does when it reaches its memory budget. .. rubric:: Variants .. rust:variant:: Ask A terminal asks (raise the budget, or stop); elsewhere the build stops. .. rust:variant:: Stop ``--memory=ram``: stop at the budget without asking. .. rust:enum:: pub enum MigrateOutput Where ``migrate`` writes conf.toml. .. rubric:: Variants .. rust:variant:: Beside Beside the conf.py. .. rust:variant:: File(PathBuf) ``-o FILE``. .. rust:variant:: Stdout ``-o -``: standard output. .. rust:enum:: pub enum PluginAction What ``guidedog plugin`` does. .. rubric:: Variants .. rust:variant:: Check { program: String } ``check PATH``. .. rust:field:: program: String The program. .. rust:variant:: Register { id: String, program: String } ``register ID PATH``. .. rust:field:: id: String The ID the program must have. .. rust:field:: program: String The program. .. rust:variant:: List ``list``. .. rust:variant:: Inspect { id: String } ``inspect ID``. .. rust:field:: id: String The registered ID. .. rust:variant:: Unregister { id: String } ``unregister ID``. .. rust:field:: id: String The registered ID. .. rust:variant:: Run { id: String, args: Vec } ``run ID -- ARGS``. .. rust:field:: id: String The registered ID. .. rust:field:: args: Vec What follows ``--``. .. rubric:: Functions .. rust:function:: pub fn extensions(linked: &Registry, machine: bool) -> Vec The commands the plugins in ``linked`` add, then (when ``machine``) those of the programs registered on this machine. A name already taken, by guidedog or an earlier plugin, is skipped. An unreadable machine registry adds nothing here; ``guidedog plugin list`` reports it. .. rust:function:: pub fn parse_command(args: &[String]) -> Parsed Reads a command line (without the program name) into the command it asks for, with guidedog's own commands only. Never fails: a mistake is returned as the command's problem, beside the reporting options read so far, so that it is reported as ``--diagnostics`` asks. .. rust:function:: pub fn parse_command_with(args: &[String], extensions: &[Extension]) -> Parsed :rust:fn:`parse_command ` knowing the commands plugins add (:rust:fn:`crate::extensions `): a word guidedog does not know, or a ``publish`` target, names one of them. .. rust:function:: pub fn full_version() -> String What the command prints as its version: :rust:const:`VERSION ` and :rust:const:`VERSION_SUFFIX `. .. rust:function:: pub fn version_text() -> String The versions built into the program, one per line: Guidedog, the Guidedoc engine and its document schema, the tree-sitter grammars, and the Graphviz library. The crash report starts with it; ``--version`` adds the Typst backend it finds. .. rust:function:: pub fn run() -> ExitCode Runs the process's command line with no linked plugin (registered programs are still found) and returns its exit status. .. rust:function:: pub fn run_with(linked: Registry) -> ExitCode Runs the process's command line (its arguments after the program name) with the plugins in ``linked``, which are looked up before the machine's registered programs. Returns the exit status. .. rust:function:: pub fn run_args(args: &[String], linked: Registry) -> ExitCode Runs the command line ``args`` (without the program name) with ``linked`` on the process's standard streams; returns the exit status. .. rust:function:: pub fn run_status(args: &[String], linked: &Registry) -> i32 :rust:fn:`run_args ` returning the exit status as a number, for a ``main`` that wraps it (in ``gd_host::catch_crash``, which takes a number). .. rust:function:: pub fn run_in(args: &[String], linked: &Registry, streams: Streams<'_>) -> i32 Runs the command line ``args`` (without the program name) with ``linked`` and the streams given, and returns the exit status. Commands that run other programs (``plugin run``) or ask questions during a build use the process's own streams. .. rubric:: Constants .. rust:const:: pub const VERSION: &str = env!("CARGO_PKG_VERSION") The Guidedog release this program belongs to: the workspace version, which the file ``VERSION`` at the repository root repeats for release tooling (a test checks both). .. rust:const:: pub const VERSION_SUFFIX: &str Build metadata appended to :rust:const:`VERSION ` for development builds, from the build-time environment variable ``GUIDEDOG_VERSION_SUFFIX`` (such as ``+3fe1d8a``); empty in a release.