-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9338e22
commit 6836618
Showing
11 changed files
with
244 additions
and
119 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::{fs::create_dir_all, path::PathBuf}; | ||
|
||
use anyhow::Result; | ||
use clap::Args; | ||
use serde::Serialize; | ||
use tinytemplate::TinyTemplate; | ||
|
||
use crate::{adr_filename, next_adr_sequence, now}; | ||
|
||
static INIT_TEMPLATE: &str = include_str!("../templates/nygard/init.md"); | ||
|
||
#[derive(Debug, Args)] | ||
#[command(version, about, long_about = None)] | ||
pub(crate) struct InitArgs { | ||
/// Directory to initialize | ||
#[arg(default_value = "doc/adr")] | ||
pub(crate) directory: PathBuf, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct InitAdrContext { | ||
number: i32, | ||
date: String, | ||
} | ||
|
||
pub(crate) fn run(args: &InitArgs) -> Result<()> { | ||
create_dir_all(&args.directory)?; | ||
|
||
let filename = format!( | ||
"{}/{:0>4}-{}.md", | ||
args.directory.to_str().unwrap(), | ||
next_adr_sequence(&args.directory)?, | ||
adr_filename("Record architecture decisions") | ||
); | ||
|
||
let init_context = InitAdrContext { | ||
number: next_adr_sequence(&args.directory)?, | ||
date: now()?, | ||
}; | ||
|
||
let mut tt = TinyTemplate::new(); | ||
tt.add_template("init_adr", INIT_TEMPLATE)?; | ||
let rendered = tt.render("init_adr", &init_context)?; | ||
std::fs::write(&filename, rendered)?; | ||
|
||
tracing::debug!("Created {}", filename); | ||
|
||
std::fs::write( | ||
std::env::current_dir()?.join(".adr-dir"), | ||
args.directory.to_str().unwrap(), | ||
)?; | ||
|
||
tracing::debug!("Wrote .adr-dir"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::fs::read_to_string; | ||
|
||
use anyhow::Result; | ||
use clap::Args; | ||
use edit::edit; | ||
use serde::Serialize; | ||
use tinytemplate::TinyTemplate; | ||
|
||
use crate::{adr_filename, next_adr_sequence, now}; | ||
|
||
static NEW_TEMPLATE: &str = include_str!("../templates/nygard/new.md"); | ||
|
||
#[derive(Debug, Args)] | ||
#[command(version, about, long_about = None)] | ||
pub(crate) struct NewArgs { | ||
/// A reference to a previous decision to supercede with this new one | ||
#[arg(short, long)] | ||
superceded: Option<Vec<String>>, | ||
/// Link the new Architectural Decision to a previous Architectural Decision Record | ||
#[arg(short, long)] | ||
link: Option<Vec<String>>, | ||
/// Title of the new Architectural Decision Record | ||
#[arg(trailing_var_arg = true, required = true)] | ||
title: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct NewAdrContext { | ||
number: i32, | ||
title: String, | ||
date: String, | ||
} | ||
|
||
pub(crate) fn run(args: &NewArgs) -> Result<()> { | ||
let adr_dir = read_to_string(".adr-dir")?; | ||
|
||
let new_context = NewAdrContext { | ||
number: next_adr_sequence(&adr_dir)?, | ||
date: now()?, | ||
title: args.title.join(" "), | ||
}; | ||
|
||
let mut tt = TinyTemplate::new(); | ||
tt.add_template("new_adr", NEW_TEMPLATE)?; | ||
let rendered = tt.render("new_adr", &new_context)?; | ||
let edited = edit(rendered)?; | ||
|
||
let filename = format!( | ||
"{}/{:0>4}-{}.md", | ||
adr_dir, | ||
new_context.number, | ||
adr_filename(&new_context.title), | ||
); | ||
std::fs::write(&filename, edited)?; | ||
|
||
tracing::debug!("Created {}", filename); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.