Skip to main content

faucet_cli/
cli.rs

1//! Argument parser shared by `main.rs` and the integration tests.
2
3use crate::commands::completions;
4use clap::{Args, Parser, Subcommand};
5use clap_complete::engine::ArgValueCandidates;
6use std::path::PathBuf;
7
8/// Runtime matrix-row selection flags, shared by `run`/`validate`/`preview`/
9/// `plan` via `#[command(flatten)]`. Implements the selection model of
10/// #370 (identity), #371 (status), #376 (tags), and #377 (include_parents).
11#[derive(Debug, Args, Default, Clone)]
12pub struct SelectionArgs {
13    /// Run only matrix rows whose id exactly matches. Repeatable and/or
14    /// comma-joined (`--select people --select time_off` or `--select a,b`).
15    /// Force-includes by name, bypassing the `status` gate. (#370)
16    #[arg(long = "select", value_delimiter = ',', env = "FAUCET_SELECT",
17          add = ArgValueCandidates::new(completions::matrix_id_candidates))]
18    pub select: Vec<String>,
19
20    /// Like `--select` but glob-matched against row ids (`--only 'timeoff_*'`).
21    /// Also bypasses the `status` gate. Repeatable / comma-joined. (#370)
22    #[arg(long = "only", value_delimiter = ',',
23          add = ArgValueCandidates::new(completions::matrix_id_candidates))]
24    pub only: Vec<String>,
25
26    /// Remove matching rows (exact id or glob) from the run set, applied last.
27    /// A `mandatory` row is removable only by an exact `--skip <id>`. (#370)
28    #[arg(long = "skip", value_delimiter = ',', env = "FAUCET_SKIP",
29          add = ArgValueCandidates::new(completions::matrix_id_candidates))]
30    pub skip: Vec<String>,
31
32    /// Additively include a readiness tier beyond the default
33    /// `{mandatory, active}` set: `available` / `draft` / `archived`.
34    /// Repeatable / comma-joined. (#371)
35    #[arg(long = "status", value_delimiter = ',', env = "FAUCET_STATUS",
36          add = ArgValueCandidates::new(completions::status_candidates))]
37    pub status: Vec<String>,
38
39    /// Narrow the eligible set to rows carrying any listed tag (union).
40    /// Cannot resurrect a non-eligible row — raise `--status` for that.
41    /// Repeatable / comma-joined. (#376)
42    #[arg(long = "tag", value_delimiter = ',', env = "FAUCET_TAGS",
43          add = ArgValueCandidates::new(completions::tag_candidates))]
44    pub tags: Vec<String>,
45
46    /// How a selected row's `parent:` / `depends_on:` ancestors are resolved
47    /// when not independently selected: `off` (default, strict — error on a
48    /// missing ancestor), `eligible`, or `all`. Overrides
49    /// `selection.include_parents` in the config. (#377)
50    #[arg(long = "include-parents", env = "FAUCET_INCLUDE_PARENTS")]
51    pub include_parents: Option<String>,
52}
53
54/// `faucet` — config-driven runner for faucet-stream pipelines.
55#[derive(Debug, Parser)]
56#[command(name = "faucet", version, about, long_about = None)]
57pub struct Cli {
58    /// Override the global log level (also honors `FAUCET_LOG`).
59    #[arg(long, global = true, env = "FAUCET_LOG", default_value = "info")]
60    pub log_level: String,
61
62    #[command(subcommand)]
63    pub command: Command,
64}
65
66/// Top-level subcommands.
67#[derive(Debug, Subcommand)]
68pub enum Command {
69    /// Execute a pipeline config end-to-end.
70    Run(RunArgs),
71    /// Replay a bounded historical window of a pipeline: chunk --from/--to
72    /// into window units, run them with bounded parallelism, and record
73    /// durable, resumable progress. Exits non-zero if any unit fails.
74    Backfill(BackfillArgs),
75    /// Bulk-snapshot a database table, then stream CDC from a position captured
76    /// before the snapshot (a true mirror with `write_mode: upsert`).
77    /// Long-running when `replication.continuous` is true (Ctrl-C / SIGTERM to stop).
78    Replicate(ReplicateArgs),
79    /// Connect to a config's source, enumerate the datasets behind it
80    /// (tables / collections / indices / prefixes), and emit a ready-to-run
81    /// config with one matrix row per dataset.
82    Discover(DiscoverArgs),
83    /// Parse + validate a pipeline config without running it.
84    Validate(ValidateArgs),
85    /// Print the JSON Schema for a specific connector.
86    Schema(SchemaArgs),
87    /// List every compiled-in source, sink, and transform with a one-line
88    /// description (`--available` lists the whole connector registry instead).
89    List(ListArgs),
90    /// Search the connector registry index for connectors by name / keyword.
91    Search(SearchArgs),
92    /// Score each connector's conformance to the faucet SDK contract and print
93    /// its maturity tier (Stable / Experimental / Beta / Draft) + capabilities.
94    Conformance(ConformanceArgs),
95    /// Show how to install or enable a connector from the registry index
96    /// (prints the recipe; never executes anything).
97    Install(InstallArgs),
98    /// Run only the source side and print records to stdout (uses the stdout sink).
99    Preview(PreviewArgs),
100    /// Read-only preview of what a config would do: resolved pipeline, inferred
101    /// output schema, sink schema delta, lineage, and target sinks — zero writes.
102    Plan(PlanArgs),
103    /// Watch a config and re-run a sample offline on every save, printing a
104    /// live diff of the output. Requires the `cli-dev` build feature.
105    #[cfg(feature = "cli-dev")]
106    Dev(DevArgs),
107    /// Scaffold a starter `pipeline.yaml` to disk.
108    Init(InitArgs),
109    /// Scaffold a new artifact — currently a third-party connector crate.
110    New(NewArgs),
111    /// Probe every connector in a config (auth / network / permissions) and
112    /// print a green/red checklist. Exits non-zero if any probe fails.
113    Doctor(DoctorArgs),
114    /// Run fixture-based offline pipeline tests from one or more spec files.
115    /// No real source or sink is touched. Exits non-zero if any case fails.
116    Test(TestArgs),
117    /// Inspect, replay, or discard dead-letter-queue envelopes written by a
118    /// pipeline's `dlq:` sink.
119    Dlq(DlqArgs),
120    /// Validate a config's `contract:` block and print a summary, or export
121    /// it in a machine-readable format (`--export`).
122    #[cfg(feature = "contract")]
123    Contract(ContractArgs),
124    /// Validate a config's `masking:` block and print which rules apply to
125    /// each destination sink.
126    #[cfg(feature = "masking")]
127    Masking(MaskingArgs),
128    /// Run a pipeline on a cron schedule (long-running; Ctrl-C / SIGTERM to stop).
129    #[cfg(feature = "schedule")]
130    Schedule(ScheduleArgs),
131    /// Run a long-running HTTP control plane (submit / poll / cancel pipeline runs).
132    #[cfg(feature = "serve")]
133    Serve(ServeArgs),
134    /// Run an MCP (Model Context Protocol) server over stdio, exposing faucet's
135    /// introspection surfaces as agent tool calls (for Claude Desktop / Code).
136    #[cfg(feature = "mcp")]
137    Mcp(McpArgs),
138    /// Send a synthetic notification through a config's `notifications:` rules
139    /// to validate channel setup end-to-end (no pipeline runs).
140    #[cfg(feature = "notify")]
141    Notify(NotifyArgs),
142    /// Browse the Data Movement Catalog accumulated by a config's `catalog:`
143    /// store — datasets, schema timelines, volume/freshness, lineage.
144    #[cfg(feature = "catalog")]
145    Catalog(CatalogArgs),
146    /// Register a parameterized config once, then trigger runs by id + params.
147    /// The registry is shared with `faucet serve` — point both at the same
148    /// store URL and templates registered here are triggerable over HTTP.
149    #[cfg(feature = "templates")]
150    Template(TemplateArgs),
151    /// Generate a shell tab-completion script (bash / zsh / fish / powershell /
152    /// elvish). For registry- and config-aware *dynamic* completion, enable the
153    /// `COMPLETE` hook instead, e.g. `source <(COMPLETE=zsh faucet)`.
154    Completions(CompletionsArgs),
155    /// Upgrade a config written against an older `faucet` grammar to the current
156    /// shape (e.g. pre-`pipeline:` top-level source/sink, legacy inline auth).
157    /// Idempotent; rewrites in place unless `--check` / `--stdout`.
158    Migrate(MigrateArgs),
159    /// Canonicalize a config: stable key order, normalized style. Idempotent;
160    /// rewrites in place unless `--check` / `--stdout`. Comments are not
161    /// preserved (the config is parsed and re-serialized).
162    Fmt(FmtArgs),
163    /// Explain, in plain English, what a pipeline config does — source →
164    /// transforms → sink, matrix expansion, replication, delivery guarantee,
165    /// and state store. Read-only and fully offline (no source is touched).
166    Explain(ExplainArgs),
167    /// Show recent run history recorded in a config's `catalog:` store —
168    /// status, duration, throughput, and bookmark. Read-only; requires the
169    /// `catalog` build feature.
170    #[cfg(feature = "catalog")]
171    History(HistoryArgs),
172}
173
174/// `faucet migrate` arguments.
175#[derive(Debug, Args)]
176pub struct MigrateArgs {
177    /// Config file to migrate. Auto-discovered (`faucet.yaml` → `.yml` →
178    /// `.json`) when omitted.
179    #[arg(value_hint = clap::ValueHint::FilePath)]
180    pub config: Option<PathBuf>,
181    /// Report whether a migration is needed without writing (exits non-zero if
182    /// the config is not current). For CI / pre-upgrade checks.
183    #[arg(long)]
184    pub check: bool,
185    /// Write the migrated config to stdout instead of rewriting the file.
186    #[arg(long, conflicts_with = "check")]
187    pub stdout: bool,
188}
189
190/// `faucet fmt` arguments.
191#[derive(Debug, Args)]
192pub struct FmtArgs {
193    /// Config file(s) to format. Auto-discovered (`faucet.yaml` → `.yml` →
194    /// `.json`) when none are given.
195    #[arg(value_hint = clap::ValueHint::FilePath)]
196    pub configs: Vec<PathBuf>,
197    /// Report whether each file is already canonical without writing (exits
198    /// non-zero and prints a unified diff for any file that is not). For CI.
199    #[arg(long)]
200    pub check: bool,
201    /// Write the formatted result to stdout instead of rewriting the file(s).
202    #[arg(long, conflicts_with = "check")]
203    pub stdout: bool,
204}
205
206/// `faucet explain` arguments.
207#[derive(Debug, Args)]
208pub struct ExplainArgs {
209    /// Path to a `.yaml`/`.yml`/`.json` config (auto-discovered if omitted).
210    pub config: Option<PathBuf>,
211    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
212    /// Defaults to `.env` in cwd if present.
213    #[arg(long, conflicts_with = "no_env_file")]
214    pub env_file: Option<PathBuf>,
215    /// Skip auto-loading `.env` from cwd.
216    #[arg(long)]
217    pub no_env_file: bool,
218    /// Select a named overlay from the config's `profiles:` block.
219    #[arg(long, env = "FAUCET_PROFILE")]
220    pub profile: Option<String>,
221    /// Emit the narration as structured JSON instead of prose.
222    #[arg(long)]
223    pub json: bool,
224    /// Narrate every matrix row instead of summarizing a large matrix.
225    #[arg(long)]
226    pub rows: bool,
227}
228
229/// `faucet history` arguments.
230#[cfg(feature = "catalog")]
231#[derive(Debug, Args)]
232pub struct HistoryArgs {
233    /// Path to a config carrying a `catalog:` block (auto-discovered if omitted).
234    pub config: Option<PathBuf>,
235    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
236    #[arg(long, conflicts_with = "no_env_file")]
237    pub env_file: Option<PathBuf>,
238    /// Skip auto-loading `.env` from cwd.
239    #[arg(long)]
240    pub no_env_file: bool,
241    /// Select a named overlay from the config's `profiles:` block.
242    #[arg(long, env = "FAUCET_PROFILE")]
243    pub profile: Option<String>,
244    /// Maximum number of runs to show, newest first.
245    #[arg(long, default_value_t = 20)]
246    pub limit: usize,
247    /// Show only runs that contain an invocation for this matrix row id.
248    #[arg(long)]
249    pub row: Option<String>,
250    /// Emit the history as JSON instead of a table.
251    #[arg(long)]
252    pub json: bool,
253}
254
255/// `faucet completions` arguments.
256#[derive(Debug, Args)]
257pub struct CompletionsArgs {
258    /// Target shell.
259    pub shell: clap_complete::aot::Shell,
260}
261
262/// `faucet catalog` arguments.
263#[cfg(feature = "catalog")]
264#[derive(Debug, Parser)]
265pub struct CatalogArgs {
266    #[command(subcommand)]
267    pub command: CatalogCommand,
268}
269
270/// `faucet catalog` subcommands.
271#[cfg(feature = "catalog")]
272#[derive(Debug, Subcommand)]
273pub enum CatalogCommand {
274    /// List every catalogued dataset (newest activity first).
275    Datasets(CatalogDatasetsArgs),
276    /// Show one dataset's detail: schema timeline, volume points, edges.
277    Show(CatalogShowArgs),
278    /// Print the dataset lineage graph (optionally rooted at a dataset).
279    Lineage(CatalogLineageArgs),
280}
281
282/// Shared config-loading flags for the `faucet catalog` subcommands.
283#[cfg(feature = "catalog")]
284#[derive(Debug, Parser)]
285pub struct CatalogConfigArgs {
286    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a
287    /// `catalog:` block naming the store. If omitted, auto-discover
288    /// `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
289    #[arg(long)]
290    pub config: Option<PathBuf>,
291    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
292    /// Defaults to `.env` in cwd if present.
293    #[arg(long, conflicts_with = "no_env_file")]
294    pub env_file: Option<PathBuf>,
295    /// Skip auto-loading `.env` from cwd.
296    #[arg(long)]
297    pub no_env_file: bool,
298    /// Select a named overlay from the config's `profiles:` block.
299    /// Overrides the `FAUCET_PROFILE` env var.
300    #[arg(long, env = "FAUCET_PROFILE")]
301    pub profile: Option<String>,
302    /// Emit machine-readable JSON instead of the human summary.
303    #[arg(long)]
304    pub json: bool,
305}
306
307/// `faucet catalog datasets` arguments.
308#[cfg(feature = "catalog")]
309#[derive(Debug, Parser)]
310pub struct CatalogDatasetsArgs {
311    #[command(flatten)]
312    pub common: CatalogConfigArgs,
313    /// Only datasets of this connector kind (e.g. `postgres`, `csv`).
314    #[arg(long)]
315    pub kind: Option<String>,
316    /// Case-insensitive substring match on the dataset URI.
317    #[arg(long)]
318    pub q: Option<String>,
319    /// Max datasets to list.
320    #[arg(long, default_value_t = 100)]
321    pub limit: usize,
322}
323
324/// `faucet catalog show <id>` arguments.
325#[cfg(feature = "catalog")]
326#[derive(Debug, Parser)]
327pub struct CatalogShowArgs {
328    /// Dataset id (from `faucet catalog datasets`), or a unique prefix of one.
329    pub id: String,
330    #[command(flatten)]
331    pub common: CatalogConfigArgs,
332}
333
334/// `faucet catalog lineage` arguments.
335#[cfg(feature = "catalog")]
336#[derive(Debug, Parser)]
337pub struct CatalogLineageArgs {
338    #[command(flatten)]
339    pub common: CatalogConfigArgs,
340    /// Dataset id to root the graph at (whole graph when omitted).
341    #[arg(long)]
342    pub root: Option<String>,
343    /// BFS hop bound around --root.
344    #[arg(long, default_value_t = 5)]
345    pub depth: u32,
346}
347
348/// `faucet template` arguments (#444).
349#[cfg(feature = "templates")]
350#[derive(Debug, Parser)]
351pub struct TemplateArgs {
352    #[command(subcommand)]
353    pub command: TemplateCommand,
354}
355
356/// `faucet template` subcommands.
357#[cfg(feature = "templates")]
358#[derive(Debug, Subcommand)]
359pub enum TemplateCommand {
360    /// Validate a config and register it as a new template version.
361    Register(TemplateRegisterArgs),
362    /// List registered templates (newest version of each, plus its release state).
363    List(TemplateListArgs),
364    /// Show one template: its params, config body, and versions.
365    Show(TemplateShowArgs),
366    /// Make a version live — what unpinned runs will use. The one action that
367    /// moves existing callers; registering a build never does.
368    Launch(TemplateLaunchArgs),
369    /// Re-launch the previously launched version.
370    Rollback(TemplateRollbackArgs),
371    /// Retire a template (or revive one with `--undo`).
372    Deprecate(TemplateDeprecateArgs),
373    /// Point a named environment channel (`prod`, `staging`, …) at a version.
374    Promote(TemplatePromoteArgs),
375    /// Delete one version, or every version, of a template.
376    Delete(TemplateDeleteArgs),
377    /// Materialize a template with the given params and run it locally.
378    Run(TemplateRunArgs),
379}
380
381/// Where the template registry lives — shared by every `faucet template`
382/// subcommand.
383#[cfg(feature = "templates")]
384#[derive(Debug, Parser)]
385pub struct TemplateStoreArgs {
386    /// Registry store URL: `sqlite:<path>`, a `postgres://…` URL, or `memory`
387    /// (process-lifetime only — useful for a smoke test). Point
388    /// `faucet serve --history` at the same URL to trigger these templates over
389    /// HTTP. SQL backends need the matching `serve-history-sqlite` /
390    /// `serve-history-postgres` build feature.
391    #[arg(long, env = "FAUCET_TEMPLATE_STORE")]
392    pub store: String,
393    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
394    /// Defaults to `.env` in cwd if present.
395    #[arg(long, conflicts_with = "no_env_file")]
396    pub env_file: Option<PathBuf>,
397    /// Skip auto-loading `.env` from cwd.
398    #[arg(long)]
399    pub no_env_file: bool,
400    /// Emit machine-readable JSON instead of the human summary.
401    #[arg(long)]
402    pub json: bool,
403}
404
405/// `faucet template register <config>` arguments.
406#[cfg(feature = "templates")]
407#[derive(Debug, Parser)]
408pub struct TemplateRegisterArgs {
409    /// Path to the `.yaml`, `.yml`, or `.json` config to register. Stored
410    /// verbatim, so `${env:…}` / `${vault:…}` stay unresolved and are resolved
411    /// when a run is triggered.
412    #[arg(value_hint = clap::ValueHint::FilePath)]
413    pub config: PathBuf,
414    /// Registry id. Derived from the config's `name:` when omitted.
415    #[arg(long)]
416    pub id: Option<String>,
417    /// Free-text description shown by `list` / `show`.
418    #[arg(long)]
419    pub description: Option<String>,
420    /// Point a named channel at the newly registered version, e.g.
421    /// `--tag dev --tag test`. The version number itself always auto-increments;
422    /// channels come from a fixed set (`dev`, `test`, `staging`, `pre-prod`,
423    /// `canary`, `stable`, `prod`, `previous`). `latest` is derived and always
424    /// names the newest version, so it cannot be assigned.
425    #[arg(long = "tag", value_name = "CHANNEL")]
426    pub tag: Vec<String>,
427    /// Launch the new version immediately, making it the one unpinned runs use.
428    /// Without this the version is registered but inert — a new build never moves
429    /// existing callers until you launch it.
430    #[arg(long)]
431    pub launch: bool,
432    #[command(flatten)]
433    pub common: TemplateStoreArgs,
434}
435
436/// `faucet template promote <id>` arguments.
437#[cfg(feature = "templates")]
438#[derive(Debug, Parser)]
439pub struct TemplatePromoteArgs {
440    /// Template id.
441    pub id: String,
442    /// Channel to move: `dev`, `test`, `staging`, `pre-prod`, `canary`, or
443    /// `prod`. The derived channels (`stable`, `previous`, `newest`) cannot be
444    /// promoted — `stable` moves with `faucet template launch`.
445    #[arg(long = "tag", value_name = "CHANNEL")]
446    pub tag: String,
447    /// What to point it at: a version number, or another channel whose current
448    /// target should be copied (`--tag prod --version pre-prod`). Defaults to
449    /// `stable`, the currently launched version.
450    #[arg(long, default_value = "stable")]
451    pub version: String,
452    #[command(flatten)]
453    pub common: TemplateStoreArgs,
454}
455
456/// `faucet template launch <id>` arguments.
457#[cfg(feature = "templates")]
458#[derive(Debug, Parser)]
459pub struct TemplateLaunchArgs {
460    /// Template id.
461    pub id: String,
462    /// Which version to make live: a number, or a channel whose current target to
463    /// copy (`--version pre-prod` launches whatever passed pre-prod). Defaults to
464    /// `newest` — launching what you just registered is the common case.
465    #[arg(long, default_value = "newest")]
466    pub version: String,
467    #[command(flatten)]
468    pub common: TemplateStoreArgs,
469}
470
471/// `faucet template rollback <id>` arguments.
472#[cfg(feature = "templates")]
473#[derive(Debug, Parser)]
474pub struct TemplateRollbackArgs {
475    /// Template id.
476    pub id: String,
477    #[command(flatten)]
478    pub common: TemplateStoreArgs,
479}
480
481/// `faucet template deprecate <id>` arguments.
482#[cfg(feature = "templates")]
483#[derive(Debug, Parser)]
484pub struct TemplateDeprecateArgs {
485    /// Template id.
486    pub id: String,
487    /// Why it is being retired — shown to anyone who triggers it.
488    #[arg(long)]
489    pub reason: Option<String>,
490    /// Revive a deprecated template instead of retiring it.
491    #[arg(long)]
492    pub undo: bool,
493    #[command(flatten)]
494    pub common: TemplateStoreArgs,
495}
496
497/// `faucet template list` arguments.
498#[cfg(feature = "templates")]
499#[derive(Debug, Parser)]
500pub struct TemplateListArgs {
501    #[command(flatten)]
502    pub common: TemplateStoreArgs,
503}
504
505/// `faucet template show <id>` arguments.
506#[cfg(feature = "templates")]
507#[derive(Debug, Parser)]
508pub struct TemplateShowArgs {
509    /// Template id.
510    pub id: String,
511    /// Version to show: a number, or a named channel (`stable` — the default,
512    /// i.e. the launched version — `newest`, `previous`, `prod`, `dev`, …).
513    #[arg(long, default_value = "stable")]
514    pub version: String,
515    #[command(flatten)]
516    pub common: TemplateStoreArgs,
517}
518
519/// `faucet template delete <id>` arguments.
520#[cfg(feature = "templates")]
521#[derive(Debug, Parser)]
522pub struct TemplateDeleteArgs {
523    /// Template id.
524    pub id: String,
525    /// Delete only this version — a number, or a named channel (`latest`,
526    /// `prod`, …) resolved to the version it points at. Omitted = delete every
527    /// version of the template.
528    #[arg(long)]
529    pub version: Option<String>,
530    #[command(flatten)]
531    pub common: TemplateStoreArgs,
532}
533
534/// `faucet template run <id>` arguments.
535#[cfg(feature = "templates")]
536#[derive(Debug, Parser)]
537pub struct TemplateRunArgs {
538    /// Template id.
539    pub id: String,
540    /// Version to run: a number, or a named channel. Defaults to `stable` — the
541    /// launched version — so an unpinned run never picks up a build that has not
542    /// been launched. Use `newest` to run the most recent build regardless.
543    #[arg(long, default_value = "stable")]
544    pub version: String,
545    /// Supply a declared param: `--param tenant_id=acme`. Repeatable.
546    #[arg(long = "param", value_name = "NAME=VALUE")]
547    pub param: Vec<String>,
548    /// Override an environment variable for this materialization only:
549    /// `--param-env REGION=eu`, or bare `--param-env TOKEN` to take it from the
550    /// caller's environment. Repeatable.
551    #[arg(long = "param-env", value_name = "NAME[=VALUE]")]
552    pub param_env: Vec<String>,
553    /// Materialize and validate without running (prints the resolved config).
554    #[arg(long)]
555    pub dry_run: bool,
556    /// Stop after writing this many records to the sink.
557    #[arg(long)]
558    pub limit: Option<usize>,
559    #[command(flatten)]
560    pub common: TemplateStoreArgs,
561}
562
563/// `faucet notify test` arguments.
564#[cfg(feature = "notify")]
565#[derive(Debug, Parser)]
566pub struct NotifyArgs {
567    #[command(subcommand)]
568    pub command: NotifyCommand,
569}
570
571/// `faucet notify` subcommands.
572#[cfg(feature = "notify")]
573#[derive(Debug, Subcommand)]
574pub enum NotifyCommand {
575    /// Fire one synthetic event at every matching rule in the config.
576    Test(NotifyTestArgs),
577}
578
579/// `faucet notify test <config>` arguments.
580#[cfg(feature = "notify")]
581#[derive(Debug, Parser)]
582pub struct NotifyTestArgs {
583    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a
584    /// `notifications:` block. If omitted, auto-discover in cwd.
585    pub config: Option<PathBuf>,
586    /// Which event to synthesize (defaults to `run_failure`).
587    #[arg(long, default_value = "run_failure")]
588    pub event: String,
589    /// Path to a `.env` file for `${env:VAR}` interpolation.
590    #[arg(long, conflicts_with = "no_env_file")]
591    pub env_file: Option<PathBuf>,
592    /// Disable `.env` auto-discovery.
593    #[arg(long)]
594    pub no_env_file: bool,
595}
596
597/// `faucet test` arguments.
598#[derive(Debug, Parser)]
599pub struct TestArgs {
600    /// One or more test-spec files (`.yaml`, `.yml`, or `.json`), e.g.
601    /// `faucet test tests/*.yaml`.
602    #[arg(required = true)]
603    pub specs: Vec<PathBuf>,
604    /// Run only cases whose name contains this substring.
605    #[arg(long)]
606    pub filter: Option<String>,
607    /// Emit a machine-readable JSON report instead of the human checklist.
608    #[arg(long)]
609    pub json: bool,
610    /// Default `${now.*}` clock for cases without their own `clock:` field
611    /// (RFC3339 like `2026-01-31T00:00:00Z`, or a date `2026-01-31`).
612    /// Defaults to process start (UTC).
613    #[arg(long)]
614    pub clock: Option<String>,
615    /// Path to a `.env` file to load for `${env:VAR}` interpolation in
616    /// referenced pipeline configs. Defaults to `.env` in cwd if present.
617    #[arg(long, conflicts_with = "no_env_file")]
618    pub env_file: Option<PathBuf>,
619    /// Skip auto-loading `.env` from cwd.
620    #[arg(long)]
621    pub no_env_file: bool,
622    /// Select a named overlay from each referenced config's `profiles:` block.
623    /// Overrides the `FAUCET_PROFILE` env var.
624    #[arg(long, env = "FAUCET_PROFILE")]
625    pub profile: Option<String>,
626    /// Resolve `${vault:…}` / `${aws-sm:…}` / … secret directives in
627    /// referenced configs (requires network + credentials). By default tests
628    /// load configs offline and leave secret directives unresolved — safe
629    /// because the real source/sink configs holding them are never used.
630    #[arg(long)]
631    pub resolve_secrets: bool,
632}
633
634/// `faucet dlq` arguments.
635#[derive(Debug, Parser)]
636pub struct DlqArgs {
637    #[command(subcommand)]
638    pub command: DlqCommand,
639}
640
641/// `faucet dlq` subcommands.
642#[derive(Debug, Subcommand)]
643pub enum DlqCommand {
644    /// Read a DLQ location back and print a per-reason / per-error-kind
645    /// breakdown plus a sample of quarantined records.
646    Inspect(DlqInspectArgs),
647    /// Re-feed quarantined records through a pipeline config (transforms →
648    /// quality → contract → sink). Rows that fail again land in a *fresh* DLQ.
649    Replay(DlqReplayArgs),
650    /// Remove processed envelopes from a DLQ location (archive by default,
651    /// or `--delete`), filtered by reason and/or age.
652    Discard(DlqDiscardArgs),
653}
654
655/// `faucet dlq inspect <location>` arguments.
656#[derive(Debug, Parser)]
657pub struct DlqInspectArgs {
658    /// DLQ location: a `.jsonl` file, a directory of `*.jsonl` files, or a glob.
659    pub location: String,
660    /// Only include envelopes with this DLQ reason (`partial` / `dlq_all` /
661    /// `quality` / `schema_drift` / `contract`).
662    #[arg(long)]
663    pub reason: Option<String>,
664    /// Number of sample records to show. Default: 5.
665    #[arg(long, default_value_t = 5)]
666    pub limit: usize,
667    /// Key for a DLQ sealed at rest by the jsonl sink's `encryption` block.
668    /// Repeat the flag to also try older (rotated) keys. Requires a build
669    /// with the `encryption` feature.
670    #[arg(long = "encryption-key")]
671    pub encryption_key: Vec<String>,
672    /// Emit a machine-readable JSON summary instead of the human report.
673    #[arg(long)]
674    pub json: bool,
675}
676
677/// `faucet dlq replay <config> --from <location>` arguments.
678#[derive(Debug, Parser)]
679pub struct DlqReplayArgs {
680    /// Path to the pipeline config whose sink / transforms / quality / contract
681    /// the replayed records flow through. If omitted, auto-discover in cwd.
682    pub config: Option<PathBuf>,
683    /// DLQ location to replay from: a `.jsonl` file, a directory, or a glob.
684    #[arg(long)]
685    pub from: String,
686    /// Only replay envelopes with this DLQ reason.
687    #[arg(long)]
688    pub reason: Option<String>,
689    /// Where replayed rows that fail *again* are quarantined. Defaults to a
690    /// `replay-failed.jsonl` sibling of the source (never the source itself).
691    #[arg(long)]
692    pub failed_dlq: Option<String>,
693    /// Which root row of the config to replay through. Defaults to the first root.
694    #[arg(long)]
695    pub row: Option<String>,
696    /// Report what would be replayed without writing to the sink.
697    #[arg(long)]
698    pub dry_run: bool,
699    /// Key for a DLQ sealed at rest by the jsonl sink's `encryption` block.
700    /// Repeat the flag to also try older (rotated) keys. Requires a build
701    /// with the `encryption` feature.
702    #[arg(long = "encryption-key")]
703    pub encryption_key: Vec<String>,
704    /// (Replay picks up the config's own dlq `encryption` block automatically
705    /// when no key is passed.)
706    /// Emit a machine-readable JSON result instead of the human summary.
707    #[arg(long)]
708    pub json: bool,
709    /// Path to a `.env` file for `${env:VAR}` interpolation in the config.
710    #[arg(long, conflicts_with = "no_env_file")]
711    pub env_file: Option<PathBuf>,
712    /// Skip auto-loading `.env` from cwd.
713    #[arg(long)]
714    pub no_env_file: bool,
715    /// Select a named overlay from the config's `profiles:` block.
716    #[arg(long, env = "FAUCET_PROFILE")]
717    pub profile: Option<String>,
718}
719
720/// `faucet dlq discard <location>` arguments.
721#[derive(Debug, Parser)]
722pub struct DlqDiscardArgs {
723    /// DLQ location: a `.jsonl` file, a directory of `*.jsonl` files, or a glob.
724    pub location: String,
725    /// Only discard envelopes with this DLQ reason.
726    #[arg(long)]
727    pub reason: Option<String>,
728    /// Only discard envelopes older than this: an RFC3339 timestamp
729    /// (`2026-06-01T00:00:00Z`) or a relative age (`7d`, `24h`, `30m`).
730    #[arg(long)]
731    pub before: Option<String>,
732    /// Permanently delete matching envelopes instead of archiving them to a
733    /// `<file>.archived.jsonl` sibling.
734    #[arg(long)]
735    pub delete: bool,
736    /// Key for a DLQ sealed at rest by the jsonl sink's `encryption` block.
737    /// Repeat the flag to also try older (rotated) keys. Requires a build
738    /// with the `encryption` feature.
739    #[arg(long = "encryption-key")]
740    pub encryption_key: Vec<String>,
741    /// Emit a machine-readable JSON result instead of the human summary.
742    #[arg(long)]
743    pub json: bool,
744}
745
746/// `faucet doctor` arguments.
747#[derive(Debug, Parser)]
748pub struct DoctorArgs {
749    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config. If omitted,
750    /// auto-discover `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
751    pub config: Option<PathBuf>,
752    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
753    /// Defaults to `.env` in cwd if present.
754    #[arg(long, conflicts_with = "no_env_file")]
755    pub env_file: Option<PathBuf>,
756    /// Skip auto-loading `.env` from cwd.
757    #[arg(long)]
758    pub no_env_file: bool,
759    /// Per-probe timeout in seconds.
760    #[arg(long, default_value_t = 10)]
761    pub timeout_secs: u64,
762    /// Emit machine-readable JSON instead of the human checklist.
763    #[arg(long)]
764    pub json: bool,
765    /// Run only the offline static config lints (no network probes): dangling /
766    /// unreferenced `auth:` providers, unused `vars:`, and no-op sink
767    /// `batch_size: 0`. Fast and credential-free — ideal for CI. Exits non-zero
768    /// on any lint *error* (warnings don't fail).
769    #[arg(long)]
770    pub offline: bool,
771    /// Select a named overlay from the config's `profiles:` block and deep-merge
772    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
773    #[arg(long, env = "FAUCET_PROFILE")]
774    pub profile: Option<String>,
775}
776
777/// `faucet contract` arguments.
778#[cfg(feature = "contract")]
779#[derive(Debug, Parser)]
780pub struct ContractArgs {
781    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a
782    /// `pipeline.contract:` block. If omitted, auto-discover
783    /// `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
784    pub config: Option<PathBuf>,
785    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
786    /// Defaults to `.env` in cwd if present.
787    #[arg(long, conflicts_with = "no_env_file")]
788    pub env_file: Option<PathBuf>,
789    /// Skip auto-loading `.env` from cwd.
790    #[arg(long)]
791    pub no_env_file: bool,
792    /// Select a named overlay from the config's `profiles:` block and deep-merge
793    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
794    #[arg(long, env = "FAUCET_PROFILE")]
795    pub profile: Option<String>,
796    /// Export the contract in a machine-readable format instead of the
797    /// human summary: the canonical contract JSON, a standalone JSON Schema,
798    /// or an OpenLineage schema facet.
799    #[arg(long, value_enum)]
800    pub export: Option<ContractExportFormat>,
801}
802
803/// Arguments for `faucet masking`.
804#[cfg(feature = "masking")]
805#[derive(Debug, Parser)]
806pub struct MaskingArgs {
807    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a
808    /// `pipeline.masking:` block. If omitted, auto-discover
809    /// `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
810    pub config: Option<PathBuf>,
811    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
812    /// Defaults to `.env` in cwd if present.
813    #[arg(long, conflicts_with = "no_env_file")]
814    pub env_file: Option<PathBuf>,
815    /// Skip auto-loading `.env` from cwd.
816    #[arg(long)]
817    pub no_env_file: bool,
818    /// Select a named overlay from the config's `profiles:` block and deep-merge
819    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
820    #[arg(long, env = "FAUCET_PROFILE")]
821    pub profile: Option<String>,
822}
823
824/// Export format for `faucet contract --export`.
825#[cfg(feature = "contract")]
826#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
827pub enum ContractExportFormat {
828    /// The canonical contract document as JSON.
829    Contract,
830    /// A standalone JSON Schema (draft 2020-12) for the promised records.
831    JsonSchema,
832    /// An OpenLineage `SchemaDatasetFacet` JSON document.
833    Openlineage,
834}
835
836/// `faucet schedule` arguments.
837#[cfg(feature = "schedule")]
838#[derive(Debug, Parser)]
839pub struct ScheduleArgs {
840    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a `schedule:`
841    /// block. If omitted, auto-discover `faucet.yaml` / `.yml` / `.json` in cwd.
842    pub config: Option<PathBuf>,
843    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
844    /// Defaults to `.env` in cwd if present.
845    #[arg(long, conflicts_with = "no_env_file")]
846    pub env_file: Option<PathBuf>,
847    /// Skip auto-loading `.env` from cwd.
848    #[arg(long)]
849    pub no_env_file: bool,
850    /// Run exactly one pipeline run immediately, then exit (ignores cron timing).
851    /// Useful for platform-driven invocation (k8s CronJob / systemd OnCalendar).
852    #[arg(long)]
853    pub once: bool,
854    /// Select a named overlay from the config's `profiles:` block and deep-merge
855    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
856    #[arg(long, env = "FAUCET_PROFILE")]
857    pub profile: Option<String>,
858}
859
860/// `faucet serve` arguments.
861#[cfg(feature = "serve")]
862#[derive(Debug, Clone, Parser)]
863pub struct ServeArgs {
864    /// Bind address. Defaults to loopback; set 0.0.0.0:PORT to expose externally.
865    #[arg(long, env = "FAUCET_SERVE_LISTEN", default_value = "127.0.0.1:8080")]
866    pub listen: String,
867    /// Bearer token required on /v1/* requests. Prefer the env var (avoids `ps` leakage).
868    #[arg(long, env = "FAUCET_SERVE_AUTH_TOKEN", conflicts_with = "no_auth")]
869    pub auth_token: Option<String>,
870    /// Explicitly disable authentication. Required if no token is set, so an
871    /// unauthenticated server is never accidental.
872    #[arg(long)]
873    pub no_auth: bool,
874    /// Path to an RBAC auth config (YAML/JSON) defining principals — each a
875    /// `{ name, token, role }` where role is `viewer` / `operator` / `admin`.
876    /// Enables role-based access control + an audit log. Mutually exclusive with
877    /// `--auth-token` / `--no-auth`.
878    #[arg(long, conflicts_with_all = ["auth_token", "no_auth"])]
879    pub auth_config: Option<std::path::PathBuf>,
880    /// Max pipeline runs executing at once. Default: min(16, cpu count).
881    #[arg(long)]
882    pub max_concurrent_runs: Option<usize>,
883    /// Max queued (not-yet-running) runs before POST /v1/runs returns 429.
884    /// Default: 8 × max-concurrent-runs.
885    #[arg(long)]
886    pub max_queued_runs: Option<usize>,
887    /// Workspace-default config merged under every submitted run.
888    #[arg(long)]
889    pub default_config: Option<std::path::PathBuf>,
890    /// Run-history backend URL: omitted = in-memory; postgres://… ; sqlite:… .
891    #[arg(long)]
892    pub history: Option<String>,
893    /// CORS allow-list origin (repeatable). Omitted = CORS disabled.
894    #[arg(long)]
895    pub cors_origin: Vec<String>,
896    /// Max POST /v1/runs body size in bytes (413 on exceed).
897    #[arg(long, default_value_t = 1_048_576)]
898    pub body_limit_bytes: usize,
899    /// SIGTERM/SIGINT drain window in seconds.
900    #[arg(long, default_value_t = 60)]
901    pub shutdown_grace_secs: u64,
902    /// Retain terminal run records this long (seconds).
903    #[arg(long, default_value_t = 604_800)]
904    pub retain_terminal_runs_secs: u64,
905    /// Idempotency-key replay window (seconds).
906    #[arg(long, default_value_t = 86_400)]
907    pub idempotency_retention_secs: u64,
908    /// Run-ownership lease TTL in seconds (multi-instance orphan fencing). A run
909    /// is owned by the instance executing it and its lease is heartbeated at
910    /// ~⅓ of this interval; only a run whose lease has expired (owner presumed
911    /// dead) is recovered as failed. Make this comfortably larger than expected
912    /// GC/IO stalls so a healthy-but-slow instance is never falsely reclaimed.
913    /// Only relevant with a persistent (postgres/sqlite) history backend.
914    #[arg(long, default_value_t = 30)]
915    pub lease_ttl_secs: u64,
916    /// Per-probe timeout for `doctor_first` preflight (seconds).
917    #[arg(long, default_value_t = 10)]
918    pub probe_timeout_secs: u64,
919    /// Path to a `.env` file loaded for the server's own startup interpolation.
920    #[arg(long, conflicts_with = "no_env_file")]
921    pub env_file: Option<std::path::PathBuf>,
922    /// Skip auto-loading `.env` from cwd at startup.
923    #[arg(long)]
924    pub no_env_file: bool,
925    /// Disable serving the embedded web console (only meaningful in a build that
926    /// includes the `serve-ui` feature; the API is unaffected).
927    #[arg(long)]
928    pub no_ui: bool,
929    /// Enable clustered execution: run a claim loop that pulls Pending runs from
930    /// the shared history DB so N instances pull-balance and fail over. Requires
931    /// a postgres/sqlite --history backend.
932    #[arg(long)]
933    pub cluster: bool,
934    /// Claim-loop poll interval (seconds) in cluster mode. Also the
935    /// cross-instance cancel-propagation lag. Must be > 0.
936    #[arg(long, default_value_t = 2)]
937    pub cluster_poll_secs: u64,
938    /// Max failover re-runs of an orphaned run before it is marked Failed
939    /// (poison). Must be > 0.
940    #[arg(long, default_value_t = 3)]
941    pub cluster_max_attempts: u32,
942    /// Path to a triggers file (YAML/JSON) defining event-driven pipeline
943    /// triggers (object-arrival / webhook / queue-depth). Requires a build with
944    /// the `triggers` feature. See `faucet schema triggers`.
945    #[arg(long)]
946    pub triggers: Option<std::path::PathBuf>,
947    /// Mount the MCP (Model Context Protocol) endpoint at `/mcp`, exposing
948    /// faucet as agent tool calls. Effective only in a build with the `mcp`
949    /// feature; the endpoint inherits serve's bearer-auth + RBAC + audit.
950    #[arg(long)]
951    pub mcp: bool,
952    /// Allow the MCP endpoint's *mutating* tools (`run_pipeline`). Off by
953    /// default: only read-only tools are exposed. A caller still needs the
954    /// `RunWrite` RBAC scope. Only meaningful together with `--mcp`.
955    #[arg(long)]
956    pub mcp_allow_mutations: bool,
957}
958
959/// `faucet mcp` arguments — run an MCP server over stdio (#420).
960#[cfg(feature = "mcp")]
961#[derive(Debug, Clone, Parser)]
962pub struct McpArgs {
963    /// Allow mutating tools (`run_pipeline`). Off by default — only read-only
964    /// tools (list / schema / scaffold / validate / preview) are exposed.
965    /// stdio is local-trust: there is no bearer/RBAC layer, so enable this only
966    /// for a trusted local agent.
967    #[arg(long)]
968    pub allow_mutations: bool,
969    /// Optional `.env` file to load before starting (for `${env:…}` in configs
970    /// passed to `validate`/`preview`/`run_pipeline`).
971    #[arg(long, conflicts_with = "no_env_file")]
972    pub env_file: Option<std::path::PathBuf>,
973    /// Skip auto-loading `.env` from cwd at startup.
974    #[arg(long)]
975    pub no_env_file: bool,
976    /// Pipeline-template registry to expose (#444): `sqlite:<path>`, a
977    /// `postgres://…` URL, or `memory`. Enables the `list_templates` /
978    /// `get_template` tools (plus `register_template` / `run_template` with
979    /// `--allow-mutations`). Omitted = no template tools are advertised.
980    #[cfg(feature = "templates")]
981    #[arg(long, env = "FAUCET_TEMPLATE_STORE")]
982    pub template_store: Option<String>,
983}
984
985/// `faucet run` arguments.
986///
987/// `Default` is derived so callers that execute an already-loaded config through
988/// `commands::run::execute` (notably `faucet template run`) can build a
989/// plain-run argument set without restating every flag.
990#[derive(Debug, Parser, Default)]
991pub struct RunArgs {
992    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config.
993    /// If omitted (and `--from-env` is not set), auto-discover
994    /// `faucet.yaml` / `faucet.yml` / `faucet.json` in the current directory.
995    /// Mutually exclusive with `--from-env`.
996    #[arg(conflicts_with = "from_env")]
997    pub config: Option<PathBuf>,
998    /// Build the pipeline entirely from `FAUCET_*` environment variables —
999    /// no YAML required. See `cli/README.md` for the variable schema.
1000    #[arg(long)]
1001    pub from_env: bool,
1002    /// Path to a `.env` file to load before reading variables. Works in both
1003    /// YAML mode (for `${env:VAR}` interpolation) and `--from-env` mode.
1004    /// When omitted, `.env` in the current directory is auto-loaded if present.
1005    /// Existing process-env values always win over file-supplied ones.
1006    #[arg(long, conflicts_with = "no_env_file")]
1007    pub env_file: Option<PathBuf>,
1008    /// Skip auto-loading `.env` from the current directory.
1009    #[arg(long)]
1010    pub no_env_file: bool,
1011    /// Stop after fetching from the source — write nothing to the sink.
1012    #[arg(long)]
1013    pub dry_run: bool,
1014    /// Stop after writing this many records to the sink. Default: unlimited.
1015    #[arg(long)]
1016    pub limit: Option<usize>,
1017    /// Override the state-store directory (file backend only).
1018    #[arg(long)]
1019    pub state_path: Option<PathBuf>,
1020    /// Override the `${now.*}` interpolation clock (RFC3339 like
1021    /// `2026-01-31T00:00:00Z`, or a date `2026-01-31`). Default: process start (UTC).
1022    /// Use for backfills.
1023    #[arg(long)]
1024    pub clock: Option<String>,
1025    /// Select a named overlay from the config's `profiles:` block and deep-merge
1026    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
1027    /// Not applicable in `--from-env` mode (no config file to compose).
1028    #[arg(long, env = "FAUCET_PROFILE")]
1029    pub profile: Option<String>,
1030    /// Show a live full-screen terminal UI (per-invocation throughput, errors,
1031    /// DLQ counts, bookmark age) while the pipeline runs. Requires a binary
1032    /// built with the `cli-tui` feature and a real terminal on stdout —
1033    /// on a non-TTY (CI, pipes) the run proceeds normally with a notice.
1034    /// Press `q` to cancel cooperatively (in-flight work flushes at the next
1035    /// page boundary).
1036    #[arg(long)]
1037    pub tui: bool,
1038
1039    /// Suppress the inline live progress line (records in/out, rows/s, pages,
1040    /// elapsed) that `faucet run` shows on an interactive terminal. The
1041    /// progress line is already auto-disabled on a non-TTY stdout (CI, pipes)
1042    /// and when `--tui` is used; `--quiet` turns it off explicitly, keeping
1043    /// only the periodic log output.
1044    #[arg(long)]
1045    pub quiet: bool,
1046
1047    /// Format for the end-of-run summary: `text` (default, human — written to
1048    /// **stderr** so stdout stays clean for the sink), `json` (a single
1049    /// machine-readable document on **stdout**), or `ndjson` (one JSON object
1050    /// per matrix row on **stdout**). With `json`/`ndjson`, stdout carries only
1051    /// the summary — logs stay on stderr — so `faucet run` is scriptable.
1052    #[arg(long, value_enum, default_value_t = RunOutput::Text)]
1053    pub output: RunOutput,
1054
1055    /// Supply a value for a `params:` entry declared by the config (#444):
1056    /// `--param tenant_id=acme`. Repeatable. Values are coerced to the declared
1057    /// type, so `--param page=50` satisfies a `type: int` param. A param with a
1058    /// `default` needs no flag; a `required` one errors when unsupplied.
1059    #[arg(long = "param", value_name = "NAME=VALUE")]
1060    pub param: Vec<String>,
1061
1062    /// Override an environment variable for this run's `${env:VAR}` resolution
1063    /// only (#444): `--param-env REGION=eu` sets it, bare `--param-env TOKEN`
1064    /// takes the value from the caller's environment. Repeatable. The process
1065    /// environment is not modified.
1066    #[arg(long = "param-env", value_name = "NAME[=VALUE]")]
1067    pub param_env: Vec<String>,
1068
1069    /// Runtime matrix-row selection (`--select`/`--only`/`--skip`/`--status`/
1070    /// `--tag`/`--include-parents`).
1071    #[command(flatten)]
1072    pub selection: SelectionArgs,
1073}
1074
1075/// Format for `faucet run`'s end-of-run summary.
1076#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, clap::ValueEnum)]
1077pub enum RunOutput {
1078    /// Human-readable one-line summary (default).
1079    #[default]
1080    Text,
1081    /// A single machine-readable JSON document with per-row + total stats.
1082    Json,
1083    /// One JSON object per matrix row (newline-delimited) for streaming consumers.
1084    Ndjson,
1085}
1086
1087/// `faucet backfill` arguments.
1088#[derive(Debug, Parser)]
1089pub struct BackfillArgs {
1090    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config. If omitted,
1091    /// auto-discover `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
1092    pub config: Option<PathBuf>,
1093    /// Window start (inclusive): RFC3339 (`2026-06-01T00:00:00Z`) or a date
1094    /// (`2026-06-01`, midnight in --timezone). Requires --to.
1095    #[arg(long, requires = "to", conflicts_with = "from_bookmark")]
1096    pub from: Option<String>,
1097    /// Window end (exclusive): RFC3339 or a date.
1098    #[arg(long, requires = "from", conflicts_with = "from_bookmark")]
1099    pub to: Option<String>,
1100    /// Chunk the range into windows of this duration (`45s`, `30m`, `6h`,
1101    /// `1d`, `1w`) so each chunk is an independent, resumable unit. Defaults
1102    /// to the config's `backfill.window`; omitted = one unit for the whole
1103    /// range.
1104    #[arg(long)]
1105    pub window: Option<String>,
1106    /// Replay from this explicit bookmark value instead of a wall-clock
1107    /// range (seeded into the backfill's scoped state key; the source's own
1108    /// incremental logic reads forward from it). JSON or a bare string.
1109    #[arg(long)]
1110    pub from_bookmark: Option<String>,
1111    /// Upper bookmark bound: records whose --bookmark-field orders after
1112    /// this value are dropped before the sink.
1113    #[arg(long, requires_all = ["from_bookmark", "bookmark_field"])]
1114    pub to_bookmark: Option<String>,
1115    /// Record field the --to-bookmark bound applies to.
1116    #[arg(long)]
1117    pub bookmark_field: Option<String>,
1118    /// Max concurrently-running window units. Defaults to the config's
1119    /// `backfill.concurrency`, else 1 (sequential).
1120    #[arg(long)]
1121    pub concurrency: Option<usize>,
1122    /// IANA timezone for date boundaries and `${now.*}` rendering. Defaults
1123    /// to the config's `backfill.timezone`, else UTC.
1124    #[arg(long)]
1125    pub timezone: Option<String>,
1126    /// Root row of the config to backfill. Defaults to the only root.
1127    #[arg(long)]
1128    pub row: Option<String>,
1129    /// Redirect writes to this named sink template under `pipeline.sinks`
1130    /// (backfill into a staging table first).
1131    #[arg(long)]
1132    pub into: Option<String>,
1133    /// Print the planned units without running anything.
1134    #[arg(long)]
1135    pub dry_run: bool,
1136    /// Continue a previously-interrupted backfill of the same range: skip
1137    /// units already done, re-run failed and pending ones.
1138    #[arg(long, conflicts_with = "restart")]
1139    pub resume: bool,
1140    /// Discard a previous progress marker for this range and start over.
1141    #[arg(long)]
1142    pub restart: bool,
1143    /// Emit a machine-readable JSON report instead of the human summary.
1144    #[arg(long)]
1145    pub json: bool,
1146    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
1147    /// Defaults to `.env` in cwd if present.
1148    #[arg(long, conflicts_with = "no_env_file")]
1149    pub env_file: Option<PathBuf>,
1150    /// Skip auto-loading `.env` from cwd.
1151    #[arg(long)]
1152    pub no_env_file: bool,
1153    /// Select a named overlay from the config's `profiles:` block.
1154    /// Overrides the `FAUCET_PROFILE` env var.
1155    #[arg(long, env = "FAUCET_PROFILE")]
1156    pub profile: Option<String>,
1157}
1158
1159/// `faucet replicate` arguments.
1160#[derive(Debug, Parser)]
1161pub struct ReplicateArgs {
1162    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config with a
1163    /// `replication:` block. If omitted, auto-discover
1164    /// `faucet.yaml` / `.yml` / `.json` in cwd.
1165    pub config: Option<PathBuf>,
1166    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
1167    /// Defaults to `.env` in cwd if present.
1168    #[arg(long, conflicts_with = "no_env_file")]
1169    pub env_file: Option<PathBuf>,
1170    /// Skip auto-loading `.env` from cwd.
1171    #[arg(long)]
1172    pub no_env_file: bool,
1173    /// Select a named overlay from the config's `profiles:` block and deep-merge
1174    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
1175    #[arg(long, env = "FAUCET_PROFILE")]
1176    pub profile: Option<String>,
1177}
1178
1179/// `faucet discover` arguments.
1180#[derive(Debug, Parser)]
1181pub struct DiscoverArgs {
1182    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config whose source
1183    /// points at the system to introspect. If omitted, auto-discover
1184    /// `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
1185    pub config: Option<PathBuf>,
1186    /// Which source template to introspect (an entry under `pipeline.sources`).
1187    /// Defaults to `default` (the legacy singular `pipeline.source`).
1188    #[arg(long)]
1189    pub source: Option<String>,
1190    /// Only include datasets whose name matches this `*`-wildcard pattern
1191    /// (repeatable; no patterns = include everything).
1192    #[arg(long)]
1193    pub include: Vec<String>,
1194    /// Exclude datasets whose name matches this `*`-wildcard pattern
1195    /// (repeatable; applied after --include).
1196    #[arg(long)]
1197    pub exclude: Vec<String>,
1198    /// Write the generated config to this file instead of stdout.
1199    #[arg(long, short = 'o')]
1200    pub output: Option<PathBuf>,
1201    /// Overwrite the --output file if it already exists.
1202    #[arg(long)]
1203    pub force: bool,
1204    /// Emit the discovered datasets as machine-readable JSON instead of a
1205    /// generated config.
1206    #[arg(long)]
1207    pub json: bool,
1208    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
1209    /// Defaults to `.env` in cwd if present.
1210    #[arg(long, conflicts_with = "no_env_file")]
1211    pub env_file: Option<PathBuf>,
1212    /// Skip auto-loading `.env` from cwd.
1213    #[arg(long)]
1214    pub no_env_file: bool,
1215    /// Select a named overlay from the config's `profiles:` block.
1216    /// Overrides the `FAUCET_PROFILE` env var.
1217    #[arg(long, env = "FAUCET_PROFILE")]
1218    pub profile: Option<String>,
1219}
1220
1221/// `faucet validate` arguments.
1222#[derive(Debug, Parser)]
1223pub struct ValidateArgs {
1224    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config. If omitted,
1225    /// auto-discover `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
1226    pub config: Option<PathBuf>,
1227    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
1228    /// Defaults to `.env` in cwd if present.
1229    #[arg(long, conflicts_with = "no_env_file")]
1230    pub env_file: Option<PathBuf>,
1231    /// Skip auto-loading `.env` from cwd.
1232    #[arg(long)]
1233    pub no_env_file: bool,
1234    /// Validate grammar and structure only — skip fetching from secrets
1235    /// managers (no network / credentials needed).
1236    #[arg(long)]
1237    pub no_secrets: bool,
1238    /// Select a named overlay from the config's `profiles:` block and deep-merge
1239    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
1240    #[arg(long, env = "FAUCET_PROFILE")]
1241    pub profile: Option<String>,
1242    /// Print the fully-composed config (after extends/!include/profile, before
1243    /// `${...}` interpolation) and exit. For debugging composition precedence.
1244    /// `--no-secrets` is redundant here (no interpolation or secret fetch occurs).
1245    #[arg(long)]
1246    pub show_composed: bool,
1247
1248    /// Supply a value for a declared `params:` entry (#444), e.g.
1249    /// `--param tenant_id=acme`. Repeatable. Without any `--param`, a `required`
1250    /// param is validated against a type-shaped placeholder — so a
1251    /// parameterized config validates in CI without inventing real values.
1252    /// Passing at least one `--param` switches to strict binding, checking that
1253    /// every required param is supplied and every value has the declared type.
1254    #[arg(long = "param", value_name = "NAME=VALUE")]
1255    pub param: Vec<String>,
1256
1257    /// Override an environment variable for this validation only:
1258    /// `--param-env REGION=eu`, or bare `--param-env TOKEN` to take it from the
1259    /// caller's environment. Repeatable.
1260    #[arg(long = "param-env", value_name = "NAME[=VALUE]")]
1261    pub param_env: Vec<String>,
1262
1263    /// Runtime matrix-row selection — `validate` reports each row's resolved
1264    /// status/tags and whether the selection would run or skip it.
1265    #[command(flatten)]
1266    pub selection: SelectionArgs,
1267}
1268
1269/// `faucet schema` arguments.
1270#[derive(Debug, Parser)]
1271pub struct SchemaArgs {
1272    #[command(subcommand)]
1273    pub target: SchemaTarget,
1274}
1275
1276/// Schema subcommand target — which connector or system component to describe.
1277#[derive(Debug, Subcommand)]
1278pub enum SchemaTarget {
1279    /// Composed JSON Schema for the **entire** `faucet.yaml` / `faucet.json`
1280    /// config document (top-level grammar + per-connector `type` discrimination).
1281    /// Point an editor at it with a `# yaml-language-server: $schema=…` header.
1282    Config,
1283    /// JSON Schema for a source connector config.
1284    Source {
1285        /// Connector name (e.g. `rest`, `graphql`, `postgres`).
1286        #[arg(add = ArgValueCandidates::new(completions::source_kind_candidates))]
1287        name: String,
1288    },
1289    /// JSON Schema for a sink connector config.
1290    Sink {
1291        /// Connector name (e.g. `jsonl`, `bigquery`, `postgres`).
1292        #[arg(add = ArgValueCandidates::new(completions::sink_kind_candidates))]
1293        name: String,
1294    },
1295    /// JSON Schema for a transform's inline config.
1296    Transform {
1297        /// Transform name (e.g. `flatten`, `keys_case`, `cast`).
1298        /// Run `faucet list` to see what is compiled in.
1299        #[arg(add = ArgValueCandidates::new(completions::transform_candidates))]
1300        name: String,
1301    },
1302    /// JSON Schema for the DLQ (Dead Letter Queue) specification.
1303    Dlq,
1304    /// JSON Schema for the `replication:` (snapshot→CDC) block.
1305    Replication,
1306    /// JSON Schema for the `backfill:` (window replay defaults) block.
1307    Backfill,
1308    /// JSON Schema for the top-level `execution:` block.
1309    Execution,
1310    /// JSON Schema for the top-level `resilience:` block.
1311    Resilience,
1312    /// JSON Schema for the top-level `sla:` (freshness/volume SLA) block.
1313    Sla,
1314    /// JSON Schema for the `quality:` block.
1315    #[cfg(feature = "quality")]
1316    Quality,
1317    /// JSON Schema for the `contract:` block.
1318    #[cfg(feature = "contract")]
1319    Contract,
1320    /// JSON Schema for the `masking:` (PII masking) block.
1321    #[cfg(feature = "masking")]
1322    Masking,
1323    /// JSON Schema for the `faucet test` spec file.
1324    Test,
1325    /// Grammar reference for secrets-manager interpolation directives.
1326    Secrets,
1327    /// JSON Schema for the `schedule:` block.
1328    #[cfg(feature = "schedule")]
1329    Schedule,
1330    /// JSON Schema for the `lineage:` (OpenLineage) block.
1331    #[cfg(feature = "lineage")]
1332    Lineage,
1333    /// JSON Schema for the `--triggers` file (event-driven pipeline triggers).
1334    #[cfg(feature = "triggers")]
1335    Triggers,
1336    /// JSON Schema for the `notifications:` (incident-routing) block.
1337    #[cfg(feature = "notify")]
1338    Notifications,
1339    /// JSON Schema for the `catalog:` (Data Movement Catalog store) block.
1340    #[cfg(feature = "catalog")]
1341    Catalog,
1342    /// JSON Schema for one entry of the `params:` (typed run parameters) block.
1343    /// A config's `params:` maps names to entries of this shape; values are
1344    /// supplied per run via `--param` or a template trigger.
1345    Params,
1346}
1347
1348/// `faucet preview` arguments.
1349#[derive(Debug, Parser)]
1350pub struct PreviewArgs {
1351    /// Path to a `.yaml`, `.yml`, or `.json` pipeline config. If omitted,
1352    /// auto-discover `faucet.yaml` / `faucet.yml` / `faucet.json` in cwd.
1353    pub config: Option<PathBuf>,
1354    /// Stop after this many records. Default: 10.
1355    #[arg(long, default_value_t = 10)]
1356    pub limit: usize,
1357    /// Path to a `.env` file to load for `${env:VAR}` interpolation.
1358    /// Defaults to `.env` in cwd if present.
1359    #[arg(long, conflicts_with = "no_env_file")]
1360    pub env_file: Option<PathBuf>,
1361    /// Skip auto-loading `.env` from cwd.
1362    #[arg(long)]
1363    pub no_env_file: bool,
1364    /// Select a named overlay from the config's `profiles:` block and deep-merge
1365    /// it over the composed base. Overrides the `FAUCET_PROFILE` env var.
1366    #[arg(long, env = "FAUCET_PROFILE")]
1367    pub profile: Option<String>,
1368
1369    /// Runtime matrix-row selection — `preview` previews the first root row of
1370    /// the selected run set.
1371    #[command(flatten)]
1372    pub selection: SelectionArgs,
1373}
1374
1375/// `faucet init` arguments.
1376#[derive(Debug, Parser)]
1377pub struct InitArgs {
1378    /// Name written into the generated file's `name:` field. Defaults to
1379    /// `my-pipeline` when omitted.
1380    pub name: Option<String>,
1381    /// Source connector kind to scaffold (e.g. `rest`, `postgres`, `s3`).
1382    /// Defaults to `rest`. Run `faucet list` to see what is compiled in.
1383    #[arg(long)]
1384    pub source: Option<String>,
1385    /// Sink connector kind to scaffold (e.g. `jsonl`, `bigquery`).
1386    /// Defaults to `jsonl`. Run `faucet list` to see what is compiled in.
1387    #[arg(long)]
1388    pub sink: Option<String>,
1389    /// Output file path. Defaults to `pipeline.yaml`.
1390    #[arg(long, short = 'o', default_value = "pipeline.yaml")]
1391    pub output: PathBuf,
1392    /// Overwrite the output file if it already exists.
1393    #[arg(long)]
1394    pub force: bool,
1395    /// Prompt for the source and sink kinds interactively instead of using
1396    /// `--source` / `--sink`. Requires the `cli-interactive` build feature
1397    /// and a TTY on stdin; falls back to the arg-driven path otherwise.
1398    #[arg(long)]
1399    pub interactive: bool,
1400    /// Name of the template under which to register the scaffolded source
1401    /// and sink. The generated config uses `pipeline.sources.<TEMPLATE>` and
1402    /// `pipeline.sinks.<TEMPLATE>`. Defaults to `default` so a matrix row
1403    /// without a `ref:` field still resolves through the new schema.
1404    #[arg(long, default_value = "default")]
1405    pub template: String,
1406    /// (singer only) Run `<executable> --discover` to fetch the tap's catalog,
1407    /// write it next to the output, and scaffold the config with the discovered
1408    /// streams listed. Requires `--source singer` and `--executable`.
1409    #[arg(long)]
1410    pub discover: bool,
1411    /// (singer only) The Singer tap executable to discover with (used by
1412    /// `--discover`), e.g. `tap-github` or `/opt/taps/tap-csv`.
1413    #[arg(long)]
1414    pub executable: Option<String>,
1415    /// (singer only) The target stream to emit. When given with `--discover`,
1416    /// the written catalog marks this stream — and any inferable parent
1417    /// streams (e.g. a parent-keyed tap's parent) — `selected`, and the
1418    /// scaffolded config's `stream:` is set to it. Most DB / SDK taps sync
1419    /// nothing unless a stream is selected in the catalog.
1420    #[arg(long)]
1421    pub stream: Option<String>,
1422}
1423
1424/// `faucet plan` arguments.
1425#[derive(Debug, Parser)]
1426pub struct PlanArgs {
1427    /// Path to a `.yaml`/`.yml`/`.json` config (auto-discovered if omitted).
1428    pub config: Option<PathBuf>,
1429    /// Which row to plan (default: the first root row).
1430    #[arg(long)]
1431    pub row: Option<String>,
1432    /// Offline sample of input records (`.jsonl` or a `.json` array) to preview
1433    /// the output schema, volume, and sink delta through — no source is touched.
1434    #[arg(long)]
1435    pub sample: Option<PathBuf>,
1436    /// Pull a capped, read-only sample from the real source instead of a
1437    /// fixture (bounded by `--limit`; no bookmark is advanced).
1438    #[arg(long)]
1439    pub live: bool,
1440    /// Cap for `--live` sampling.
1441    #[arg(long, default_value_t = 10)]
1442    pub limit: usize,
1443    /// Emit the plan as JSON.
1444    #[arg(long)]
1445    pub json: bool,
1446    /// Show a `terraform plan`-style diff of the current config against the last
1447    /// recorded run, instead of the resolved-pipeline preview (#374). Requires a
1448    /// `catalog:` block. Resolves secrets so the diff matches what `run` records.
1449    #[arg(long)]
1450    pub diff: bool,
1451    /// Resolve secrets-manager directives (needs network/credentials). Off by
1452    /// default so `plan` works offline like `faucet test`. Implied by `--diff`.
1453    #[arg(long)]
1454    pub resolve_secrets: bool,
1455    /// Select a `profiles:` overlay.
1456    #[arg(long, env = "FAUCET_PROFILE")]
1457    pub profile: Option<String>,
1458}
1459
1460/// `faucet dev` arguments.
1461#[derive(Debug, Parser)]
1462pub struct DevArgs {
1463    /// Path to the `.yaml`/`.yml`/`.json` config to watch.
1464    pub config: PathBuf,
1465    /// Which row to run (default: the first root row).
1466    #[arg(long)]
1467    pub row: Option<String>,
1468    /// Offline sample of input records (`.jsonl` or `.json` array). Required
1469    /// for the offline loop.
1470    #[arg(long)]
1471    pub sample: Option<PathBuf>,
1472    /// (reserved) pull a capped read-only sample from the real source.
1473    #[arg(long)]
1474    pub live: bool,
1475    /// Cap for `--live` sampling.
1476    #[arg(long, default_value_t = 10)]
1477    pub limit: usize,
1478    /// Run once and exit instead of watching (also the non-TTY fallback).
1479    #[arg(long)]
1480    pub once: bool,
1481    /// Debounce window between re-runs, in milliseconds.
1482    #[arg(long, default_value_t = 300)]
1483    pub debounce_ms: u64,
1484    /// Select a `profiles:` overlay.
1485    #[arg(long, env = "FAUCET_PROFILE")]
1486    pub profile: Option<String>,
1487}
1488
1489/// `faucet list` arguments.
1490#[derive(Debug, Parser)]
1491pub struct ListArgs {
1492    /// List every connector in the registry index (not just the compiled-in
1493    /// ones), marking which are already in this binary.
1494    #[arg(long)]
1495    pub available: bool,
1496    /// Read a custom registry index instead of the built-in one.
1497    #[arg(long)]
1498    pub index: Option<PathBuf>,
1499}
1500
1501/// `faucet conformance` arguments.
1502#[derive(Debug, Parser)]
1503pub struct ConformanceArgs {
1504    /// Only score the connector with this system name (e.g. `postgres`); prints
1505    /// a detailed scorecard. Omit to score every compiled-in connector.
1506    pub name: Option<String>,
1507    /// Restrict to `source` or `sink`.
1508    #[arg(long)]
1509    pub kind: Option<String>,
1510    /// Score every compiled-in connector (the default when no NAME is given;
1511    /// accepted explicitly for clarity in CI).
1512    #[arg(long)]
1513    pub all: bool,
1514    /// Emit the full scorecards as JSON.
1515    #[arg(long)]
1516    pub json: bool,
1517    /// Fail (exit non-zero) if any scored connector is below this maturity tier
1518    /// — an opt-in CI gate. One of `stable` / `experimental` / `beta` / `draft`.
1519    #[arg(long, value_name = "TIER")]
1520    pub min_tier: Option<String>,
1521    /// Print the connector capability matrix (Markdown) derived from the
1522    /// registry allowlists and exit — the generated source for the docs-site
1523    /// capability matrix. Ignores the scoring flags.
1524    #[arg(long)]
1525    pub matrix: bool,
1526}
1527
1528/// `faucet search` arguments.
1529#[derive(Debug, Parser)]
1530pub struct SearchArgs {
1531    /// Term to match against connector name / description / keywords / crate.
1532    pub term: String,
1533    /// Read a custom registry index instead of the built-in one.
1534    #[arg(long)]
1535    pub index: Option<PathBuf>,
1536    /// Emit matches as JSON.
1537    #[arg(long)]
1538    pub json: bool,
1539}
1540
1541/// `faucet install` arguments.
1542#[derive(Debug, Parser)]
1543pub struct InstallArgs {
1544    /// Connector system name (e.g. `kafka`).
1545    pub name: String,
1546    /// Disambiguate when a name exists as both a source and a sink.
1547    #[arg(long)]
1548    pub kind: Option<String>,
1549    /// Read a custom registry index instead of the built-in one.
1550    #[arg(long)]
1551    pub index: Option<PathBuf>,
1552}
1553
1554/// `faucet new` arguments.
1555#[derive(Debug, Parser)]
1556pub struct NewArgs {
1557    #[command(subcommand)]
1558    pub target: NewTarget,
1559}
1560
1561/// What `faucet new` scaffolds.
1562#[derive(Debug, Subcommand)]
1563pub enum NewTarget {
1564    /// Scaffold a ready-to-build `faucet-source-<name>` / `faucet-sink-<name>`
1565    /// connector crate following every repo convention.
1566    Connector(NewConnectorArgs),
1567}
1568
1569/// `faucet new connector` arguments.
1570#[derive(Debug, Parser)]
1571pub struct NewConnectorArgs {
1572    /// Connector system name (lowercase, e.g. `acme` or `acme-widgets`). Becomes
1573    /// the crate name `faucet-<kind>-<name>` and the YAML `type:` value.
1574    pub name: String,
1575    /// Whether to scaffold a `source` or a `sink`.
1576    #[arg(long)]
1577    pub kind: String,
1578    /// Also scaffold a `faucet-common-<name>` crate for config shared between a
1579    /// source/sink pair.
1580    #[arg(long)]
1581    pub common: bool,
1582    /// Directory to write the new crate(s) into. Defaults to the current dir.
1583    #[arg(long, short = 'o', default_value = ".")]
1584    pub output: PathBuf,
1585    /// Overwrite any existing files.
1586    #[arg(long)]
1587    pub force: bool,
1588}