diff options
author | Matan Kushner <hello@matchai.me> | 2019-04-19 16:57:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-19 16:57:14 -0400 |
commit | 022e0002e40d9286677ae59e751b4b873dce6e95 (patch) | |
tree | 3769e569da5bbdeeb1c9c9759806deea5e1608f6 /src/context.rs | |
parent | 6d7485cf5017d05596db85ce49bc979ee3319057 (diff) |
Use "context" to contain run details (#14)
* Create "context" to contain run details
* Use context in tests and benchmarks
Diffstat (limited to 'src/context.rs')
-rw-r--r-- | src/context.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs new file mode 100644 index 000000000..32e9fab11 --- /dev/null +++ b/src/context.rs @@ -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, + } + } +} |