Skip to content

Commit

Permalink
feat: Make xtask rfd new include title in RFD file
Browse files Browse the repository at this point in the history
Previously when making a new RFD, the `xtask` command would generate
one without a YAML frontmatter, which would cause compilation with
`zola` to fail. This fixes that, now including a YAML frontmatter
with a `title` field filled with the title the user provided on
the CLI.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored and j-lanson committed Sep 20, 2024
1 parent 58c57e2 commit 52f6560
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions xtask/src/task/buf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

use crate::workspace;
use anyhow::{Context, Result};
use pathbuf::pathbuf;
Expand Down
22 changes: 19 additions & 3 deletions xtask/src/task/rfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
//! Tasks to list or create RFDs
use crate::{NewRfdArgs, RfdArgs};
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context as _, Result};
use convert_case::{Case, Casing as _};
use glob::{glob, Paths};
use pathbuf::pathbuf;
use std::{fs::File, path::PathBuf};
use std::{
fs::File,
io::{BufWriter, Write as _},
path::PathBuf,
};

/// Run the `rfd` command.
pub fn run(args: RfdArgs) -> Result<()> {
Expand Down Expand Up @@ -38,13 +42,25 @@ fn new(args: NewRfdArgs) -> Result<()> {
let title = args.title.to_case(Case::Kebab);
let file_name = format!("{:04}-{}.md", id, title);
let path = pathbuf![&root, "site", "content", "rfds", &file_name];
let _ = File::create_new(path)?;
let file = File::create_new(path).context("failed to create new RFD file")?;

let mut file = BufWriter::new(file);

writeln!(&mut file, "---")
.and_then(|_| writeln!(&mut file, "title: \"{}\"", args.title))
.and_then(|_| writeln!(&mut file, "---"))
.context("failed to write to new RFD file")?;

file.flush()
.context("failed to flush writes to RFD file to disk")?;

log::warn!(
"created draft RFD #{}: \"{}\", at '{}'",
id,
args.title,
pathbuf!["docs", "rfds", &file_name].display()
);

Ok(())
}

Expand Down

0 comments on commit 52f6560

Please sign in to comment.