pub struct Scope { /* private fields */ }Expand description
The declaration, compiled, with where it came from.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn compile(declaration: Declaration, origin: Origin, path: &str) -> Self
pub fn compile(declaration: Declaration, origin: Origin, path: &str) -> Self
Compile a declaration read from path (repository-relative, or the share path).
Sourcepub fn load(share: &Share, repo: &Repository) -> Result<Self, Error>
pub fn load(share: &Share, repo: &Repository) -> Result<Self, Error>
Read the repository’s declaration when its manifest names a scope section,
otherwise the distribution’s default under the share directory.
Sourcepub fn declaration(&self) -> &Declaration
pub fn declaration(&self) -> &Declaration
The declaration as read.
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
The file the declaration was read from: repository-relative for the repository’s own, the share path for the distribution’s.
Sourcepub fn classify_name(&self, path: &str, directory: bool) -> Classification
pub fn classify_name(&self, path: &str, directory: bool) -> Classification
Judge a repository-relative path by its name alone: the out paths and names, then
the in pathspecs. Size and content are not consulted; Scope::classify does.
A directory is in when an in pathspec can match beneath it.
use majordomus_cli::scope::{Declaration, Origin, Reason, Scope, Verdict};
use std::path::Path;
let text = "version: 1\nin:\n - src/**\n - docs/**\nout:\n paths: ['.git/', '**/target/']\n secret:\n names: ['.env', '*.pem']\n";
let scope = Scope::compile(Declaration::parse(Path::new("s"), text).unwrap(), Origin::Repository, "s");
assert_eq!(scope.classify_name("src/main.rs", false).verdict, Verdict::In);
assert_eq!(scope.classify_name("src/.env", false).reason, Some(Reason::Secret));
assert_eq!(scope.classify_name("src/target/x.rs", false).reason, Some(Reason::Path));
assert_eq!(scope.classify_name("README.md", false).reason, Some(Reason::Undeclared));
assert_eq!(scope.classify_name("docs", true).verdict, Verdict::In);Sourcepub fn classify(&self, root: &Path, path: &str) -> Classification
pub fn classify(&self, root: &Path, path: &str) -> Classification
Judge a repository-relative path by name, then, when it exists as a file the name
admits, by size and by the first SNIFF_BYTES of its content. A symlink is judged
by name only and reported as not existing: sources are regular files.
Sourcepub fn tally(&self, root: &Path, files: &[String]) -> Tally
pub fn tally(&self, root: &Path, files: &[String]) -> Tally
Every tracked file judged by name and size, counted; the out ones listed with their reason. Content is not read: a binary is caught here only by its name.
Sourcepub fn tally_repository(
&self,
repo: &Repository,
source: &dyn DiscoverySource,
) -> Result<(Tally, Vec<Diagnostic>), Error>
pub fn tally_repository( &self, repo: &Repository, source: &dyn DiscoverySource, ) -> Result<(Tally, Vec<Diagnostic>), Error>
The tracked files of the repository, through source, judged: the tally, and a
diagnostic for every tracked secret, which is never read and should not be tracked.