Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 141 additions & 114 deletions crates/registry-cli-docs/catalog.json

Large diffs are not rendered by default.

121 changes: 114 additions & 7 deletions crates/registry-cli-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ fn breg_reference() -> CommandReference {
/// The shared walker omits commands named `help` because Clap normally adds
/// one synthetically, while `rstack` disables that command and defines its own.
fn rstack_reference() -> CommandReference {
let command = registry_rstack::command();
let mut command = registry_rstack::command();
command.build();
let (help_index, help) = command
.get_subcommands()
.filter(|subcommand| !subcommand.is_hide_set())
Expand All @@ -102,9 +103,24 @@ fn rstack_reference() -> CommandReference {
help_index,
command_reference(help, Some(&reference.invocation), None),
);
limit_launcher_format_to_one(&mut reference);
reference
}

fn limit_launcher_format_to_one(command: &mut CommandReference) {
// The launcher rejects duplicate --format options before Clap parses them.
if let Some(format) = command
.options
.iter_mut()
.find(|option| option.display == "--format <FORMAT>")
{
format.repeatable = false;
}
for subcommand in &mut command.subcommands {
limit_launcher_format_to_one(subcommand);
}
}

/// The committed catalog snapshot the docs site renders, beside this crate's
/// manifest.
pub fn snapshot_path() -> PathBuf {
Expand Down Expand Up @@ -288,12 +304,103 @@ mod tests {
] {
assert!(!find_command(&catalog.binaries, invocation).usage.is_empty());
}
let root = find_command(&catalog.binaries, "rstack");
assert!(root.options.iter().any(|option| {
option.display == "--format <FORMAT>"
&& option.default_values == ["human"]
&& option.possible_values == ["human", "json"]
}));
for invocation in ["rstack", "rstack help", "rstack dev check"] {
let command = find_command(&catalog.binaries, invocation);
assert!(
command.options.iter().any(|option| {
option.display == "--format <FORMAT>"
&& !option.repeatable
&& option.default_values == ["human"]
&& option.possible_values == ["human", "json"]
}),
"{invocation}"
);
}
let help = find_command(&catalog.binaries, "rstack help");
assert_eq!(help.usage, "rstack help [OPTIONS] [PRODUCT]");
for option in [
"--install-root <INSTALL_ROOT>",
"--bin-dir <BIN_DIR>",
"--asset-dir <ASSET_DIR>",
"-h, --help",
] {
assert!(
help.options
.iter()
.any(|argument| argument.display == option),
"{option}"
);
}
let completions = find_command(&catalog.binaries, "rstack completions");
assert!(!completions
.options
.iter()
.any(|option| option.display.starts_with("--format ")));
assert!(completions
.long_about
.as_deref()
.is_some_and(|about| about.contains("rstack completions zsh")));
for invocation in ["rstack install", "rstack uninstall"] {
let command = find_command(&catalog.binaries, invocation);
assert!(
command.long_about.as_deref().is_some_and(|about| {
about.contains("one or more component names or `--all`")
}),
"{invocation}"
);
}
}

#[test]
fn provision_references_document_the_shared_mode_requirement() {
let catalog = catalog();
for invocation in [
"adapterctl provision",
"adapterctl job provision",
"coordinatorctl provision",
"documentsctl provision",
] {
let command = find_command(&catalog.binaries, invocation);
assert!(command.options.iter().any(|option| {
option.display == "--print-sql"
&& option.description.contains("Choose exactly one of `--admin-url-file`, `--admin-url-env`, or `--print-sql`.")
}), "{invocation}");
}
}

#[test]
fn coordinator_reference_describes_execution_requirements() {
let catalog = catalog();
for (verb, requirements) in [
(
"serve",
["Supply `--runtime-config <FILE>`", "Omit `--format`"],
),
(
"check",
[
"`--project`, `--runtime-config`, or both",
"`--explain` requires `--project`",
],
),
(
"provision",
[
"Supply `--runtime-config <FILE>`",
"before or after `provision`",
],
),
] {
let invocation = format!("coordinatorctl {verb}");
let command = find_command(&catalog.binaries, &invocation);
let description = command.long_about.as_deref().expect("command description");
for requirement in requirements {
assert!(
description.contains(requirement),
"{invocation}: {description}"
);
}
}
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions crates/registry-coordinator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ enum Command {
command: registry_cli_api::ConnectionCommand,
},
/// Run the production Coordinator service with the selected runtime.
///
/// Supply `--runtime-config <FILE>` for the deployment. Omit `--format` to use the service output stream.
Serve {
/// Coordinator runtime executable for an unmanaged installation.
#[arg(long, hide = true, env = "COORDINATOR_BIN", value_name = "BINARY")]
Expand All @@ -156,6 +158,8 @@ enum Command {
topic: GenerateTopic,
},
/// Validate the workflow, Transforms and root YAML companions offline.
///
/// Supply `--project`, `--runtime-config`, or both. `--explain` requires `--project`.
Check {
#[arg(long)]
/// Directory containing workflow.yaml and its declared code and contract assets.
Expand Down Expand Up @@ -228,6 +232,8 @@ enum Command {
remove_workflow: Vec<String>,
},
/// Create the database, the migration and runtime roles, and the grants `apply` expects, as a PostgreSQL administrator.
///
/// Supply `--runtime-config <FILE>` before or after `provision`.
#[command(mut_arg("runtime_config", |argument| argument.required(false)))]
Provision(registry_platform_provision::cli::ProvisionArgs),
/// Apply every listed workflow's package and least-privileged runtime grants using migration credentials.
Expand Down
32 changes: 32 additions & 0 deletions crates/registry-coordinator/tests/cli_authoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ fn cli(arguments: &[&str]) -> std::process::Output {
.unwrap()
}

#[test]
fn serve_help_documents_the_runtime_file_and_stream_requirements() {
let output = cli(&["serve", "--help"]);
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
let help = String::from_utf8(output.stdout).unwrap();
assert!(help.contains("Supply `--runtime-config <FILE>`"), "{help}");
assert!(help.contains("Omit `--format`"), "{help}");

for (arguments, diagnostic) in [
(&["serve"][..], "serve requires --runtime-config"),
(
&[
"serve",
"--runtime-config",
"unused.yaml",
"--format",
"human",
],
"--format does not apply to serve",
),
] {
let output = cli(arguments);
assert_eq!(output.status.code(), Some(2), "{output:?}");
assert!(output.stdout.is_empty(), "{output:?}");
assert!(
String::from_utf8_lossy(&output.stderr).contains(diagnostic),
"{output:?}"
);
}
}

#[test]
fn runtime_check_is_offline_until_environment_is_explicitly_requested() {
let root = tempfile::tempdir().unwrap();
Expand Down
4 changes: 3 additions & 1 deletion crates/registry-platform-provision/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ pub struct ProvisionArgs {
required_unless_present_any = ["admin_url_file", "print_sql"]
)]
pub admin_url_env: Option<String>,
/// Print the SQL script and connect to nothing
/// Print the SQL script and connect to nothing.
///
/// Choose exactly one of `--admin-url-file`, `--admin-url-env`, or `--print-sql`.
#[arg(long)]
pub print_sql: bool,
/// Declared posture: development or production. Unset means production.
Expand Down
28 changes: 23 additions & 5 deletions crates/registry-rstack/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ enum RequestedReportFormat {
)]
struct Cli {
/// Report encoding. Defaults to human even when stdout is piped.
/// Supply `--format` at most once.
/// Only forwarded evidence test and evidence fixtures run commands accept junit.
#[arg(long, global = true, value_enum, action = ArgAction::Append, default_value = "human")]
format: Vec<ReportFormat>,
Expand Down Expand Up @@ -113,6 +114,8 @@ enum Command {
command: ComponentCommand,
},
/// Install one or more components at the selected release.
///
/// Select either one or more component names or `--all`.
Install {
/// Install every product available for the selected platform.
#[arg(long)]
Expand All @@ -131,6 +134,8 @@ enum Command {
preview: bool,
},
/// Remove one or more installed components.
///
/// Select either one or more component names or `--all`.
Uninstall {
/// Remove the complete managed installation.
#[arg(long)]
Expand All @@ -144,12 +149,17 @@ enum Command {
/// Check selected binaries, paths, and component availability.
Doctor,
/// Show offline product help.
///
/// Omit the product for the launcher overview. Use `rstack help dev` for local development help.
/// For a specific product action, run `rstack <product> <action> --help`.
Help {
/// Product whose offline command reference to show.
#[arg(value_name = "PRODUCT")]
product: Option<String>,
},
/// Generate shell completion script.
/// Generate a Zsh completion script.
///
/// Run `rstack completions zsh` and omit `--format`.
Completions {
/// Shell whose completion script to generate.
#[arg(value_name = "SHELL")]
Expand Down Expand Up @@ -671,11 +681,11 @@ enum ComponentCommand {
List,
}

/// The installer's global path flags mean nothing to a development run, so
/// `dev` and its subcommands carry hidden copies that keep them out of their
/// help while still accepting them.
/// Build the launcher tree with help tailored to each command. Development
/// hides the installer's path flags. Completions hides the report format flag
/// so the handler can still give its dedicated refusal when it is supplied.
pub fn command() -> clap::Command {
Cli::command().mut_subcommand("dev", |dev| {
let command = Cli::command().mut_subcommand("dev", |dev| {
[
("install_root", "install-root"),
("bin_dir", "bin-dir"),
Expand All @@ -691,6 +701,14 @@ pub fn command() -> clap::Command {
.value_parser(value_parser!(PathBuf)),
)
})
});
let format = command
.get_arguments()
.find(|argument| argument.get_id() == "format")
.expect("the launcher has a global report format")
.clone();
command.mut_subcommand("completions", |completions| {
completions.arg(format.hide(true))
})
}

Expand Down
51 changes: 51 additions & 0 deletions crates/registry-rstack/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,50 @@ fn root_help_works_without_an_installation() {
assert!(text.contains("evidence"));
}

#[test]
fn offline_help_command_shows_its_own_invocation_and_global_options() {
let output = run(&["help", "--help"]);
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
let help = String::from_utf8(output.stdout).unwrap();
assert!(
help.contains("Usage: rstack help [OPTIONS] [PRODUCT]"),
"{help}"
);
for option in [
"--format",
"--install-root",
"--bin-dir",
"--asset-dir",
"--help",
] {
assert!(help.contains(option), "{help}");
}
}

#[test]
fn installation_commands_document_and_enforce_the_component_selection() {
for verb in ["install", "uninstall"] {
let output = run(&[verb, "--help"]);
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
let help = String::from_utf8(output.stdout).unwrap();
assert!(
help.contains("one or more component names or `--all`"),
"{help}"
);

for arguments in [vec![verb], vec![verb, "breg", "--all"]] {
let output = run(&arguments);
assert_eq!(output.status.code(), Some(2), "{output:?}");
assert!(output.stdout.is_empty(), "{output:?}");
assert!(
String::from_utf8_lossy(&output.stderr).contains("select component names or --all")
);
}
}
}

#[test]
fn unknown_component_and_duplicate_format_are_usage_failures() {
let unknown = run(&["install", "bogus"]);
Expand Down Expand Up @@ -67,6 +111,13 @@ fn unknown_component_and_duplicate_format_are_usage_failures() {

#[test]
fn completions_refuses_an_explicit_report_format_without_emitting_a_script() {
let output = run(&["completions", "--help"]);
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
let help = String::from_utf8(output.stdout).unwrap();
assert!(help.contains("rstack completions zsh"), "{help}");
assert!(!help.contains("--format <FORMAT>"), "{help}");

let before = run(&["--format", "human", "completions", "zsh"]);
assert_eq!(before.status.code(), Some(2), "{before:?}");
assert!(before.stdout.is_empty(), "{before:?}");
Expand Down
26 changes: 26 additions & 0 deletions docs/site/scripts/cli-reference-sidebar.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ test('seats every published command page in command order', async (t) => {
]);
});

test('seats the launcher and its nested commands only when published', async (t) => {
const root = await mkdtemp(resolve(tmpdir(), 'registry-docs-cli-sidebar-'));
t.after(() => rm(root, { recursive: true, force: true }));
const index = resolve(root, 'index.mdx');

await writeFile(index, page('CLI reference'));
await mkdir(resolve(root, 'rstack/dev'), { recursive: true });
await writeFile(resolve(root, 'rstack/dev.mdx'), page('rstack dev'));
await writeFile(resolve(root, 'rstack/dev/check.mdx'), page('rstack dev check'));
await writeFile(resolve(root, 'rstack/dev/run.mdx'), draftPage('rstack dev run'));

const launcher = resolve(root, 'rstack.mdx');
await writeFile(launcher, draftPage('rstack'));
assert.deepEqual(cliReferenceSidebar(index)[0].items, [
{ label: 'Overview', slug: 'reference/cli' },
]);

await writeFile(launcher, page('rstack'));
assert.deepEqual(cliReferenceSidebar(index)[0].items, [
{ label: 'Overview', slug: 'reference/cli' },
{ label: 'rstack', slug: 'reference/cli/rstack' },
{ label: 'rstack dev', slug: 'reference/cli/rstack/dev' },
{ label: 'rstack dev check', slug: 'reference/cli/rstack/dev/check' },
]);
});

test('omits every seat of a binary whose product the docset does not publish', async (t) => {
const root = await mkdtemp(resolve(tmpdir(), 'registry-docs-cli-sidebar-'));
t.after(() => rm(root, { recursive: true, force: true }));
Expand Down
Loading
Loading