use std::path::PathBuf;
use std::time::Duration;
use clap::{Parser, Subcommand};
use url::Url;
use crate::releases::TargetName;
use crate::rules::MergePolicy;
use crate::sweep;
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
#[command(name = "onevcs", version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum Command {
Register(RegisterArgs),
Repos(ReposArgs),
Resolve(ResolveArgs),
Session {
#[command(subcommand)]
command: SessionCommand,
},
Publish(PublishArgs),
PublishBranch(PublishBranchArgs),
Recover(RecoverArgs),
Recoverable(RecoverableArgs),
Status(StatusArgs),
Import(ImportArgs),
Integrate(IntegrateArgs),
Sync(SyncArgs),
Sweep(SweepArgs),
Events(EventsArgs),
Artifact {
#[command(subcommand)]
command: ArtifactCommand,
},
Rules {
#[command(subcommand)]
command: RulesCommand,
},
Release {
#[command(subcommand)]
command: ReleaseCommand,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct RegisterArgs {
pub path: PathBuf,
#[arg(long, value_name = "URL")]
pub origin: Option<Url>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReposArgs {
#[arg(long)]
pub audit_gates: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ResolveArgs {
pub repo: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum SessionCommand {
Open(SessionOpenArgs),
Adopt(SessionTokenArgs),
Close(SessionTokenArgs),
Holders(SessionHoldersArgs),
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct SessionOpenArgs {
pub repo: String,
#[arg(long, value_name = "B")]
pub branch: Option<String>,
#[arg(long, value_name = "B")]
pub base: Option<String>,
#[arg(long, value_name = "ALIAS")]
pub execution_checkout: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct SessionTokenArgs {
pub token: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct SessionHoldersArgs {
pub repo: String,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct PublishArgs {
pub token: String,
#[arg(long, value_name = "P")]
pub policy: Option<MergePolicy>,
#[arg(long, value_name = "T")]
pub title: Option<String>,
#[arg(long, value_name = "TEXT")]
pub body: Option<String>,
#[arg(long, value_name = "PATH")]
pub body_file: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct PublishBranchArgs {
pub branch: String,
#[arg(long, value_name = "PATH")]
pub repo: PathBuf,
#[arg(long, value_name = "T")]
pub title: Option<String>,
#[arg(long, value_name = "P")]
pub policy: Option<MergePolicy>,
#[arg(long, value_name = "TEXT")]
pub body: Option<String>,
#[arg(long, value_name = "PATH")]
pub body_file: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct RecoverArgs {
pub branch: String,
#[arg(long, value_name = "PATH")]
pub repo: PathBuf,
#[arg(long, value_name = "T")]
pub title: Option<String>,
#[arg(long, value_name = "TEXT")]
pub body: Option<String>,
#[arg(long, value_name = "PATH")]
pub body_file: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct RecoverableArgs {
#[arg(long)]
pub all: bool,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct StatusArgs {
pub reference: String,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ImportArgs {
pub branch: String,
#[arg(long, value_name = "PATH")]
pub repo: PathBuf,
#[arg(long, value_name = "SOURCE")]
pub from: Option<String>,
#[arg(long, value_name = "NAME")]
pub r#as: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct IntegrateArgs {
#[arg(required = true, num_args = 1..)]
pub branches: Vec<String>,
#[arg(long)]
pub push: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct SyncArgs {
pub branch: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct SweepArgs {
#[arg(long)]
pub dry_run: bool,
#[arg(
long,
value_name = "HOURS",
default_value = sweep::DEFAULT_MIN_AGE_HOURS,
value_parser = sweep::hours,
)]
pub min_age_hours: Duration,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct EventsArgs {
pub token: String,
#[arg(long)]
pub follow: bool,
#[arg(long, value_name = "SPEC")]
pub filter: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ArtifactCommand {
Cat(ArtifactCatArgs),
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ArtifactCatArgs {
pub id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum RulesCommand {
Check(RulesCheckArgs),
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct RulesCheckArgs {
pub repo: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReleaseCommand {
Targets(ReleaseTargetsArgs),
Discover(ReleaseDiscoverArgs),
Latest(ReleaseLatestArgs),
Status(ReleaseStatusArgs),
Acknowledge(ReleaseAcknowledgeArgs),
Declaration(ReleaseDeclarationArgs),
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseDeclarationArgs {
pub path: PathBuf,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseTargetsArgs {
pub repo: String,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseDiscoverArgs {
pub repo: String,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseLatestArgs {
pub repo: String,
#[arg(long, value_name = "NAME")]
pub target: Option<TargetName>,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseStatusArgs {
pub reference: String,
#[arg(long, value_name = "NAME")]
pub target: Option<TargetName>,
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Parser)]
pub struct ReleaseAcknowledgeArgs {
pub reference: String,
#[arg(long, value_name = "NAME")]
pub target: TargetName,
#[arg(long, value_name = "VERSION")]
pub version: String,
#[arg(long)]
pub supersede: bool,
#[arg(long)]
pub json: bool,
}