-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated commit and version deps, rust cli tool for adrs, radar enhancments, design system tooling
- Loading branch information
1 parent
148d71c
commit 7df3688
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
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,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/ |
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,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" |
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,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); | ||
} | ||
} | ||
} |