-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from daniel7grant/feature/repository-command
Add repository creation and forking commands
- Loading branch information
Showing
28 changed files
with
2,155 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod args; | |
pub mod config; | ||
pub mod login; | ||
pub mod pr; | ||
pub mod repo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::io::{self, Write}; | ||
|
||
use crate::cmd::{ | ||
args::{Cli, Commands, RepoCommands}, | ||
config::Configuration, | ||
}; | ||
use colored::Colorize; | ||
use eyre::{eyre, Context, ContextCompat, Result}; | ||
use gr_bin::vcs::common::init_vcs; | ||
use gr_bin::{git::git::LocalRepository, vcs::common::VersionControlSettings}; | ||
use tracing::instrument; | ||
|
||
#[instrument(skip_all, fields(command = ?args.command))] | ||
pub fn delete(args: Cli, conf: Configuration) -> Result<()> { | ||
let Cli { | ||
command, | ||
branch, | ||
dir, | ||
auth, | ||
output, | ||
verbose: _, | ||
} = args; | ||
if let Commands::Repo(RepoCommands::Delete { force }) = command { | ||
let repository = LocalRepository::init(dir)?; | ||
let (hostname, repo, ..) = repository.get_parsed_remote(branch)?; | ||
|
||
// Find settings or use the auth command | ||
let settings = conf.find_settings(&hostname, &repo); | ||
let settings = if let Some(auth) = auth { | ||
VersionControlSettings { | ||
auth, | ||
..settings.unwrap_or_default() | ||
} | ||
} else { | ||
settings.wrap_err(eyre!( | ||
"Authentication not found for {} in {}.", | ||
&hostname, | ||
&repo | ||
))? | ||
}; | ||
|
||
let vcs = init_vcs(hostname, repo, settings)?; | ||
|
||
let repo = vcs.get_repository()?; | ||
repo.print(false, output.into()); | ||
|
||
if !force { | ||
println!( | ||
"You are about to {} this repository. {}", | ||
"delete".red().bold(), | ||
"This action cannot be undone!".bold() | ||
); | ||
let mut stdout = io::stdout(); | ||
let stdin = io::stdin(); | ||
write!( | ||
stdout, | ||
"Please enter the repository name if you are absolutely sure: " | ||
)?; | ||
stdout.flush()?; | ||
let mut entered_name = String::new(); | ||
stdin | ||
.read_line(&mut entered_name) | ||
.wrap_err("Reading the repository name failed.")?; | ||
entered_name = entered_name.trim().to_string(); | ||
if entered_name != repo.full_name { | ||
return Err(eyre!( | ||
"You cannot delete {}! You entered: {}.", | ||
repo.full_name, | ||
entered_name | ||
)); | ||
} | ||
} | ||
|
||
vcs.delete_repository()?; | ||
|
||
println!("Repository {} deleted.", repo.full_name); | ||
|
||
Ok(()) | ||
} else { | ||
Err(eyre!("Invalid command!")) | ||
} | ||
} |
Oops, something went wrong.