-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mdk): overridable templates (#842)
<!-- Pull requests are squashed and merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog. --> <!-- 1. Explain WHAT the change is about --> Solve [MET-630](https://linear.app/metatypedev/issue/MET-630/gen-add-parameter-to-replace-static-sections) - [x] Make templates in the _static_ sections overridable - [x] `mdk_rust` - [x] `mdk_python` - [x] `mdk_typescript` - [x] Add a CLI tool to generate extract the default template <!-- 3. Explain HOW users should update their code --> #### Migration notes No changes needed. --- - [x] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change
- Loading branch information
Showing
32 changed files
with
1,644 additions
and
683 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
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,52 @@ | ||
use async_trait::async_trait; | ||
use clap::{Parser, ValueEnum}; | ||
|
||
use crate::interlude::*; | ||
|
||
use super::{Action, ConfigArgs}; | ||
|
||
#[derive(ValueEnum, Debug, Clone)] | ||
enum Template { | ||
Rust, | ||
Python, | ||
Typescript, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct CreateMdkTemplate { | ||
/// Target directory | ||
#[clap(long)] | ||
dir: String, | ||
|
||
/// Template to create | ||
#[clap(long)] | ||
template: Template, | ||
} | ||
|
||
#[async_trait] | ||
impl Action for CreateMdkTemplate { | ||
#[tracing::instrument] | ||
async fn run(&self, args: ConfigArgs) -> Result<()> { | ||
let dir = args.dir()?.join(&self.dir); | ||
tracing::info!("creating mdk template at {:?}", dir); | ||
|
||
tokio::fs::create_dir_all(&dir) | ||
.await | ||
.context("failed to create target directory")?; | ||
|
||
let template = match self.template { | ||
Template::Rust => metagen::MDK_RUST_DEFAULT_TEMPLATE, | ||
Template::Python => metagen::MDK_PYTHON_DEFAULT_TEMPLATE, | ||
Template::Typescript => metagen::MDK_TYPESCRIPT_DEFAULT_TEMPLATE, | ||
}; | ||
|
||
for (file_name, content) in template.iter() { | ||
let path = dir.join(file_name); | ||
tokio::fs::write(&path, content) | ||
.await | ||
.context("failed to write the template into the file")?; | ||
} | ||
|
||
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
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
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
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
Oops, something went wrong.