step twenty: tag, implement cli command
This commit is contained in:
parent
41cf24d2bd
commit
019729a3fe
|
@ -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
|
||||
|
|
18
src/main.rs
18
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue