Skip to content

Commit

Permalink
✨ feat(radar): big update
Browse files Browse the repository at this point in the history
updated commit and version deps, rust cli tool for adrs, radar enhancments,          design system
tooling
  • Loading branch information
alanpcurrie committed Nov 29, 2023
1 parent 148d71c commit 7df3688
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
34 changes: 34 additions & 0 deletions rust_adr_gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Compiled files
/target/

# Rustdoc documentation
/doc/

# Cargo.lock in a library project, keep it for an executable
# (Cargo.lock is not usually checked into version control for libraries)
/Cargo.lock


# These are backup files generated by rustfmt
**/*.rs.bk

# These are auto-generated files for code completion in some editors
**/*.rs.bk

# Dependency directories (remove if you want to track dependencies)
**/vendor/

# Miscellaneous files
.DS_Store
**/*.swp
**/*.swo

# Environment configuration files
.env
.env.*

# Build scripts
/build/

# Ignore npm packages in a WebAssembly project
**/node_modules/
12 changes: 12 additions & 0 deletions rust_adr_gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "rust_adr_gen"
version = "0.1.0"
edition = "2021"


[dependencies]
chrono = "0.4"
colored = "2.0"
indoc = "2"
dialoguer = "0.9"
clap = "3.0"
85 changes: 85 additions & 0 deletions rust_adr_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use chrono::Utc;
use colored::*;
use dialoguer::Input;
use indoc::indoc;
use std::env;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::process;

fn main() {
let current_dir = env::current_dir().unwrap();
println!("Current directory: {}", current_dir.display());

let file_name = env::args().nth(1).unwrap_or_else(|| {
eprintln!("{}", "Error: Please specify a file name".red());
std::process::exit(1);
});

let adrs_dir = match env::var("ADRS_DIR") {
Ok(val) => PathBuf::from(val),
Err(_) => PathBuf::from("../src/pages/adrs"),
};

let file_path = adrs_dir.join(format!("{}.mdx", &file_name));

fs::create_dir_all(&adrs_dir).unwrap_or_else(|e| {
eprintln!("{}", format!("Failed to create directory: {}", e).red());
std::process::exit(1);
});

let context = get_user_input("Enter Context");
let decision = get_user_input("Enter Decision");
let consequences = get_user_input("Enter Consequences");

let content = format!(
indoc! {"
---
title: \"{}\"
date: \"{}\"
---
# {}
## Context
{}
## Decision
{}
## Consequences
{}
"},
file_name,
Utc::now().format("%Y-%m-%dT%H:%M:%S%.3fZ"),
file_name,
context,
decision,
consequences
);

let mut file = fs::File::create(&file_path).unwrap_or_else(|e| {
eprintln!("{}", format!("Failed to create file: {}", e).red());
std::process::exit(1);
});
file.write_all(content.as_bytes()).unwrap_or_else(|e| {
eprintln!("{}", format!("Failed to write to file: {}", e).red());
std::process::exit(1);
});

println!(
"ADR MDX file created at {}",
file_path.display().to_string().green()
);
}

fn get_user_input(prompt: &str) -> String {
match Input::<String>::new().with_prompt(prompt).interact_text() {
Ok(input) => input,
Err(e) => {
eprintln!("{}", format!("Failed to read {}: {}", prompt, e).red());
process::exit(1);
}
}
}

0 comments on commit 7df3688

Please sign in to comment.