feat: add models path arg
This commit is contained in:
parent
e4f6c0f12d
commit
21c1f2e069
2 changed files with 13 additions and 5 deletions
|
|
@ -38,6 +38,9 @@ struct GenerateMigration {
|
|||
/// Generate Rust SQLx repositories code
|
||||
#[argh(subcommand, name = "gen-repositories")]
|
||||
struct GenerateRepositories {
|
||||
/// path of the directory that contains repositories
|
||||
#[argh(option, short = 'o')]
|
||||
output: Option<String>
|
||||
}
|
||||
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
|
|
@ -57,6 +60,10 @@ struct GeneratorArgs {
|
|||
/// path where to find Cargo.toml
|
||||
#[argh(option)]
|
||||
project_root: Option<String>,
|
||||
|
||||
/// path of the directory containing models
|
||||
#[argh(option, short = 'm')]
|
||||
models_path: Option<String>,
|
||||
|
||||
#[argh(subcommand)]
|
||||
nested: GeneratorArgsSubCommands
|
||||
|
|
@ -97,6 +104,9 @@ pub fn main() -> Result<()> {
|
|||
// search for a models modules
|
||||
let models_mod_location = "src/models.rs";
|
||||
let mut models_mod_path = project_root_path.join(models_mod_location);
|
||||
if let Some(models_path) = args.models_path {
|
||||
models_mod_path = project_root_path.join(models_path);
|
||||
}
|
||||
if !models_mod_path.exists() {
|
||||
let models_mod_location = "src/models/mod.rs";
|
||||
models_mod_path = project_root_path.join(models_mod_location);
|
||||
|
|
@ -115,7 +125,7 @@ pub fn main() -> Result<()> {
|
|||
GeneratorArgsSubCommands::GenerateRepositories(opts) => {
|
||||
eprintln!("Generating repositories…");
|
||||
// search for a repository module
|
||||
let repositories_mod_location = "src/repositories";
|
||||
let repositories_mod_location = opts.output.unwrap_or("src/repositories".to_string());
|
||||
let repositories_mod_path = project_root_path.join(repositories_mod_location);
|
||||
if !repositories_mod_path.exists() {
|
||||
return Err(anyhow!("Could not resolve repositories modules."));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue