Skip to content

Commit 45b2611

Browse files
committed
Organize all ts CLI commands under commands/<name>/
Every subcommand's implementation now lives under commands/<name>/, matching the dev command's layout: audit moves to commands/audit/mod.rs, config init to commands/config/init.rs. AuditArgs moves from run.rs into the audit module alongside run_audit, so run.rs only wires subcommands together. audit and config are pub(crate) (crate-internal); dev stays pub for the proxy_e2e integration suite.
1 parent 3872eea commit 45b2611

9 files changed

Lines changed: 42 additions & 39 deletions

File tree

crates/trusted-server-cli/src/audit/analyzer.rs renamed to crates/trusted-server-cli/src/commands/audit/analyzer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use regex::Regex;
55
use scraper::{Html, Selector};
66
use url::Url;
77

8-
use crate::audit::collector::CollectedPage;
9-
use crate::audit::{AssetParty, AuditArtifact, AuditedAsset, DetectedIntegration};
8+
use crate::commands::audit::collector::CollectedPage;
9+
use crate::commands::audit::{AssetParty, AuditArtifact, AuditedAsset, DetectedIntegration};
1010
use crate::error::{CliResult, report_error};
1111

1212
static GTM_REGEX: LazyLock<Regex> =
@@ -256,7 +256,7 @@ pub(crate) fn extract_gtm_container_id(artifact: &AuditArtifact) -> Option<Strin
256256
#[cfg(test)]
257257
mod tests {
258258
use super::*;
259-
use crate::audit::collector::{CollectedRequest, CollectedScriptTag};
259+
use crate::commands::audit::collector::{CollectedRequest, CollectedScriptTag};
260260

261261
fn page_url() -> Url {
262262
Url::parse("https://publisher.example/page").expect("should parse URL")

crates/trusted-server-cli/src/audit/browser_collector.rs renamed to crates/trusted-server-cli/src/commands/audit/browser_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tokio::time::{sleep, timeout};
1111
use url::Url;
1212
use which::which;
1313

14-
use crate::audit::collector::{
14+
use crate::commands::audit::collector::{
1515
AuditCollector, CollectedPage, CollectedRequest, CollectedScriptTag,
1616
};
1717
use crate::error::{CliResult, report_error};
File renamed without changes.

crates/trusted-server-cli/src/audit.rs renamed to crates/trusted-server-cli/src/commands/audit/mod.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,34 @@ use std::path::{Path, PathBuf};
1010
use serde::Serialize;
1111
use url::Url;
1212

13-
use crate::audit::collector::AuditCollector;
14-
use crate::config_init::EXAMPLE_CONFIG;
13+
use crate::commands::audit::collector::AuditCollector;
14+
use crate::commands::config::init::EXAMPLE_CONFIG;
1515
use crate::error::{CliResult, cli_error, report_error};
16-
use crate::run::AuditArgs;
1716

1817
use analyzer::{analyze_collected_page, extract_gtm_container_id};
1918

19+
/// Arguments for the `ts audit` command.
20+
#[derive(Debug, clap::Args)]
21+
pub(crate) struct AuditArgs {
22+
/// Public HTTP(S) URL to audit.
23+
pub(crate) url: String,
24+
/// JavaScript asset audit output path.
25+
#[arg(long)]
26+
pub(crate) js_assets: Option<std::path::PathBuf>,
27+
/// Draft Trusted Server config output path.
28+
#[arg(long)]
29+
pub(crate) config: Option<std::path::PathBuf>,
30+
/// Do not write the JavaScript asset audit file.
31+
#[arg(long)]
32+
pub(crate) no_js_assets: bool,
33+
/// Do not write the draft Trusted Server config file.
34+
#[arg(long)]
35+
pub(crate) no_config: bool,
36+
/// Overwrite existing output files.
37+
#[arg(long)]
38+
pub(crate) force: bool,
39+
}
40+
2041
const DEFAULT_JS_ASSETS_PATH: &str = "js-assets.toml";
2142
const DEFAULT_CONFIG_PATH: &str = "trusted-server.toml";
2243

@@ -393,7 +414,7 @@ mod tests {
393414
use tempfile::TempDir;
394415

395416
use super::*;
396-
use crate::audit::collector::{CollectedPage, CollectedRequest, CollectedScriptTag};
417+
use crate::commands::audit::collector::{CollectedPage, CollectedRequest, CollectedScriptTag};
397418

398419
struct FakeCollector {
399420
collected: CollectedPage,
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod init;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
pub(crate) mod audit;
2+
pub(crate) mod config;
3+
// `dev` is `pub` so the macOS-gated `tests/proxy_e2e.rs` suite can reach
4+
// `commands::dev::proxy`; the other command modules are crate-internal.
15
pub mod dev;

crates/trusted-server-cli/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#[cfg(not(target_arch = "wasm32"))]
2-
mod audit;
3-
#[cfg(not(target_arch = "wasm32"))]
4-
mod config_init;
5-
#[cfg(not(target_arch = "wasm32"))]
62
mod error;
73
#[cfg(not(target_arch = "wasm32"))]
84
mod run;
95

106
#[cfg(not(target_arch = "wasm32"))]
117
pub use run::run_from_env;
128

13-
// The `ts dev` command group is available on every host target; its only
14-
// subcommand, `ts dev proxy`, is macOS-only (CA trust via the login keychain,
15-
// Safari automation via `networksetup`, a native TLS / networking stack) and its
9+
// Every `ts` subcommand's implementation lives under `commands/<name>`. The
10+
// `ts dev` group is available on every host target; its only subcommand,
11+
// `ts dev proxy`, is macOS-only (CA trust via the login keychain, Safari
12+
// automation via `networksetup`, a native TLS / networking stack) and its
1613
// dependencies are scoped to macOS in `Cargo.toml`. `commands` is `pub` so the
1714
// macOS-gated `tests/proxy_e2e.rs` integration suite can exercise the proxy
1815
// internals.

crates/trusted-server-cli/src/run.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use edgezero_cli::args::{
77
};
88
use trusted_server_core::config::TrustedServerAppConfig;
99

10-
use crate::audit::browser_collector::BrowserAuditCollector;
11-
use crate::config_init::{ConfigInitArgs, run_config_init};
10+
use crate::commands::audit::AuditArgs;
11+
use crate::commands::audit::browser_collector::BrowserAuditCollector;
12+
use crate::commands::config::init::{ConfigInitArgs, run_config_init};
1213

1314
#[derive(Debug, Parser)]
1415
#[command(name = "ts", about = "Trusted Server CLI")]
@@ -39,27 +40,6 @@ enum Command {
3940
Dev(crate::commands::dev::DevCommand),
4041
}
4142

42-
#[derive(Debug, clap::Args)]
43-
pub(crate) struct AuditArgs {
44-
/// Public HTTP(S) URL to audit.
45-
pub(crate) url: String,
46-
/// JavaScript asset audit output path.
47-
#[arg(long)]
48-
pub(crate) js_assets: Option<std::path::PathBuf>,
49-
/// Draft Trusted Server config output path.
50-
#[arg(long)]
51-
pub(crate) config: Option<std::path::PathBuf>,
52-
/// Do not write the JavaScript asset audit file.
53-
#[arg(long)]
54-
pub(crate) no_js_assets: bool,
55-
/// Do not write the draft Trusted Server config file.
56-
#[arg(long)]
57-
pub(crate) no_config: bool,
58-
/// Overwrite existing output files.
59-
#[arg(long)]
60-
pub(crate) force: bool,
61-
}
62-
6343
#[derive(Debug, Subcommand)]
6444
enum ConfigCommand {
6545
/// Initialize a Trusted Server config file from the example template.
@@ -88,7 +68,7 @@ fn dispatch(args: Args) -> Result<(), String> {
8868
let stdout = std::io::stdout();
8969
let mut out = stdout.lock();
9070
let collector = BrowserAuditCollector;
91-
crate::audit::run_audit(&args, &collector, &mut out)
71+
crate::commands::audit::run_audit(&args, &collector, &mut out)
9272
}
9373
Command::Auth(args) => edgezero_cli::run_auth(&args),
9474
Command::Build(args) => edgezero_cli::run_build(&args),

0 commit comments

Comments
 (0)