Use "context" to contain run details (#14)

* Create "context" to contain run details

* Use context in tests and benchmarks
This commit is contained in:
Matan Kushner
2019-04-19 16:57:14 -04:00
committed by GitHub
parent 6d7485cf50
commit 022e0002e4
11 changed files with 81 additions and 45 deletions
+30
View File
@@ -0,0 +1,30 @@
use clap::ArgMatches;
use std::env;
use std::path::PathBuf;
pub struct Context<'a> {
pub current_dir: PathBuf,
pub arguments: ArgMatches<'a>,
}
impl<'a> Context<'a> {
pub fn new(arguments: ArgMatches) -> Context {
// TODO: Currently gets the physical directory. Get the logical directory.
let current_dir = env::current_dir().expect("Unable to identify current directory.");
Context {
current_dir,
arguments,
}
}
pub fn new_with_dir<T>(arguments: ArgMatches, dir: T) -> Context
where
T: Into<PathBuf>,
{
Context {
current_dir: dir.into(),
arguments,
}
}
}