diff options
author | Matan Kushner <hello@matchai.me> | 2019-07-15 18:18:19 -0400 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-07-19 18:45:38 -0400 |
commit | feb6d8aec7b95a71a1eb95b2eb3f4e9b39e99318 (patch) | |
tree | e889956833288e7ef29b090461c9630096fcc095 /src | |
parent | 274e411f7d1bb538b3a8dde6357741ae29b36509 (diff) |
refactor: Better document context contents
Diffstat (limited to 'src')
-rw-r--r-- | src/context.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs index dd8e63435..e8ca107f1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -8,16 +8,34 @@ use std::ffi::OsStr; use std::fs; use std::path::PathBuf; +/// Context contains data or common methods that may be used by multiple modules. +/// The data contained within Context will be relevant to this particular rendering +/// of the prompt. pub struct Context<'a> { + /// The deserialized configuration map from the user's `starship.toml` file. pub config: Config, + + /// The current working directory that starship is being called in. pub current_dir: PathBuf, + + /// A vector containing the full paths of all the files in `current_dir`. pub dir_files: Vec<PathBuf>, + + /// The map of arguments that were passed when starship was called. pub arguments: ArgMatches<'a>, + + /// If `current_dir` is a git repository or is contained within one, + /// this is the path to the root of that repo. pub repo_root: Option<PathBuf>, + + /// If `current_dir` is a git repository or is contained within one, + /// this is the current branch name of that repo. pub branch_name: Option<String>, } impl<'a> Context<'a> { + /// Identify the current working directory and create an instance of Context + /// for it. pub fn new(arguments: ArgMatches) -> Context { // Retreive the "path" flag. If unavailable, use the current directory instead. let path = arguments @@ -28,6 +46,7 @@ impl<'a> Context<'a> { Context::new_with_dir(arguments, path) } + /// Create a new instance of Context for the provided directory pub fn new_with_dir<T>(arguments: ArgMatches, dir: T) -> Context where T: Into<PathBuf>, |