feat: add update command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2024-09-26 21:36:03 +02:00
parent e3292b0c73
commit 17cb06904f
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
4 changed files with 33 additions and 3 deletions

View File

@ -1,9 +1,16 @@
function git-now {
# Run an update in the background
(
nohup gitnow update > /dev/null 2>&1 &
)
# Find the repository of choice
choice=$(gitnow "$@" --no-shell)
if [[ $? -ne 0 ]]; then
return $?
fi
# Enter local repository path
cd "$(echo "$choice" | tail --lines 1)"
}

View File

@ -1,2 +1,3 @@
pub mod root;
pub mod shell;
pub mod update;

View File

@ -0,0 +1,14 @@
use crate::{app::App, cache::CacheApp, projects_list::ProjectsListApp};
#[derive(clap::Parser)]
pub struct Update {}
impl Update {
pub async fn execute(&mut self, app: &'static App) -> anyhow::Result<()> {
let repositories = app.projects_list().get_projects().await?;
app.cache().update(&repositories).await?;
Ok(())
}
}

View File

@ -4,7 +4,7 @@ use std::path::PathBuf;
use anyhow::Context;
use clap::{Parser, Subcommand};
use commands::{root::RootCommand, shell::Shell};
use commands::{root::RootCommand, shell::Shell, update::Update};
use config::Config;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
@ -50,6 +50,7 @@ struct Command {
#[derive(Subcommand)]
enum Commands {
Init(Shell),
Update(Update),
}
const DEFAULT_CONFIG_PATH: &str = ".config/gitnow/gitnow.toml";
@ -80,7 +81,14 @@ async fn main() -> anyhow::Result<()> {
tracing::debug!("Starting cli");
match cli.command {
Some(Commands::Init(mut shell)) => shell.execute().await?,
Some(cmd) => match cmd {
Commands::Init(mut shell) => {
shell.execute().await?;
}
Commands::Update(mut update) => {
update.execute(app).await?;
}
},
None => {
RootCommand::new(app)
.execute(