Skip to content

Commit

Permalink
adding status
Browse files Browse the repository at this point in the history
  • Loading branch information
mckernant1 committed Sep 3, 2019
1 parent b7688ef commit 975ebf0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pm"
version = "0.2.2"
version = "0.3.0"
authors = ["Tom McKernan <tmeaglei@gmail.com>"]
edition = "2018"

Expand Down
12 changes: 9 additions & 3 deletions src/cli.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Project Manager
version: 0.2.2
version: 0.3.0
author: Tom McKernan <tmeaglei@gmail.com>
about: A project manager for your computer
subcommands:
Expand Down Expand Up @@ -41,7 +41,7 @@ subcommands:
required: true
help: The name of the project to delete
- cmd:
about: runs given shell script in project directory. If command doesn't exist you will be prompted for it.
about: runs given command in project directory. If command doesn't exist you will be prompted for it.
args:
- PROJ_NAME:
required: true
Expand All @@ -50,8 +50,14 @@ subcommands:
required: true
help: name of the command to run
- cmds:
about: lists commands for a given project
about: Lists commands for a given project
args:
- PROJ_NAME:
required: true
help: The name of the project
- status:
about: Displays the status of specified repo if none is provided, displays all
args:
- PROJ_NAME:
required: false
help: The name of the project
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod setup;
mod subcommands;

use clap::{App, AppSettings, ArgMatches};
use subcommands::{pull, list, add, delete, clone, cmd, cmds};
use subcommands::{pull, list, add, delete, clone, cmd, cmds, status};
use setup::SettingsFile;


Expand All @@ -18,7 +18,6 @@ fn main() {
.setting(AppSettings::ArgRequiredElseHelp)
.get_matches();
call_subcommands(matches, settings_file)

}

fn call_subcommands(matches: ArgMatches, settings_file: SettingsFile) {
Expand All @@ -36,6 +35,8 @@ fn call_subcommands(matches: ArgMatches, settings_file: SettingsFile) {
cmd(matches, settings_file)
} else if matches.is_present("cmds") {
cmds(matches, settings_file)
} else if matches.is_present("status") {
status(matches, settings_file)
}
}

71 changes: 57 additions & 14 deletions src/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn clone(matches: ArgMatches, settings_file: SettingsFile) {

let mut child = exec_git(
vec!["clone", repo_string.as_str(), repo_dir.clone().as_str()],
Option::from(Stdio::piped()),
Option::from(Stdio::inherit()), Option::from(Stdio::inherit())
);
child.wait().unwrap();
settings_file.clone().add_repo(object! {
Expand All @@ -42,7 +42,7 @@ pub fn pull(matches: ArgMatches, settings_file: SettingsFile) {
m["name"].to_string() == repo_name
}).unwrap()["path"].to_string();
println!("Pulling: {}", repo_name);
exec_git(vec!["-C", path.as_str(), "pull"], Option::None)
exec_git(vec!["-C", path.as_str(), "pull"], Option::None, Option::None)
.wait().unwrap();
println!("Done pulling: {}", repo_name)
} else {
Expand All @@ -51,7 +51,7 @@ pub fn pull(matches: ArgMatches, settings_file: SettingsFile) {
println!("Pulling: {}", member["name"].clone().to_string());
child_list.push((
member["name"].to_string(),
exec_git(vec!["-C", member["path"].as_str().unwrap(), "pull"], Option::None)
exec_git(vec!["-C", member["path"].as_str().unwrap(), "pull"], Option::None, Option::None)
))
}
for child_pair in child_list {
Expand All @@ -62,17 +62,7 @@ pub fn pull(matches: ArgMatches, settings_file: SettingsFile) {
}
}

fn exec_git(args: Vec<&str>, io: Option<Stdio>) -> Child {
let io_option = match io {
Some(io) => io,
None => Stdio::null()
};

Command::new("git")
.args(args)
.stdout(io_option)
.spawn().unwrap()
}

pub fn list(matches: ArgMatches, settings_file: SettingsFile) {
let repos = settings_file.list_repos();
Expand Down Expand Up @@ -172,7 +162,6 @@ pub fn cmds(matches: ArgMatches, settings_file: SettingsFile) {
}
}


fn create_new_cmd(settings_file: SettingsFile, cmd_name: &str, repo_json: JsonValue) {
println!("This command does not exist.");
print!("Please enter the command you want to run in this directory: ");
Expand All @@ -185,3 +174,57 @@ fn create_new_cmd(settings_file: SettingsFile, cmd_name: &str, repo_json: JsonVa

settings_file.add_repo(repo_json_mut);
}

pub fn status(matches: ArgMatches, settings_file: SettingsFile) {
let repo_name = matches
.subcommand_matches("status").unwrap()
.value_of("PROJ_NAME");

match repo_name {
Some(name) => {
let repo_path = settings_file.get_repo_by_name(name)["path"].clone();
println!("Status of {} in {}", name, repo_path);
exec_git(
vec![
"-C",
repo_path.as_str().unwrap(),
"status"
],
Option::from(Stdio::inherit()),
Option::from(Stdio::inherit())
).wait().unwrap();

},
None => {
let repos = settings_file.list_repos();
for member in repos.members() {
let path = member["path"].as_str().unwrap();
let name = member["name"].as_str().unwrap();
let print_string = format!("Status of {} in {}", name, path);
println!("{}\n", print_string);
exec_git(
vec![
"-C",
path,
"status"
],
Option::from(Stdio::inherit()),
Option::from(Stdio::inherit())
).wait().unwrap();
println!("{}", "#".repeat(50));
}
}
};

}

fn exec_git(args: Vec<&str>, stdio: Option<Stdio>, stderr: Option<Stdio>) -> Child {
let stdio_option = stdio.unwrap_or(Stdio::null());
let stderr_option = stderr.unwrap_or(Stdio::null());

Command::new("git")
.args(args)
.stdout(stdio_option)
.stderr(stderr_option)
.spawn().unwrap()
}

0 comments on commit 975ebf0

Please sign in to comment.