Skip to main content

spec_driven_docs/cli/
migrate.rs

1//! `migrate` subcommand: parse-shape.
2//!
3//! Holds the clap derive structs only. No I/O, no business logic.
4
5use camino::Utf8PathBuf;
6
7use crate::domain::migration::Status;
8
9/// Archive a corpus, track its rebuild, and close the migration.
10#[derive(Debug, clap::Args)]
11pub struct MigrateArgs {
12    /// What to do.
13    #[command(subcommand)]
14    pub command: MigrateCommand,
15}
16
17/// The verbs `sdd migrate` offers.
18#[derive(Debug, clap::Subcommand)]
19pub enum MigrateCommand {
20    /// List every document the target holds, with its kind and checksum.
21    Inventory(TargetArgs),
22    /// Move every document but the root metadata into the archive, and open
23    /// the migration; without --apply nothing is written.
24    Archive(ArchiveArgs),
25    /// Move a source, or every source of a group, to a status.
26    Mark(MarkArgs),
27    /// Report where every source of the open migration stands.
28    Status(TargetArgs),
29    /// End the open migration once every source is verified or dropped;
30    /// without --apply nothing is written.
31    Close(CloseArgs),
32}
33
34/// The repository a read-only verb reads.
35#[derive(Debug, clap::Args)]
36pub struct TargetArgs {
37    /// The repository to read; absolute, or the working directory.
38    #[arg(long, default_value = ".")]
39    pub target: Utf8PathBuf,
40
41    /// Print one JSON object instead of text.
42    #[arg(long)]
43    pub json: bool,
44}
45
46/// Move the corpus into the archive.
47#[derive(Debug, clap::Args)]
48pub struct ArchiveArgs {
49    /// The repository to migrate; absolute, or the working directory.
50    #[arg(long, default_value = ".")]
51    pub target: Utf8PathBuf,
52
53    /// Write: move the documents, write the registry, and record the open
54    /// migration in the declaration.
55    #[arg(long)]
56    pub apply: bool,
57
58    /// Recreate the open migration's archive from Git at its base commit,
59    /// on this clone or another one.
60    #[arg(long)]
61    pub rebuild: bool,
62
63    /// The trunk every archived document must match byte for byte: a
64    /// branch or a commit. By default, the local branch the remote's HEAD
65    /// names. A rebuild reads its base from the registry or from Git.
66    #[arg(long, value_name = "REF", conflicts_with = "rebuild")]
67    pub trunk: Option<String>,
68
69    /// Print one JSON object instead of text.
70    #[arg(long)]
71    pub json: bool,
72}
73
74/// Move a source or a group to a status.
75#[derive(Debug, clap::Args)]
76pub struct MarkArgs {
77    /// A source id or path, or a group id.
78    pub name: String,
79
80    /// The status it takes.
81    #[arg(value_enum)]
82    pub status: Status,
83
84    /// The repository of the open migration; absolute, or the working
85    /// directory.
86    #[arg(long, default_value = ".")]
87    pub target: Utf8PathBuf,
88
89    /// File the source into this group, created where it is new.
90    #[arg(long, value_name = "GROUP")]
91    pub group: Option<String>,
92
93    /// Tag the source with this topic. Repeatable.
94    #[arg(long, value_name = "TAG")]
95    pub tag: Vec<String>,
96
97    /// Give the group this destination. Repeatable.
98    #[arg(long, value_name = "PATH")]
99    pub destination: Vec<Utf8PathBuf>,
100
101    /// Why the source is dropped; required with `dropped`.
102    #[arg(long)]
103    pub reason: Option<String>,
104
105    /// Print one JSON object instead of text.
106    #[arg(long)]
107    pub json: bool,
108}
109
110/// End the open migration.
111#[derive(Debug, clap::Args)]
112pub struct CloseArgs {
113    /// The repository of the open migration; absolute, or the working
114    /// directory.
115    #[arg(long, default_value = ".")]
116    pub target: Utf8PathBuf,
117
118    /// Write: remove the migration from the declaration.
119    #[arg(long)]
120    pub apply: bool,
121
122    /// Print one JSON object instead of text.
123    #[arg(long)]
124    pub json: bool,
125}