use crate::BoxError;
use asimov_module::ModuleName;
use clientele::{StandardOptions, crates::clap::Subcommand, options::sort::SortKeys};
#[derive(Debug, Subcommand)]
pub enum SourceCommand {
#[clap(aliases = ["extract", "get", "import", "ingest", "parse"])]
Fetch {
#[clap(flatten)]
args: fetch::SourceFetchArgs,
},
#[clap(aliases = ["dir", "ls"])]
List {
urls: Vec<String>,
#[clap(long, short = 'M')]
module: Option<ModuleName>,
#[clap(long, aliases = ["sort-by", "order", "order-by"], value_name = "[+|-]KEY,...", allow_hyphen_values = true)]
sort: Option<SortKeys>,
#[clap(value_name = "INDEX", long, default_value = "0")]
offset: Option<usize>,
#[arg(value_name = "COUNT", short = 'n', long)]
limit: Option<usize>,
#[arg(value_name = "FORMAT", short = 'o', long)]
output: Option<String>, },
Read {
#[clap(long, short = 'M')]
module: Option<ModuleName>,
urls: Vec<String>,
},
#[cfg(feature = "source-snap")]
Snap {
#[clap(subcommand)]
command: Option<SnapCommand>,
#[clap(flatten)]
args: SnapSaveArgs,
},
}
impl Default for SourceCommand {
fn default() -> Self {
SourceCommand::Fetch {
args: fetch::SourceFetchArgs::default(),
}
}
}
impl SourceCommand {
pub async fn run(self, flags: &StandardOptions) -> Result<(), BoxError> {
use SourceCommand::*;
match self {
Fetch { args } => fetch(args, flags).await,
List {
urls,
module,
sort,
offset,
limit,
output,
} => list(urls, module, sort, offset, limit, output, flags).await,
Read { module, urls } => read(urls, module, flags).await,
#[cfg(feature = "source-snap")]
Snap { command, args } => {
command
.unwrap_or(SnapCommand::Save { args })
.run(flags)
.await
},
}
}
}
#[cfg(false)]
pub mod describe;
mod fetch;
pub use fetch::*;
mod list;
pub use list::list;
mod read;
pub use read::*;
mod snap;
pub use snap::*;