refactor(cli): remove help and version subcommands

This commit is contained in:
ldm0
2026-08-17 01:23:02 +08:00
committed by Donough Liu
parent 2692c5ce76
commit be85a67d54
8 changed files with 22 additions and 36 deletions
+1 -19
View File
@@ -11,7 +11,7 @@ use crate::{
};
use anyhow::Result;
use anyhow::{Context, anyhow};
use clap::{CommandFactory, Parser};
use clap::Parser;
use moli_core::runtime::{
Browser, FetchedDocument, NavigationRuntimeConfig, PageVmInitStage, RenderedDomWaitUntil,
storage_partition::StoragePartitionState,
@@ -39,23 +39,6 @@ pub async fn run_cli_with_config<W: Write>(
config: AppConfig,
stdout: &mut W,
) -> Result<()> {
match cli.command.clone() {
Commands::Help => {
let mut command = Cli::command();
command
.write_long_help(&mut *stdout)
.context("failed to print CLI help")?;
writeln!(stdout).context("failed to write CLI help trailing newline")?;
return Ok(());
}
Commands::Version => {
writeln!(stdout, "{}", env!("CARGO_PKG_VERSION"))
.context("failed to write CLI version")?;
return Ok(());
}
_ => {}
}
match cli.command {
Commands::Fetch(args) => {
let browser = Browser::new(config.browser.clone())
@@ -253,7 +236,6 @@ pub async fn run_cli_with_config<W: Write>(
);
server.serve().await.context("protocol server failed")?;
}
Commands::Help | Commands::Version => unreachable!(),
}
Ok(())
+1 -3
View File
@@ -39,7 +39,7 @@ const FETCH_INFER_FLAGS: &[&str] = &[
"--web-bot-auth-profile",
];
const SERVE_INFER_FLAGS: &[&str] = &["--host", "--port", "--timeout", "--layout"];
const EXPLICIT_COMMANDS: &[&str] = &["fetch", "serve", "help", "version"];
const EXPLICIT_COMMANDS: &[&str] = &["fetch", "serve"];
const DUMP_MODES: &[&str] = &[
"json",
"html",
@@ -69,8 +69,6 @@ pub struct Cli {
pub enum Commands {
Fetch(Box<FetchArgs>),
Serve(Box<ServeArgs>),
Help,
Version,
}
#[derive(Debug, Clone, PartialEq, Eq, Args)]
-1
View File
@@ -58,7 +58,6 @@ impl AppConfig {
config.server.cdp_max_connections = args.cdp_max_connections;
config.server.cdp_max_pending_connections = args.cdp_max_pending_connections;
}
Commands::Help | Commands::Version => {}
}
Ok(config)
+16 -9
View File
@@ -580,15 +580,22 @@ fn infers_serve_mode_from_legacy_serve_flags() {
}
#[test]
fn parses_version_and_help_commands() {
assert_eq!(
Cli::try_parse_from(["moli", "version"]).unwrap().command,
Commands::Version
);
assert_eq!(
Cli::try_parse_from(["moli", "help"]).unwrap().command,
Commands::Help
);
fn rejects_removed_version_and_help_subcommands() {
for command in ["version", "help"] {
let error = Cli::try_parse_from(["moli", command]).unwrap_err();
assert_eq!(error.kind(), clap::error::ErrorKind::InvalidSubcommand);
}
}
#[test]
fn standard_version_and_help_flags_remain_available() {
for (flag, expected_kind) in [
("--version", clap::error::ErrorKind::DisplayVersion),
("--help", clap::error::ErrorKind::DisplayHelp),
] {
let error = Cli::try_parse_from(["moli", flag]).unwrap_err();
assert_eq!(error.kind(), expected_kind);
}
}
#[test]
+1 -1
View File
@@ -39,7 +39,7 @@ try {
$pathEntries = $env:PATH -split ";"
if ($installDir -notin $pathEntries) {
Write-Host "Add $installDir to PATH, then run: moli version"
Write-Host "Add $installDir to PATH, then run: moli --version"
}
} finally {
if (Test-Path -LiteralPath $tempDir) {
+1 -1
View File
@@ -78,6 +78,6 @@ printf 'Installed moli to %s/moli\n' "$moli_install_dir"
case ":${PATH:-}:" in
*":$moli_install_dir:"*) ;;
*)
printf 'Add %s to PATH, then run: moli version\n' "$moli_install_dir"
printf 'Add %s to PATH, then run: moli --version\n' "$moli_install_dir"
;;
esac
+1 -1
View File
@@ -26,7 +26,7 @@ Preserve the client's existing API where Moli supports it.
irm https://github.com/lexmount/moli/releases/latest/download/moli-installer.ps1 | iex
```
Resolve the installed binary again and run `moli version`. The default
Resolve the installed binary again and run `moli --version`. The default
location is `~/.local/bin/moli` on Linux/macOS and
`%LOCALAPPDATA%\Moli\bin\moli.exe` on Windows when it is not yet on `PATH`.
2. Start `moli serve` on the default loopback endpoint
+1 -1
View File
@@ -27,7 +27,7 @@ structure-first; enable layout only when the result needs pixels or pagination.
irm https://github.com/lexmount/moli/releases/latest/download/moli-installer.ps1 | iex
```
Resolve the installed binary again and run `moli version`. The default
Resolve the installed binary again and run `moli --version`. The default
location is `~/.local/bin/moli` on Linux/macOS and
`%LOCALAPPDATA%\Moli\bin\moli.exe` on Windows when it is not yet on `PATH`.
2. Fetch the seed URL as Markdown with the default completion strategy: