From 019729a3fe1e9b2ab4558191ec42c616563a8f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Val=C3=A9rio?= Date: Tue, 3 Nov 2020 23:49:43 +0000 Subject: [PATCH] step twenty: tag, implement cli command --- src/base.rs | 4 ++++ src/main.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/base.rs b/src/base.rs index 621e4f8..684d202 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index 151a23a..9fb7278 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); + } +}