use crev_data::Level;
use semver::Version;
use std::ffi::OsString;
use structopt::StructOpt;
#[derive(Debug, StructOpt, Clone)]
pub struct CrateSelector {
pub name: Option<String>,
pub version: Option<Version>,
}
#[derive(Debug, StructOpt, Clone)]
pub struct NewId {
#[structopt(long = "url")]
pub url: Option<String>,
#[structopt(long = "github-username")]
pub github_username: Option<String>,
#[structopt(long = "https-push")]
pub use_https_push: bool,
}
#[derive(Debug, StructOpt, Clone)]
pub enum New {
#[structopt(name = "id")]
Id(NewId),
}
#[derive(Debug, StructOpt, Clone)]
pub struct SwitchId {
pub id: String,
}
#[derive(Debug, StructOpt, Clone)]
pub struct TrustDistanceParams {
#[structopt(long = "depth", default_value = "10")]
pub depth: u64,
#[structopt(long = "high-cost", default_value = "0")]
pub high_cost: u64,
#[structopt(long = "medium-cost", default_value = "1")]
pub medium_cost: u64,
#[structopt(long = "low-cost", default_value = "5")]
pub low_cost: u64,
}
impl From<TrustDistanceParams> for crev_lib::TrustDistanceParams {
fn from(params: TrustDistanceParams) -> Self {
crev_lib::TrustDistanceParams {
max_distance: params.depth,
high_trust_distance: params.high_cost,
medium_trust_distance: params.medium_cost,
low_trust_distance: params.low_cost,
}
}
}
#[derive(Debug, StructOpt, Clone)]
pub struct Diff {
#[structopt(long = "src")]
pub src: Option<Version>,
#[structopt(long = "dst")]
pub dst: Option<Version>,
#[structopt(flatten)]
pub requirements: VerificationRequirements,
#[structopt(flatten)]
pub trust_params: TrustDistanceParams,
pub name: String,
#[structopt(parse(from_os_str))]
pub args: Vec<OsString>,
}
#[derive(Debug, StructOpt, Clone)]
pub struct VerificationRequirements {
#[structopt(long = "trust", default_value = "low")]
pub trust_level: crev_data::Level,
#[structopt(long = "redundancy", default_value = "1")]
pub redundancy: u64,
#[structopt(long = "understanding", default_value = "none")]
pub understanding_level: Level,
#[structopt(long = "thoroughness", default_value = "none")]
pub thoroughness_level: Level,
}
impl From<VerificationRequirements> for crev_lib::VerificationRequirements {
fn from(req: VerificationRequirements) -> Self {
crev_lib::VerificationRequirements {
trust_level: req.trust_level,
redundancy: req.redundancy,
understanding: req.understanding_level,
thoroughness: req.thoroughness_level,
}
}
}
#[derive(Debug, StructOpt, Clone)]
#[structopt(
name = "deps",
after_help = r"This will show the following information:
- trust - Trust check result: `pass` for trusted, `none` for lacking reviews, `flagged` or `dangerous` for crates with problem reports.
- reviews - Number of reviews for the specific version and for all available versions (total)
- downloads - Download counts from crates.io for the specific version and all versions
- own. - Owner counts from crates.io (known/all)
- issues - Number of issues repored (from trusted sources/all)
- lines - Lines of Rust code
- geiger - Geiger score: number of `unsafe` lines
- flgs - Flags for specific types of packages
- CB - Custom Build
- name - Crate name
- version - Crate version
- latest_t - Latest trusted version"
)]
pub struct Verify {
#[structopt(long = "verbose", short = "v")]
pub verbose: bool,
#[structopt(flatten)]
pub trust_params: TrustDistanceParams,
#[structopt(flatten)]
pub requirements: VerificationRequirements,
#[structopt(long = "skip-verified")]
pub skip_verified: bool,
#[structopt(long = "skip-known-owners")]
pub skip_known_owners: bool,
#[structopt(long = "for-id")]
pub for_id: Option<String>,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Trust {
pub pub_ids: Vec<String>,
#[structopt(flatten)]
pub common_proof_create: CommonProofCreate,
}
#[derive(Debug, StructOpt, Clone)]
pub struct FetchUrl {
pub url: String,
}
#[derive(Debug, StructOpt, Clone)]
pub enum Fetch {
#[structopt(name = "trusted")]
Trusted(TrustDistanceParams),
#[structopt(name = "url")]
Url(FetchUrl),
#[structopt(name = "all")]
All,
}
#[derive(Debug, StructOpt, Clone)]
pub enum QueryId {
#[structopt(name = "current")]
Current,
#[structopt(name = "all")]
All,
#[structopt(name = "own")]
Own,
#[structopt(name = "trusted")]
Trusted {
#[structopt(flatten)]
trust_params: TrustDistanceParams,
#[structopt(long = "for-id")]
for_id: Option<String>,
},
}
#[derive(Debug, StructOpt, Clone)]
pub struct QueryReview {
#[structopt(flatten)]
pub crate_: CrateSelector,
}
#[derive(Debug, StructOpt, Clone)]
pub struct QueryAdvisory {
#[structopt(flatten)]
pub crate_: CrateSelector,
}
#[derive(Debug, StructOpt, Clone)]
pub struct QueryIssue {
#[structopt(flatten)]
pub crate_: CrateSelector,
#[structopt(flatten)]
pub trust_params: TrustDistanceParams,
#[structopt(long = "trust", default_value = "none")]
pub trust_level: crev_data::Level,
}
#[derive(Debug, StructOpt, Clone)]
pub struct QueryDir {
#[structopt(flatten)]
pub common: ReviewOrGotoCommon,
}
#[derive(Debug, StructOpt, Clone)]
pub enum Query {
#[structopt(name = "id")]
Id(QueryId),
#[structopt(name = "review")]
Review(QueryReview),
#[structopt(name = "advisory")]
Advisory(QueryAdvisory),
#[structopt(name = "issue")]
Issue(QueryIssue),
#[structopt(name = "dir")]
Dir(QueryDir),
}
#[derive(Debug, StructOpt, Clone)]
pub enum Switch {
#[structopt(name = "id")]
Id(SwitchId),
}
#[derive(Debug, StructOpt, Clone)]
pub enum Edit {
#[structopt(name = "readme")]
Readme,
#[structopt(name = "config")]
Config,
#[structopt(name = "known")]
Known,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Git {
#[structopt(parse(from_os_str))]
pub args: Vec<OsString>,
}
#[derive(Debug, StructOpt, Clone)]
pub struct ReviewOrGotoCommon {
#[structopt(flatten)]
pub crate_: CrateSelector,
#[structopt(long = "unrelated", short = "u")]
pub unrelated: bool,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Open {
#[structopt(long = "cmd")]
pub cmd: Option<String>,
#[structopt(long = "cmd-save")]
pub cmd_save: bool,
#[structopt(flatten)]
pub common: ReviewOrGotoCommon,
}
#[derive(Debug, StructOpt, Clone)]
pub struct CommonProofCreate {
#[structopt(long = "no-commit")]
pub no_commit: bool,
#[structopt(long = "print-unsigned")]
pub print_unsigned: bool,
#[structopt(long = "print-signed")]
pub print_signed: bool,
#[structopt(long = "no-store")]
pub no_store: bool,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Review {
#[structopt(flatten)]
pub common: ReviewOrGotoCommon,
#[structopt(flatten)]
pub common_proof_create: CommonProofCreate,
#[structopt(long = "advisory")]
pub advisory: bool,
#[structopt(long = "issue")]
pub issue: bool,
#[structopt(long = "skip-activity-check")]
pub skip_activity_check: bool,
#[structopt(long = "diff")]
#[allow(clippy::option_option)]
pub diff: Option<Option<semver::Version>>,
}
#[derive(Debug, StructOpt, Clone, Default)]
pub struct AdviseCommon {
#[structopt(long = "affected", default_value = "major")]
pub affected: crev_data::proof::review::package::VersionRange,
#[structopt(long = "severity", default_value = "medium")]
pub severity: Level,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Advise {
#[structopt(flatten)]
pub common: ReviewOrGotoCommon,
#[structopt(flatten)]
pub common_proof_create: CommonProofCreate,
#[structopt(flatten)]
pub advise_common: AdviseCommon,
}
#[derive(Debug, StructOpt, Clone, Default)]
pub struct ReportCommon {
#[structopt(long = "severity", default_value = "medium")]
pub severity: Level,
}
#[derive(Debug, StructOpt, Clone)]
pub struct Report {
#[structopt(flatten)]
pub common: ReviewOrGotoCommon,
#[structopt(flatten)]
pub common_proof_create: CommonProofCreate,
#[structopt(flatten)]
pub report_common: ReportCommon,
}
#[derive(Debug, StructOpt, Clone)]
pub struct ExportId {
pub id: Option<String>,
}
#[derive(Debug, StructOpt, Clone)]
pub enum Export {
#[structopt(name = "id")]
Id(ExportId),
}
#[derive(Debug, StructOpt, Clone)]
pub enum Import {
#[structopt(name = "id")]
Id,
#[structopt(name = "proof")]
Proof(ImportProof),
}
#[derive(Debug, StructOpt, Clone)]
pub struct ImportProof {
#[structopt(long = "reset-date")]
pub reset_date: bool,
#[structopt(flatten)]
pub common: CommonProofCreate,
}
#[derive(Debug, StructOpt, Clone)]
pub enum Command {
#[structopt(name = "new")]
New(New),
#[structopt(name = "switch")]
Switch(Switch),
#[structopt(name = "edit")]
Edit(Edit),
#[structopt(name = "verify")]
Verify(Verify),
#[structopt(name = "review")]
Review(Review),
#[structopt(name = "flag")]
Flag(Review),
#[structopt(name = "report")]
Report(Report),
#[structopt(name = "advise")]
Advise(Advise),
#[structopt(name = "query")]
Query(Query),
#[structopt(name = "trust")]
Trust(Trust),
#[structopt(name = "distrust")]
Distrust(Trust),
#[structopt(name = "fetch")]
Fetch(Fetch),
#[structopt(name = "git")]
#[structopt(raw(setting = "structopt::clap::AppSettings::TrailingVarArg"))]
#[structopt(raw(setting = "structopt::clap::AppSettings::AllowLeadingHyphen"))]
Git(Git),
#[structopt(name = "push")]
Push,
#[structopt(name = "publish")]
Publish,
#[structopt(name = "pull")]
Pull,
#[structopt(name = "goto")]
Goto(ReviewOrGotoCommon),
#[structopt(name = "open")]
Open(Open),
#[structopt(name = "clean")]
Clean(ReviewOrGotoCommon),
#[structopt(name = "export")]
Export(Export),
#[structopt(name = "import")]
Import(Import),
#[structopt(name = "update")]
Update,
#[structopt(name = "diff")]
#[structopt(raw(setting = "structopt::clap::AppSettings::TrailingVarArg"))]
#[structopt(raw(setting = "structopt::clap::AppSettings::AllowLeadingHyphen"))]
Diff(Diff),
}
#[derive(Debug, StructOpt, Clone)]
pub enum MainCommand {
#[structopt(name = "crev")]
Crev(Command),
}
#[derive(Debug, StructOpt, Clone)]
#[structopt(about = "Distributed code review system")]
pub struct Opts {
#[structopt(subcommand)]
pub command: MainCommand,
}