-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,279 additions
and
715 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version = "1" | ||
|
||
[source] | ||
pattern = "src/**/*.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{ | ||
extract, | ||
manifest::{Requirement, Source}, | ||
report, | ||
}; | ||
use clap::Parser; | ||
use duvet_core::{env, path::Path, query, Result}; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct Arguments { | ||
#[clap(short, long, global = true)] | ||
pub config: Option<Path>, | ||
|
||
#[command(subcommand)] | ||
pub command: Command, | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum Command { | ||
Extract(extract::Extract), | ||
Report(report::Report), | ||
} | ||
|
||
impl Arguments { | ||
pub async fn exec(&self) -> Result<()> { | ||
match &self.command { | ||
Command::Extract(args) => args.exec().await, | ||
Command::Report(args) => args.exec().await, | ||
} | ||
} | ||
|
||
pub fn load_sources(&self, sources: &mut Vec<Source>) { | ||
match &self.command { | ||
Command::Extract(_) => (), | ||
Command::Report(args) => args.load_sources(sources), | ||
} | ||
} | ||
|
||
pub fn load_requirements(&self, requirements: &mut Vec<Requirement>) { | ||
match &self.command { | ||
Command::Extract(_) => (), | ||
Command::Report(args) => args.load_requirements(requirements), | ||
} | ||
} | ||
} | ||
|
||
#[query] | ||
pub async fn get() -> Arc<Arguments> { | ||
let args = env::args(); | ||
Arc::new(Arguments::parse_from(args.iter())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::annotation::{AnnotationSet, AnnotationType}; | ||
use anyhow::anyhow; | ||
use duvet_core::{diagnostic::Error, file::SourceFile}; | ||
use std::sync::Arc; | ||
|
||
pub mod parser; | ||
pub mod tokenizer; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub fn extract( | ||
file: &SourceFile, | ||
pattern: &Pattern, | ||
default_type: AnnotationType, | ||
) -> (AnnotationSet, Vec<Error>) { | ||
let tokens = tokenizer::tokens(file, pattern); | ||
let mut parser = parser::parse(tokens, default_type); | ||
|
||
let annotations = (&mut parser).collect(); | ||
let errors = parser.errors(); | ||
|
||
(annotations, errors) | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
pub struct Pattern { | ||
pub meta: Arc<str>, | ||
pub content: Arc<str>, | ||
} | ||
|
||
impl Default for Pattern { | ||
fn default() -> Self { | ||
Self { | ||
meta: "//=".into(), | ||
content: "//#".into(), | ||
} | ||
} | ||
} | ||
|
||
impl Pattern { | ||
pub fn from_arg(arg: &str) -> Result<Self, anyhow::Error> { | ||
let mut parts = arg.split(',').filter(|p| !p.is_empty()); | ||
let meta = parts.next().expect("should have at least one pattern"); | ||
if meta.is_empty() { | ||
return Err(anyhow!("compliance pattern cannot be empty")); | ||
} | ||
|
||
let content = parts.next().unwrap(); | ||
|
||
let meta = meta.into(); | ||
let content = content.into(); | ||
|
||
Ok(Self { meta, content }) | ||
} | ||
} |
Oops, something went wrong.