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;
|
mod list;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
@ -9,12 +10,15 @@ use crate::Environment;
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
#[command(visible_alias = "l")]
|
#[command(visible_alias = "l")]
|
||||||
List(list::Command),
|
List(list::Command),
|
||||||
|
#[command(visible_alias = "a")]
|
||||||
|
Add(add::Command),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::List(command) => command.run(env),
|
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;
|
use crate::Environment;
|
||||||
|
|
||||||
/// List all notes in the current repository.
|
/// List all notes in the selected repository.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct Command {}
|
pub struct Command {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod ids;
|
pub mod ids;
|
||||||
mod repo;
|
pub mod repo;
|
||||||
|
|
||||||
pub const PROPER_NAME: &str = "GedächtNAS";
|
pub const PROPER_NAME: &str = "GedächtNAS";
|
||||||
pub const TECHNICAL_NAME: &str = "gedaechtnas";
|
pub const TECHNICAL_NAME: &str = "gedaechtnas";
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use anyhow::{anyhow, bail};
|
||||||
use git2::{Commit, ErrorCode, Oid, Reference, Repository};
|
use git2::{Commit, ErrorCode, Oid, Reference, Repository};
|
||||||
use jiff::Zoned;
|
use jiff::Zoned;
|
||||||
|
|
||||||
pub use self::v1::{Repo, VERSION};
|
pub use self::v1::{Note, Repo, VERSION};
|
||||||
|
|
||||||
const VERSION_FILE: &str = "VERSION";
|
const VERSION_FILE: &str = "VERSION";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue