Guidedog 설명서 1.0.0-beta.16
언어
이 페이지의 내용
Guidedog / 문서 1.0.0-beta.16

gd_cli

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.

fn main() -> std::process::ExitCode {
    let linked = gd_plugins::Registry::new(Vec::new()).unwrap_or_default();
    gd_cli::run_with(linked)
}

The staged path: parse_command turns words into a typed Command (plain data, checked, with Elm-style usage problems), and 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.

Structs

pub struct gd_cli::MigrateCommand

guidedog migrate [conf.py|DIR].

Fields

pub input: PathBuf

The conf.py, or the folder holding it.

pub output: MigrateOutput

-o.

pub force: bool

--force: replace an existing conf.toml.

pub struct gd_cli::BuildCommand

guidedog build: what to load, what to build, and how.

Fields

pub dir: PathBuf

The project folder (the sphinx-build forms: the source folder).

pub kind: BuilderKind

The builder.

pub load: LoadOptions

-c, -C, -D, and the sphinx-build forms’ folders.

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.

pub memory: MemoryMode

--memory.

pub verbose: u32

-v, repeatable: show notes too.

pub typst: Option<String>

--typst: overrides typst in conf.toml.

pub peak_memory_file: Option<PathBuf>

--peak-memory-file: where to write the process’s peak memory in bytes when the build ends (GDS 0020).

pub struct gd_cli::CleanCommand

guidedog clean [PROJECT].

Fields

pub dir: PathBuf

The project folder.

pub struct gd_cli::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.

Fields

pub input: String

The input path, or - for standard input.

pub output: String

The output path, or - for standard output.

pub from: Format

The input’s markup.

pub to: Target

The artifact to write.

pub emit_typst: Option<PathBuf>

--emit-typst: where to write the generated Typst too.

pub force: bool

--force: replace an existing output.

pub raw: ContentPolicy

--raw: what happens to raw HTML or Typst content.

pub strict: bool

--strict: warnings fail the conversion.

pub title: String

--title.

pub lang: String

--lang.

pub fragment: bool

--fragment: the body only.

pub number_sections: bool

--number-sections.

pub math: MathOutput

--math: how HTML shows formulas.

pub embed_pictures: bool

--embed-pictures: draw graphs, Typst diagrams and scores into the HTML.

pub max_pictures: Option<usize>

--max-pictures: how many pictures --embed-pictures embeds.

pub max_picture_kib: Option<usize>

--max-picture-kib: the size of all embedded pictures together, in KiB.

pub keep_going: bool

--keep-going: write the output although the content has errors.

pub typst: String

--typst: the Typst program, typst for the embedded compiler.

pub font_paths: Vec<PathBuf>

--font-path, repeatable.

pub package_cache: Option<PathBuf>

--package-cache.

pub offline: bool

--offline.

pub embedded_fonts_only: bool

--embedded-fonts-only.

pub budget_mib: Option<usize>

--budget, in MiB.

pub max_depth: Option<usize>

--max-depth.

pub max_nodes: Option<usize>

--max-nodes.

pub stack_kib: Option<usize>

--stack-kib.

pub struct gd_cli::CapabilitiesCommand

guidedog capabilities.

Fields

pub json: bool

--json or --format=json instead of the summary.

pub project: Option<PathBuf>

The project whose configuration decides what is enabled; None reports a project without configuration.

pub struct gd_cli::FormatsCommand

guidedog formats.

Fields

pub json: bool

--format=json instead of the table.

pub typst: String

--typst: the Typst program to describe.

pub struct gd_cli::IntlCommand

guidedog intl update|stat [PROJECT], with sphinx-intl’s options.

Fields

pub action: IntlAction

update or stat.

pub dir: PathBuf

The project folder.

pub load: LoadOptions

-c and -D.

pub languages: Vec<String>

-l, repeatable.

pub pot_dir: Option<PathBuf>

-p: the templates; None for _build/gettext.

pub locale_dir: Option<PathBuf>

-d: the catalogs; None for the first of locale_dirs.

pub line_width: usize

-w (default 76).

pub obsolete: bool

Keep messages the templates no longer have (--no-obsolete clears it).

pub struct gd_cli::ExtensionCommand

A command a plugin adds, as a command line names it.

Fields

pub extension: crate::Extension

The command and the plugin that contributes it.

pub args: Vec<String>

The command line without the command’s words, for the plugin to read.

pub help: bool

--help or -h was given (before --): guidedog shows the command’s help.

pub struct gd_cli::QuickstartCommand

guidedog quickstart [DIR]: the answers given as options; a terminal asks for the rest unless quiet.

Fields

pub dir: PathBuf

Where to create the project.

pub quiet: bool

-q: ask nothing.

pub project: String

-p.

pub author: String

-a.

pub version: String

-v: the short version; the release when empty.

pub release: String

-r.

pub language: String

-l; empty for en (or the answer).

pub suffix: String

--suffix; empty for .rst.

pub separate: Option<bool>

--sep (Some(true)) or --no-sep (Some(false)); None asks.

pub struct gd_cli::ServeCommand

guidedog serve: the HTML build it repeats, and the listen address.

Fields

pub build: BuildCommand

The build to run first and on every change (always html).

pub host: std::net::IpAddr

--host (default 127.0.0.1).

pub port: u16

--port (default 8000).

pub struct gd_cli::Output

How the command reports, whatever it runs: --color, --diagnostics, -q.

Fields

pub color: ColorMode

--color.

pub diagnostics: Diagnostics

--diagnostics.

pub quiet: bool

-q: no success messages; warnings and errors still show.

pub struct gd_cli::Parsed

A parsed command line: how to report, and the command, or the usage problem that stopped parsing (reported as output asks).

Fields

pub output: Output

How to report.

pub command: Result<Command, gd_host::Problem>

The command to run, or why the command line is not one.

pub struct gd_cli::PluginCommand

guidedog plugin ....

Fields

pub action: PluginAction

The subcommand.

pub project: Option<PathBuf>

--project: the project the checks use (default: the current folder).

pub config: Option<PathBuf>

--config: the plugin’s configuration, relative to the project.

pub timeout: Option<u32>

--timeout, in seconds (default 60).

pub yes: bool

--yes: register without asking.

pub struct gd_cli::PublishCommand

guidedog publish --publisher=ID --config=FILE.

Fields

pub publisher: String

--publisher.

pub config: String

--config.

pub dry_run: bool

--dry-run: build and plan, publish nothing.

pub wait: Option<u32>

--wait, in seconds; None for the publisher’s default.

pub timeout: Option<u32>

--timeout, in seconds; None for 300.

pub verbose: bool

--verbose: list every change of the plan.

pub struct gd_cli::Streams<'a>

The streams a command line runs with, borrowed for the run.

Fields

pub out: &'a mut dyn Write

Results: tables, converted output, success messages.

pub err: &'a mut dyn Write

Reports, problems, progress, and questions.

pub input: &'a mut dyn BufRead

Answers to questions, one per line.

pub terminals: Terminals

Which streams are terminals.

Trait Implementations

impl std::fmt::Debug for Streams<'_>
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
pub struct gd_cli::Terminals

Whether each standard stream is a terminal: colors (--color=auto) and questions (only a person at a terminal is asked) depend on it.

Fields

pub stdin: bool

Standard input is a terminal.

pub stdout: bool

Standard output is a terminal.

pub stderr: bool

Standard error is a terminal.

Implementations

impl Terminals
pub fn detect() -> Terminals

The process’s own streams.

pub struct gd_cli::Extension

A command a plugin adds to guidedog’s command line, and the plugin that runs it.

Fields

pub plugin: String

The ID of the plugin that contributes it.

pub info: CommandInfo

Its name, summary, help and options, as the plugin declares them.

pub linked: bool

The plugin is linked into this program (not a registered program).

Implementations

impl Extension
pub fn name(&self) -> String

The command’s name, such as pages workflow.

Enums

pub enum gd_cli::ColorMode

When the command styles its output with colors.

Variants

Auto

Only on a terminal, unless NO_COLOR is set or TERM is dumb.

Always

Always.

Never

Never.

pub enum gd_cli::Command

What a command line asks for.

Variants

Help(Option<&'static str>)

Show help: the overview (None) or a command’s.

Version { typst: String }

--version, with the Typst program to describe.

typst: String

--typst.

Licenses

--licenses.

Formats(FormatsCommand)

formats.

Capabilities(CapabilitiesCommand)

capabilities.

Convert(Box<ConvertCommand>)

convert.

Quickstart(QuickstartCommand)

quickstart.

Build(Box<BuildCommand>)

build (and the sphinx-build forms).

Serve(Box<ServeCommand>)

serve.

Clean(CleanCommand)

clean.

Migrate(MigrateCommand)

migrate.

Intl(IntlCommand)

intl update and intl stat.

Plugin(PluginCommand)

plugin ....

Publish(PublishCommand)

publish --publisher=ID.

Extension(ExtensionCommand)

A command a plugin adds, such as pages workflow or publish pages.

ExtensionHelp(String)

WORD --help, where WORD begins only commands plugins add: their list.

pub enum gd_cli::Diagnostics

How problems and reports are written on standard error.

Variants

Text

Explained, Elm-style reports.

Json

One JSON object per report.

pub enum gd_cli::IntlAction

The two intl commands.

Variants

Update

Create or merge the catalogs from the templates.

Stat

Count what is translated.

pub enum gd_cli::MemoryMode

What a build does when it reaches its memory budget.

Variants

Ask

A terminal asks (raise the budget, or stop); elsewhere the build stops.

Stop

--memory=ram: stop at the budget without asking.

pub enum gd_cli::MigrateOutput

Where migrate writes conf.toml.

Variants

Beside

Beside the conf.py.

File(PathBuf)

-o FILE.

Stdout

-o -: standard output.

pub enum gd_cli::PluginAction

What guidedog plugin does.

Variants

Check { program: String }

check PATH.

program: String

The program.

Register { id: String, program: String }

register ID PATH.

id: String

The ID the program must have.

program: String

The program.

List

list.

Inspect { id: String }

inspect ID.

id: String

The registered ID.

Unregister { id: String }

unregister ID.

id: String

The registered ID.

Run { id: String, args: Vec<String> }

run ID -- ARGS.

id: String

The registered ID.

args: Vec<String>

What follows --.

Functions

pub fn gd_cli::extensions(linked: &Registry, machine: bool) -> Vec<Extension>

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.

pub fn gd_cli::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.

pub fn gd_cli::parse_command_with(args: &[String], extensions: &[Extension]) -> Parsed

parse_command knowing the commands plugins add (crate::extensions): a word guidedog does not know, or a publish target, names one of them.

pub fn gd_cli::full_version() -> String

What the command prints as its version: VERSION and VERSION_SUFFIX.

pub fn gd_cli::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.

pub fn gd_cli::run() -> ExitCode

Runs the process’s command line with no linked plugin (registered programs are still found) and returns its exit status.

pub fn gd_cli::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.

pub fn gd_cli::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.

pub fn gd_cli::run_status(args: &[String], linked: &Registry) -> i32

run_args returning the exit status as a number, for a main that wraps it (in gd_host::catch_crash, which takes a number).

pub fn gd_cli::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.

Constants

pub const gd_cli::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).

pub const gd_cli::VERSION_SUFFIX: &str

Build metadata appended to VERSION for development builds, from the build-time environment variable GUIDEDOG_VERSION_SUFFIX (such as +3fe1d8a); empty in a release.