Skip to content

Commit

Permalink
feat: support snapshot command (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat authored Aug 9, 2023
1 parent d0efd33 commit 6a4a9ea
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ where
results.into_iter().map(|(_, result)| result).collect()
}

pub fn is_ok<R>(results: &Vec<Result<R>>) -> bool {
for result in results {
if let Err(_) = result {
return false;
}
}
true
}

fn show_done(ok: bool, msg: String, current: usize, total: usize) {
let pad_len = total.to_string().chars().count();
let current_pad = format!("{:pad_len$}", current + 1, pad_len = pad_len);
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::cmd::run::release::ReleaseArgs;
use crate::cmd::run::remove::RemoveArgs;
use crate::cmd::run::reset::ResetArgs;
use crate::cmd::run::run::RunArgs;
use crate::cmd::run::snapshot::SnapshotArgs;
use crate::cmd::run::squash::SquashArgs;
use crate::cmd::run::sync::SyncArgs;
use crate::cmd::run::tag::TagArgs;
Expand Down Expand Up @@ -55,6 +56,7 @@ pub enum Commands {
Import(ImportArgs),
Run(RunArgs),
Sync(SyncArgs),
Snapshot(SnapshotArgs),
}

impl Run for App {
Expand Down Expand Up @@ -85,6 +87,7 @@ impl Run for App {
Commands::Import(args) => args.run(),
Commands::Run(args) => args.run(),
Commands::Sync(args) => args.run(),
Commands::Snapshot(args) => args.run(),
}
}
}
1 change: 1 addition & 0 deletions src/cmd/complete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod owner;
pub mod release;
pub mod remote;
pub mod run;
pub mod snapshot;
pub mod tag;

pub struct Complete {
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/complete/snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anyhow::Result;

use crate::cmd::complete::Complete;
use crate::repo::snapshot::Snapshot;

pub fn complete(args: &[&str]) -> Result<Complete> {
match args.len() {
0 | 1 => {
let names = Snapshot::list()?;
Ok(Complete::from(names))
}
_ => Ok(Complete::empty()),
}
}
2 changes: 1 addition & 1 deletion src/cmd/run/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl BranchArgs {
};
items.push(msg);
}
utils::confirm_items(items, "sync", "synchronization", "Branch", "Branches")?;
utils::confirm_items(&items, "sync", "synchronization", "Branch", "Branches")?;

for task in tasks {
match task {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Run for ClearArgs {
};
let repos = self.filter(repos)?;
let items: Vec<_> = repos.iter().map(|repo| repo.full_name()).collect();
utils::confirm_items(items, "remove", "removal", "Repo", "Repos")?;
utils::confirm_items(&items, "remove", "removal", "Repo", "Repos")?;

for repo in repos.into_iter() {
let path = repo.get_path();
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/run/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::cmd::complete::owner;
use crate::cmd::complete::release;
use crate::cmd::complete::remote;
use crate::cmd::complete::run;
use crate::cmd::complete::snapshot;
use crate::cmd::complete::tag;
use crate::cmd::complete::Complete;
use crate::cmd::Run;
Expand Down Expand Up @@ -61,6 +62,7 @@ impl CompleteArgs {
"import" => owner::complete,
"run" => run::complete,
"sync" => no_complete,
"snapshot" => snapshot::complete,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Run for ImportArgs {
drop(owner_arc);

let items: Vec<_> = tasks.iter().map(|task| format!("{}", task.name)).collect();
utils::confirm_items(items, "import", "import", "Repo", "Repos")?;
utils::confirm_items(&items, "import", "import", "Repo", "Repos")?;

let remote_rc = Rc::new(self.remote.clone());
let owner_rc = Rc::new(self.owner.clone());
Expand Down
1 change: 1 addition & 0 deletions src/cmd/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod release;
pub mod remove;
pub mod reset;
pub mod run;
pub mod snapshot;
pub mod squash;
pub mod sync;
pub mod tag;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Run for RunArgs {
}

let items: Vec<_> = repos.iter().map(|repo| repo.as_string(&level)).collect();
utils::confirm_items(items, "run workflow", "workflow", "Repo", "Repos")?;
utils::confirm_items(&items, "run workflow", "workflow", "Repo", "Repos")?;

let level = Arc::new(level);
let mut tasks = Vec::with_capacity(repos.len());
Expand Down
Loading

0 comments on commit 6a4a9ea

Please sign in to comment.