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
+5 -4
View File
@@ -1,21 +1,22 @@
use super::Segment;
use ansi_term::Color;
use clap::ArgMatches;
use std::fs::{self, DirEntry};
use std::path::Path;
use std::process::Command;
use super::Segment;
use crate::context::Context;
/// Creates a segment with the current Node.js version
///
/// Will display the Node.js version if any of the following criteria are met:
/// - Current directory contains a `.js` file
/// - Current directory contains a `node_modules` directory
/// - Current directory contains a `package.json` file
pub fn segment(current_dir: &Path, _args: &ArgMatches) -> Option<Segment> {
pub fn segment(context: &Context) -> Option<Segment> {
const NODE_CHAR: &str = "";
const SECTION_COLOR: Color = Color::Green;
let mut segment = Segment::new("node");
let current_dir = &context.current_dir;
let files = fs::read_dir(current_dir).unwrap();
// Early return if there are no JS project files