aaaaaaa
This commit is contained in:
24
src/git.rs
24
src/git.rs
@@ -1,5 +1,5 @@
|
||||
use clap::Subcommand;
|
||||
use std::process::Command;
|
||||
use openssh::{Session, KnownHosts};
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum GitCommand {
|
||||
@@ -7,23 +7,29 @@ pub enum GitCommand {
|
||||
#[arg()]
|
||||
name: String
|
||||
},
|
||||
|
||||
List,
|
||||
|
||||
Delete {
|
||||
#[arg()]
|
||||
name: String
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_git(cmd: &GitCommand) {
|
||||
pub async fn handle_git(cmd: &GitCommand) {
|
||||
let session = Session::connect("git@breadpi", KnownHosts::Strict)
|
||||
.await
|
||||
.expect("Could not connect to git@breadpi");
|
||||
|
||||
match cmd {
|
||||
GitCommand::Create { name } => {
|
||||
let path = format!("git@breadpi:~/store/{}", name);
|
||||
let git_create = Command::new("ssh")
|
||||
.args([path])
|
||||
.spawn()
|
||||
.expect("Could not create remote repo!");
|
||||
let mkdir = format!("~/store/{name}");
|
||||
let cd = format!("cd ~/store/{name}");
|
||||
let init = format!("git --bare init");
|
||||
|
||||
session.command(mkdir)
|
||||
.args(["-p", &mkdir])
|
||||
.output().await.unwrap();
|
||||
session.command(cd).output().await.unwrap();
|
||||
session.command(init).output().await.unwrap();
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod git;
|
||||
|
||||
use tokio;
|
||||
use clap::{Parser, Subcommand};
|
||||
use crate::git::{handle_git, GitCommand};
|
||||
|
||||
@@ -18,12 +19,13 @@ struct Cli {
|
||||
command: Command
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args = Cli::parse();
|
||||
|
||||
match &args.command {
|
||||
Command::Git { git_command } => {
|
||||
handle_git(&git_command);
|
||||
handle_git(&git_command).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user