From feb6d8aec7b95a71a1eb95b2eb3f4e9b39e99318 Mon Sep 17 00:00:00 2001 From: Matan Kushner Date: Mon, 15 Jul 2019 18:18:19 -0400 Subject: [PATCH] refactor: Better document context contents --- src/context.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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, + + /// 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, + + /// 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, } 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(arguments: ArgMatches, dir: T) -> Context where T: Into,