feat: add update command
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e3292b0c73
commit
17cb06904f
@ -1,9 +1,16 @@
|
|||||||
function git-now {
|
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)
|
choice=$(gitnow "$@" --no-shell)
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Enter local repository path
|
||||||
cd "$(echo "$choice" | tail --lines 1)"
|
cd "$(echo "$choice" | tail --lines 1)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
pub mod root;
|
pub mod root;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
|
pub mod update;
|
||||||
|
14
crates/gitnow/src/commands/update.rs
Normal file
14
crates/gitnow/src/commands/update.rs
Normal 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(())
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use commands::{root::RootCommand, shell::Shell};
|
use commands::{root::RootCommand, shell::Shell, update::Update};
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
@ -50,6 +50,7 @@ struct Command {
|
|||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Init(Shell),
|
Init(Shell),
|
||||||
|
Update(Update),
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_CONFIG_PATH: &str = ".config/gitnow/gitnow.toml";
|
const DEFAULT_CONFIG_PATH: &str = ".config/gitnow/gitnow.toml";
|
||||||
@ -80,7 +81,14 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
tracing::debug!("Starting cli");
|
tracing::debug!("Starting cli");
|
||||||
|
|
||||||
match cli.command {
|
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 => {
|
None => {
|
||||||
RootCommand::new(app)
|
RootCommand::new(app)
|
||||||
.execute(
|
.execute(
|
||||||
|
Loading…
Reference in New Issue
Block a user