use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "gdelt")]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
#[command(flatten)]
pub global: GlobalArgs,
}
#[derive(Args, Debug, Clone)]
pub struct GlobalArgs {
#[arg(short, long, global = true, value_enum, default_value = "auto")]
pub output: OutputFormat,
#[arg(long, global = true, conflicts_with = "output")]
pub json: bool,
#[arg(long, global = true, conflicts_with = "output")]
pub jsonl: bool,
#[arg(long, global = true, conflicts_with = "output")]
pub csv: bool,
#[arg(long, global = true, conflicts_with = "output")]
pub table: bool,
#[arg(long, global = true, conflicts_with = "output")]
pub markdown: bool,
#[arg(long, global = true)]
pub pretty: bool,
#[arg(long, global = true, conflicts_with = "pretty")]
pub compact: bool,
#[arg(short, long, global = true)]
pub quiet: bool,
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(long, global = true)]
pub dry_run: bool,
#[arg(short, long, global = true)]
pub yes: bool,
#[arg(long, global = true)]
pub no_cache: bool,
#[arg(long, global = true, conflicts_with = "no_cache")]
pub cache_only: bool,
#[arg(long, global = true, default_value = "30")]
pub timeout: u64,
#[arg(long, global = true, default_value = "3")]
pub retries: u32,
#[arg(long, global = true)]
pub wait_on_rate_limit: bool,
#[arg(long, global = true, default_value = "120")]
pub max_rate_limit_wait: u64,
#[arg(short, long, global = true, env = "GDELT_CONFIG")]
pub config: Option<PathBuf>,
#[arg(long, global = true)]
pub profile: Option<String>,
#[arg(long, global = true)]
pub debug: bool,
#[arg(long, global = true, conflicts_with = "debug")]
pub trace: bool,
#[arg(long, global = true)]
pub timing: bool,
#[arg(long, global = true)]
pub help_json: bool,
}
impl GlobalArgs {
pub fn effective_output_format(&self) -> OutputFormat {
if self.json {
OutputFormat::Json
} else if self.jsonl {
OutputFormat::Jsonl
} else if self.csv {
OutputFormat::Csv
} else if self.table {
OutputFormat::Table
} else if self.markdown {
OutputFormat::Markdown
} else {
self.output
}
}
pub fn should_pretty_print(&self) -> bool {
if self.compact {
return false;
}
if self.pretty {
return true;
}
atty::is(atty::Stream::Stdout)
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
#[default]
Auto,
Json,
Jsonl,
Csv,
Table,
Markdown,
}
#[derive(Subcommand, Debug)]
pub enum Command {
#[command(subcommand)]
Doc(DocCommand),
#[command(subcommand)]
Geo(GeoCommand),
#[command(subcommand)]
Tv(TvCommand),
#[command(subcommand)]
Tvai(TvAiCommand),
#[command(subcommand)]
Data(DataCommand),
#[command(subcommand)]
Events(EventsCommand),
#[command(subcommand)]
Gkg(GkgCommand),
#[command(subcommand)]
Db(DbCommand),
Serve(ServeArgs),
#[command(subcommand)]
Daemon(DaemonCommand),
#[command(subcommand)]
Skill(SkillCommand),
#[command(subcommand)]
Analytics(AnalyticsCommand),
#[command(subcommand)]
Config(ConfigCommand),
#[command(subcommand)]
Schema(SchemaCommand),
Enrich(EnrichArgs),
Completions(CompletionsArgs),
}
#[derive(Subcommand, Debug)]
pub enum DocCommand {
Search(DocSearchArgs),
Timeline(DocTimelineArgs),
Wordcloud(DocWordcloudArgs),
Themes(DocThemesArgs),
}
#[derive(Args, Debug)]
pub struct DocSearchArgs {
pub query: String,
#[arg(short, long, default_value = "24h")]
pub timespan: String,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(short = 'n', long, default_value = "75")]
pub max_records: u32,
#[arg(short, long, value_enum, default_value = "hybrid-rel")]
pub sort: SortOrder,
#[arg(short, long)]
pub lang: Option<String>,
#[arg(long)]
pub country: Option<String>,
#[arg(short, long)]
pub domain: Option<String>,
#[arg(long)]
pub theme: Option<String>,
#[arg(long)]
pub tone_min: Option<f64>,
#[arg(long)]
pub tone_max: Option<f64>,
#[arg(long)]
pub enrich: bool,
#[arg(long)]
pub fetch_text: bool,
#[arg(long, default_value = "5")]
pub fetch_concurrency: usize,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum SortOrder {
DateDesc,
DateAsc,
ToneDesc,
ToneAsc,
HybridRel,
}
#[derive(Args, Debug)]
pub struct DocTimelineArgs {
pub query: String,
#[arg(short, long, value_enum, default_value = "vol")]
pub mode: TimelineMode,
#[arg(short, long, default_value = "30d")]
pub timespan: String,
#[arg(long)]
pub smooth: Option<u8>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum TimelineMode {
Vol,
VolRaw,
Tone,
Lang,
SourceCountry,
}
#[derive(Args, Debug)]
pub struct DocWordcloudArgs {
pub query: String,
#[arg(short, long, default_value = "24h")]
pub timespan: String,
}
#[derive(Args, Debug)]
pub struct DocThemesArgs {
#[arg(short, long)]
pub filter: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum GeoCommand {
Search(GeoSearchArgs),
Points(GeoPointsArgs),
Heatmap(GeoHeatmapArgs),
Aggregate(GeoAggregateArgs),
}
#[derive(Args, Debug)]
pub struct GeoSearchArgs {
pub query: String,
#[arg(short, long, default_value = "24h")]
pub timespan: String,
#[arg(long)]
pub location: Option<String>,
#[arg(long)]
pub country: Option<String>,
#[arg(short = 'n', long, default_value = "250")]
pub max_points: u32,
}
#[derive(Args, Debug)]
pub struct GeoPointsArgs {
pub query: String,
#[arg(short, long, default_value = "24h")]
pub timespan: String,
#[arg(long, default_value = "0")]
pub resolution: u8,
}
#[derive(Args, Debug)]
pub struct GeoHeatmapArgs {
pub query: String,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
}
#[derive(Args, Debug)]
pub struct GeoAggregateArgs {
pub query: String,
#[arg(short, long, value_enum, default_value = "country")]
pub level: AggregationLevel,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum AggregationLevel {
Country,
Adm1,
}
#[derive(Subcommand, Debug)]
pub enum TvCommand {
Search(TvSearchArgs),
Clips(TvClipsArgs),
Timeline(TvTimelineArgs),
Stations(TvStationsArgs),
}
#[derive(Args, Debug)]
pub struct TvSearchArgs {
pub query: String,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
#[arg(long)]
pub station: Option<String>,
#[arg(short = 'n', long, default_value = "250")]
pub max_records: u32,
}
#[derive(Args, Debug)]
pub struct TvClipsArgs {
pub query: String,
#[arg(short, long, default_value = "24h")]
pub timespan: String,
}
#[derive(Args, Debug)]
pub struct TvTimelineArgs {
pub query: String,
#[arg(short, long, default_value = "30d")]
pub timespan: String,
#[arg(long)]
pub by_station: bool,
}
#[derive(Args, Debug)]
pub struct TvStationsArgs {
#[arg(short, long)]
pub country: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum TvAiCommand {
Search(TvAiSearchArgs),
Concepts(TvAiConceptsArgs),
Visual(TvAiVisualArgs),
}
#[derive(Args, Debug)]
pub struct TvAiSearchArgs {
pub query: String,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
#[arg(long, default_value = "true")]
pub captions: bool,
#[arg(long)]
pub ocr: bool,
#[arg(long)]
pub asr: bool,
}
#[derive(Args, Debug)]
pub struct TvAiConceptsArgs {
pub concept: String,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
}
#[derive(Args, Debug)]
pub struct TvAiVisualArgs {
pub entity: String,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
}
#[derive(Subcommand, Debug)]
pub enum DataCommand {
#[command(subcommand)]
Download(DownloadCommand),
Sync(DataSyncArgs),
Status(DataStatusArgs),
List(DataListArgs),
Delete(DataDeleteArgs),
}
#[derive(Subcommand, Debug)]
pub enum DownloadCommand {
Events(DownloadEventsArgs),
Gkg(DownloadGkgArgs),
Mentions(DownloadMentionsArgs),
}
#[derive(Args, Debug)]
pub struct DownloadEventsArgs {
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(long)]
pub all: bool,
#[arg(long, default_value = "4")]
pub parallel: u8,
}
#[derive(Args, Debug)]
pub struct DownloadGkgArgs {
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(long, default_value = "2")]
pub version: u8,
#[arg(long, default_value = "4")]
pub parallel: u8,
}
#[derive(Args, Debug)]
pub struct DownloadMentionsArgs {
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(long, default_value = "4")]
pub parallel: u8,
}
#[derive(Args, Debug)]
pub struct DataSyncArgs {
#[arg(short, long, value_enum)]
pub data_type: Option<DataType>,
#[arg(long)]
pub quick: bool,
#[arg(long)]
pub days: Option<u32>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum DataType {
Events,
Gkg,
Mentions,
All,
}
#[derive(Args, Debug)]
pub struct DataStatusArgs {
#[arg(long)]
pub detailed: bool,
}
#[derive(Args, Debug)]
pub struct DataListArgs {
#[arg(short, long, value_enum)]
pub data_type: Option<DataType>,
}
#[derive(Args, Debug)]
pub struct DataDeleteArgs {
#[arg(short, long, value_enum)]
pub data_type: DataType,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(long)]
pub all: bool,
}
#[derive(Subcommand, Debug)]
pub enum EventsCommand {
Query(EventsQueryArgs),
Lookup(EventsLookupArgs),
Actors(EventsActorsArgs),
Countries(EventsCountriesArgs),
#[command(subcommand)]
Codes(CodesCommand),
}
#[derive(Args, Debug)]
pub struct EventsQueryArgs {
#[arg(short, long)]
pub actor: Option<String>,
#[arg(short, long)]
pub event_code: Option<String>,
#[arg(long)]
pub quad_class: Option<u8>,
#[arg(short, long)]
pub country: Option<String>,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(long)]
pub goldstein_min: Option<f64>,
#[arg(long)]
pub goldstein_max: Option<f64>,
#[arg(short = 'n', long, default_value = "100")]
pub limit: u32,
#[arg(long, default_value = "0")]
pub offset: u32,
}
#[derive(Args, Debug)]
pub struct EventsLookupArgs {
pub event_id: String,
}
#[derive(Args, Debug)]
pub struct EventsActorsArgs {
pub actor: Option<String>,
#[arg(long)]
pub stats: bool,
#[arg(short = 'n', long, default_value = "50")]
pub limit: u32,
}
#[derive(Args, Debug)]
pub struct EventsCountriesArgs {
pub country: Option<String>,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum CodesCommand {
List(CodesListArgs),
Search(CodesSearchArgs),
Describe(CodesDescribeArgs),
}
#[derive(Args, Debug)]
pub struct CodesListArgs {
#[arg(short = 't', long, value_enum)]
pub code_type: Option<CodeType>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum CodeType {
Event,
Actor,
Country,
Ethnic,
Religion,
}
#[derive(Args, Debug)]
pub struct CodesSearchArgs {
pub pattern: String,
}
#[derive(Args, Debug)]
pub struct CodesDescribeArgs {
pub code: String,
}
#[derive(Subcommand, Debug)]
pub enum GkgCommand {
Query(GkgQueryArgs),
Themes(GkgThemesArgs),
Persons(GkgPersonsArgs),
Organizations(GkgOrganizationsArgs),
Locations(GkgLocationsArgs),
}
#[derive(Args, Debug)]
pub struct GkgQueryArgs {
#[arg(short, long)]
pub theme: Option<String>,
#[arg(short, long)]
pub person: Option<String>,
#[arg(short, long)]
pub org: Option<String>,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
#[arg(short = 'n', long, default_value = "100")]
pub limit: u32,
}
#[derive(Args, Debug)]
pub struct GkgThemesArgs {
pub pattern: Option<String>,
#[arg(long, default_value = "10")]
pub min_count: u32,
#[arg(long)]
pub start: Option<String>,
#[arg(long)]
pub end: Option<String>,
}
#[derive(Args, Debug)]
pub struct GkgPersonsArgs {
pub pattern: Option<String>,
#[arg(long, default_value = "5")]
pub min_count: u32,
#[arg(short = 'n', long, default_value = "50")]
pub limit: u32,
}
#[derive(Args, Debug)]
pub struct GkgOrganizationsArgs {
pub pattern: Option<String>,
#[arg(long, default_value = "5")]
pub min_count: u32,
#[arg(short = 'n', long, default_value = "50")]
pub limit: u32,
}
#[derive(Args, Debug)]
pub struct GkgLocationsArgs {
pub pattern: Option<String>,
#[arg(short, long)]
pub country: Option<String>,
#[arg(short = 'n', long, default_value = "50")]
pub limit: u32,
}
#[derive(Subcommand, Debug)]
pub enum DbCommand {
Stats(DbStatsArgs),
Vacuum(DbVacuumArgs),
Export(DbExportArgs),
Import(DbImportArgs),
Query(DbQueryArgs),
}
#[derive(Args, Debug)]
pub struct DbStatsArgs {
#[arg(long)]
pub detailed: bool,
}
#[derive(Args, Debug)]
pub struct DbVacuumArgs {
#[arg(long)]
pub analyze: bool,
}
#[derive(Args, Debug)]
pub struct DbExportArgs {
pub table: String,
#[arg(short, long)]
pub output: PathBuf,
#[arg(short, long, value_enum, default_value = "parquet")]
pub format: ExportFormat,
#[arg(long)]
pub filter: Option<String>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum ExportFormat {
Parquet,
Csv,
Json,
}
#[derive(Args, Debug)]
pub struct DbImportArgs {
pub input: PathBuf,
#[arg(short, long)]
pub table: String,
#[arg(short, long, value_enum)]
pub format: Option<ExportFormat>,
}
#[derive(Args, Debug)]
pub struct DbQueryArgs {
pub query: String,
}
#[derive(Args, Debug)]
pub struct ServeArgs {
#[arg(short, long, value_enum, default_value = "stdio")]
pub transport: Transport,
#[arg(short, long, default_value = "8080")]
pub port: u16,
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Transport {
Stdio,
Sse,
Http,
}
#[derive(Subcommand, Debug)]
pub enum DaemonCommand {
Start(DaemonStartArgs),
Stop,
Restart,
Status,
Logs(DaemonLogsArgs),
Install(DaemonInstallArgs),
Uninstall,
#[command(hide = true)]
Run,
}
#[derive(Args, Debug)]
pub struct DaemonStartArgs {
#[arg(long, default_value = "true")]
pub mcp: bool,
#[arg(long)]
pub sync: bool,
#[arg(long, default_value = "8080")]
pub port: u16,
}
#[derive(Args, Debug)]
pub struct DaemonLogsArgs {
#[arg(short = 'n', long, default_value = "50")]
pub tail: u32,
#[arg(short, long)]
pub follow: bool,
}
#[derive(Args, Debug)]
pub struct DaemonInstallArgs {
#[arg(long, value_enum)]
pub service_type: Option<ServiceType>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum ServiceType {
Systemd,
Launchd,
}
#[derive(Subcommand, Debug)]
pub enum SkillCommand {
Install(SkillInstallArgs),
Uninstall,
Update,
Status,
}
#[derive(Args, Debug)]
pub struct SkillInstallArgs {
#[arg(long)]
pub project: bool,
#[arg(short, long)]
pub force: bool,
}
#[derive(Subcommand, Debug)]
pub enum AnalyticsCommand {
Trends(AnalyticsTrendsArgs),
Entities(AnalyticsEntitiesArgs),
Sentiment(AnalyticsSentimentArgs),
Compare(AnalyticsCompareArgs),
#[command(subcommand)]
Report(ReportCommand),
}
#[derive(Args, Debug)]
pub struct AnalyticsTrendsArgs {
pub topics: Vec<String>,
#[arg(short, long, value_enum, default_value = "doc")]
pub source: AnalyticsSource,
#[arg(short, long, default_value = "30d")]
pub timespan: String,
#[arg(short, long, value_enum, default_value = "day")]
pub granularity: Granularity,
#[arg(long)]
pub normalize: bool,
#[arg(long)]
pub detect_anomalies: bool,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum AnalyticsSource {
Doc,
Tv,
Events,
Gkg,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Granularity {
Hour,
Day,
Week,
Month,
}
#[derive(Args, Debug)]
pub struct AnalyticsEntitiesArgs {
#[arg(short, long, value_enum, default_value = "doc")]
pub source: AnalyticsSource,
#[arg(short, long, value_enum, default_value = "all")]
pub entity_type: EntityTypeArg,
#[arg(long, default_value = "5")]
pub min_count: u32,
#[arg(short = 'n', long, default_value = "50")]
pub limit: u32,
#[arg(short, long, default_value = "7d")]
pub timespan: String,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum EntityTypeArg {
Person,
Organization,
Location,
Actor,
Theme,
All,
}
#[derive(Args, Debug)]
pub struct AnalyticsSentimentArgs {
pub topic: String,
#[arg(short, long, value_enum, default_value = "time")]
pub dimension: SentimentDimension,
#[arg(short, long, default_value = "30d")]
pub timespan: String,
#[arg(short, long, value_enum, default_value = "day")]
pub granularity: Granularity,
#[arg(long)]
pub compare_with: Option<String>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum SentimentDimension {
Time,
Region,
Source,
Entity,
}
#[derive(Args, Debug)]
pub struct AnalyticsCompareArgs {
pub topic_a: String,
pub topic_b: String,
#[arg(short, long, default_value = "30d")]
pub timespan: String,
}
#[derive(Subcommand, Debug)]
pub enum ReportCommand {
Daily(ReportArgs),
Weekly(ReportArgs),
Custom(ReportCustomArgs),
}
#[derive(Args, Debug)]
pub struct ReportArgs {
#[arg(short, long)]
pub topics: Vec<String>,
#[arg(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub struct ReportCustomArgs {
#[arg(long)]
pub start: String,
#[arg(long)]
pub end: String,
#[arg(short, long)]
pub topics: Vec<String>,
#[arg(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub struct EnrichArgs {
#[arg(required_unless_present = "stdin")]
pub urls: Vec<String>,
#[arg(long)]
pub stdin: bool,
#[arg(long)]
pub fetch_text: bool,
#[arg(long, default_value = "5")]
pub concurrency: usize,
}
#[derive(Subcommand, Debug)]
pub enum ConfigCommand {
Show,
Get(ConfigGetArgs),
Set(ConfigSetArgs),
Reset,
Validate,
}
#[derive(Args, Debug)]
pub struct ConfigGetArgs {
pub key: String,
}
#[derive(Args, Debug)]
pub struct ConfigSetArgs {
pub key: String,
pub value: String,
}
#[derive(Subcommand, Debug)]
pub enum SchemaCommand {
Commands,
Command(SchemaCommandArgs),
Output(SchemaOutputArgs),
Codes,
Tools,
}
#[derive(Args, Debug)]
pub struct SchemaCommandArgs {
pub command: String,
}
#[derive(Args, Debug)]
pub struct SchemaOutputArgs {
pub command: String,
}
#[derive(Args, Debug)]
pub struct CompletionsArgs {
#[arg(value_enum)]
pub shell: Shell,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Shell {
Bash,
Zsh,
Fish,
PowerShell,
}