asimov_cli/commands/
source.rs1use crate::BoxError;
4use asimov_module::ModuleName;
5use clientele::{StandardOptions, crates::clap::Subcommand, options::sort::SortKeys};
6
7#[derive(Debug, Subcommand)]
8pub enum SourceCommand {
9 #[clap(aliases = ["extract", "get", "import", "ingest", "parse"])]
11 Fetch {
12 #[clap(flatten)]
13 args: fetch::SourceFetchArgs,
14 },
15
16 #[clap(aliases = ["dir", "ls"])]
18 List {
19 urls: Vec<String>,
21
22 #[clap(long, short = 'M')]
24 module: Option<ModuleName>,
25
26 #[clap(long, aliases = ["sort-by", "order", "order-by"], value_name = "[+|-]KEY,...", allow_hyphen_values = true)]
28 sort: Option<SortKeys>,
29
30 #[clap(value_name = "INDEX", long, default_value = "0")]
32 offset: Option<usize>,
33
34 #[arg(value_name = "COUNT", short = 'n', long)]
36 limit: Option<usize>,
37
38 #[arg(value_name = "FORMAT", short = 'o', long)]
40 output: Option<String>, },
42
43 Read {
45 #[clap(long, short = 'M')]
46 module: Option<ModuleName>,
47
48 urls: Vec<String>,
49 },
50
51 #[cfg(feature = "source-snap")]
53 Snap {
54 #[clap(subcommand)]
55 command: Option<SnapCommand>,
56
57 #[clap(flatten)]
58 args: SnapSaveArgs,
59 },
60}
61
62impl Default for SourceCommand {
63 fn default() -> Self {
64 SourceCommand::Fetch {
65 args: fetch::SourceFetchArgs::default(),
66 }
67 }
68}
69
70impl SourceCommand {
71 pub async fn run(self, flags: &StandardOptions) -> Result<(), BoxError> {
72 use SourceCommand::*;
73 match self {
74 Fetch { args } => fetch(args, flags).await,
75
76 List {
77 urls,
78 module,
79 sort,
80 offset,
81 limit,
82 output,
83 } => list(urls, module, sort, offset, limit, output, flags).await,
84
85 Read { module, urls } => read(urls, module, flags).await,
86
87 #[cfg(feature = "source-snap")]
88 Snap { command, args } => {
89 command
90 .unwrap_or(SnapCommand::Save { args })
91 .run(flags)
92 .await
93 },
94 }
95 }
96}
97
98#[cfg(false)]
99pub mod describe;
100
101mod fetch;
102pub use fetch::*;
103
104mod list;
105pub use list::list;
106
107mod read;
108pub use read::*;
109
110mod snap;
111pub use snap::*;