step twenty: tag, implement cli command

This commit is contained in:
Gonçalo Valério 2020-11-03 23:49:43 +00:00
parent 41cf24d2bd
commit 019729a3fe
2 changed files with 22 additions and 0 deletions

View File

@ -115,6 +115,10 @@ pub fn checkout(oid: String) {
data::set_head(oid);
}
pub fn create_tag(name: String, oid: String) {
println!("{} - {}", name, oid);
}
fn is_ignored(path: &String) -> bool {
if path.contains(".rgit") {
true

View File

@ -48,6 +48,12 @@ fn main() {
.about("Move the current content and HEAD to given commit")
.arg(Arg::with_name("oid").index(1).required(true)),
)
.subcommand(
SubCommand::with_name("tag")
.about("Create a tag for a given commit")
.arg(Arg::with_name("name").index(1).required(true))
.arg(Arg::with_name("oid").index(2).required(false)),
)
.get_matches();
match matches.subcommand_name() {
@ -59,6 +65,7 @@ fn main() {
Some("commit") => commit(matches),
Some("log") => log_commits(matches),
Some("checkout") => checkout(matches),
Some("tag") => tag(matches),
_ => println!("unknown sub command"),
}
}
@ -139,3 +146,14 @@ fn checkout(matches: ArgMatches) {
base::checkout(oid);
}
}
fn tag(matches: ArgMatches) {
if let Some(cmd_matches) = matches.subcommand_matches("tag") {
let name = cmd_matches.value_of("name").unwrap().to_owned();
let mut oid = cmd_matches.value_of("oid").unwrap_or("").to_owned();
if oid == "" {
oid = data::get_head().expect("Cannot read HEAD");
}
base::create_tag(name, oid);
}
}