Add repo add and repo show commands
This commit is contained in:
parent
b922af9283
commit
2c5ff584db
10 changed files with 219 additions and 4 deletions
22
gdn-cli/src/commands/repo.rs
Normal file
22
gdn-cli/src/commands/repo.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
mod add;
|
||||
mod show;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::Environment;
|
||||
|
||||
/// Perform repo operations.
|
||||
#[derive(Debug, Parser)]
|
||||
pub enum Command {
|
||||
Show(show::Command),
|
||||
Add(add::Command),
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
match self {
|
||||
Self::Show(command) => command.run(env),
|
||||
Self::Add(command) => command.run(env),
|
||||
}
|
||||
}
|
||||
}
|
||||
18
gdn-cli/src/commands/repo/add.rs
Normal file
18
gdn-cli/src/commands/repo/add.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use clap::Parser;
|
||||
|
||||
use crate::Environment;
|
||||
|
||||
/// Add a new repository.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Command {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
let data = gdn::data::open_and_migrate(env.data_dir.clone())?;
|
||||
let id = gdn::data::add_repo(&data, self.name.clone())?;
|
||||
println!("Added repo {} ({id}).", self.name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
30
gdn-cli/src/commands/repo/show.rs
Normal file
30
gdn-cli/src/commands/repo/show.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use clap::Parser;
|
||||
use gdn::data::REPO_VERSION;
|
||||
|
||||
use crate::Environment;
|
||||
|
||||
/// Show info about a repository.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Command {
|
||||
repo: String,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
let data = gdn::data::open(env.data_dir.clone())?;
|
||||
let state = gdn::data::load_state(&data)?;
|
||||
|
||||
let Some(id) = state.resolve_repo_identifier(&self.repo) else {
|
||||
println!("No repo found for identifier {}.", self.repo);
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let version = gdn::data::load_repo_version(&data, id)?;
|
||||
let repo = gdn::data::load_repo(&data, id)?;
|
||||
|
||||
println!("Repo version: {version} (latest: {REPO_VERSION})",);
|
||||
println!("Number of notes: {}", repo.notes.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue