Add note add command
This commit is contained in:
parent
3390526522
commit
e2436328b7
5 changed files with 41 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
mod add;
|
||||
mod list;
|
||||
|
||||
use clap::Parser;
|
||||
|
|
@ -9,12 +10,15 @@ use crate::Environment;
|
|||
pub enum Command {
|
||||
#[command(visible_alias = "l")]
|
||||
List(list::Command),
|
||||
#[command(visible_alias = "a")]
|
||||
Add(add::Command),
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
match self {
|
||||
Self::List(command) => command.run(env),
|
||||
Self::Add(command) => command.run(env),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
gdn-cli/src/commands/note/add.rs
Normal file
34
gdn-cli/src/commands/note/add.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use clap::Parser;
|
||||
use gdn::ids::NoteId;
|
||||
use gdn::repo::Note;
|
||||
|
||||
use crate::Environment;
|
||||
|
||||
/// Add a note to the selected repository.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Command {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||
let data = gdn::data::open_and_migrate(env.data_dir.clone())?;
|
||||
let state = gdn::data::load_state(&data)?;
|
||||
let Some(selected) = state.selected_repo else {
|
||||
println!("No repo selected");
|
||||
return Ok(());
|
||||
};
|
||||
let mut repo = gdn::data::load_repo(&data, selected)?;
|
||||
|
||||
repo.notes.push(Note {
|
||||
id: NoteId::new(),
|
||||
text: self.text,
|
||||
children: vec![],
|
||||
});
|
||||
|
||||
let oid = gdn::data::save_repo(&data, selected, repo)?;
|
||||
println!("Note added ({oid}).");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ use clap::Parser;
|
|||
|
||||
use crate::Environment;
|
||||
|
||||
/// List all notes in the current repository.
|
||||
/// List all notes in the selected repository.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Command {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub mod data;
|
||||
pub mod ids;
|
||||
mod repo;
|
||||
pub mod repo;
|
||||
|
||||
pub const PROPER_NAME: &str = "GedächtNAS";
|
||||
pub const TECHNICAL_NAME: &str = "gedaechtnas";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use anyhow::{anyhow, bail};
|
|||
use git2::{Commit, ErrorCode, Oid, Reference, Repository};
|
||||
use jiff::Zoned;
|
||||
|
||||
pub use self::v1::{Repo, VERSION};
|
||||
pub use self::v1::{Note, Repo, VERSION};
|
||||
|
||||
const VERSION_FILE: &str = "VERSION";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue