diff --git a/crates/gitnow/include/shell/zsh.sh b/crates/gitnow/include/shell/zsh.sh index cbfd2ea..4eaa5c2 100644 --- a/crates/gitnow/include/shell/zsh.sh +++ b/crates/gitnow/include/shell/zsh.sh @@ -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)" } diff --git a/crates/gitnow/src/commands.rs b/crates/gitnow/src/commands.rs index 30cd74e..d6de77d 100644 --- a/crates/gitnow/src/commands.rs +++ b/crates/gitnow/src/commands.rs @@ -1,2 +1,3 @@ pub mod root; pub mod shell; +pub mod update; diff --git a/crates/gitnow/src/commands/update.rs b/crates/gitnow/src/commands/update.rs new file mode 100644 index 0000000..69a27c4 --- /dev/null +++ b/crates/gitnow/src/commands/update.rs @@ -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(()) + } +} diff --git a/crates/gitnow/src/main.rs b/crates/gitnow/src/main.rs index c21ef01..7939011 100644 --- a/crates/gitnow/src/main.rs +++ b/crates/gitnow/src/main.rs @@ -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(