2019-04-16 00:54:52 +00:00
|
|
|
use clap::{App, Arg};
|
2019-04-19 20:57:14 +00:00
|
|
|
use starship::context::Context;
|
2019-04-16 00:54:52 +00:00
|
|
|
use starship::modules;
|
2019-04-19 20:57:14 +00:00
|
|
|
use std::path::PathBuf;
|
2019-04-16 00:54:52 +00:00
|
|
|
|
2019-04-23 18:51:08 +00:00
|
|
|
#[allow(dead_code)]
|
2019-04-19 20:57:14 +00:00
|
|
|
pub fn render_segment<T>(module: &str, path: T) -> String
|
|
|
|
where
|
|
|
|
T: Into<PathBuf>,
|
|
|
|
{
|
2019-04-23 18:51:08 +00:00
|
|
|
render_segment_with_status(module, path.into(), "0")
|
2019-04-16 00:54:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 20:57:14 +00:00
|
|
|
pub fn render_segment_with_status<T>(module: &str, path: T, status: &str) -> String
|
|
|
|
where
|
|
|
|
T: Into<PathBuf>,
|
|
|
|
{
|
2019-04-16 00:54:52 +00:00
|
|
|
// Create an `Arg` with status_code of "0"
|
|
|
|
let args = App::new("starship")
|
|
|
|
.arg(Arg::with_name("status_code"))
|
|
|
|
.get_matches_from(vec!["starship", status]);
|
2019-04-19 20:57:14 +00:00
|
|
|
let context = Context::new_with_dir(args, path.into());
|
2019-04-16 00:54:52 +00:00
|
|
|
|
2019-04-19 20:57:14 +00:00
|
|
|
let segment = modules::handle(module, &context);
|
2019-04-16 00:54:52 +00:00
|
|
|
|
|
|
|
segment.unwrap().output()
|
|
|
|
}
|