diff --git a/README.md b/README.md index 82ab90f..1913946 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ SUBCOMMANDS: compute db docker - g + gen gcloud gh help Print this message or the help of the given subcommand(s) @@ -137,7 +137,7 @@ Now go to Create Model ```bash -$ zapp g model user +$ zapp gen model user ✅ Successfully created migration file: migration/src/m20220613_102512_create_user_table.rs ✅ Successfully added route to `migration/src/lib.rs` ✅ Successfully created entity file: entity/src/user.rs diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 2dee146..25476a0 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -47,7 +47,7 @@ pub enum Commands { Compute(Compute), Docker(Docker), Sql(Sql), - G(G), + Gen(Gen), Db(Db), New { app_name: String }, Gcloud(Gcloud), @@ -104,9 +104,9 @@ pub struct Sql { #[derive(Debug, Args)] #[clap(args_conflicts_with_subcommands = true)] -pub struct G { +pub struct Gen { #[clap(subcommand)] - pub command: Option, + pub command: Option, } #[derive(Debug, Args)] @@ -174,7 +174,7 @@ pub enum SqlCommands { } #[derive(Debug, Subcommand)] -pub enum GCommands { +pub enum GenCommands { Model { model: String, #[clap(parse(from_os_str), short, long)] diff --git a/src/docker/process.rs b/src/docker/process.rs index 4c13da4..a1c191c 100644 --- a/src/docker/process.rs +++ b/src/docker/process.rs @@ -2,7 +2,6 @@ use crate::style_print::*; use std::process::Command; use std::str; - pub fn process_psql_docker() { create_docker_network(); process_docker_psql("zapp-psql"); diff --git a/src/g/entity/creation.rs b/src/gen/entity/creation.rs similarity index 97% rename from src/g/entity/creation.rs rename to src/gen/entity/creation.rs index bff5abd..623397d 100644 --- a/src/g/entity/creation.rs +++ b/src/gen/entity/creation.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, to_upper_camel}; +use crate::gen::{emit_generated_code, to_upper_camel}; use crate::style_print::log_success; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/src/g/entity/mod.rs b/src/gen/entity/mod.rs similarity index 71% rename from src/g/entity/mod.rs rename to src/gen/entity/mod.rs index 4bcff3b..d78fb5d 100644 --- a/src/g/entity/mod.rs +++ b/src/gen/entity/mod.rs @@ -1,4 +1,4 @@ -use crate::g::entity::{creation::create_entity, registration::register_entity}; +use crate::gen::entity::{creation::create_entity, registration::register_entity}; use crate::style_print::log_error; use std::fs; use std::path::Path; @@ -6,7 +6,7 @@ use std::path::Path; mod creation; mod registration; -pub(in crate::g) fn process_entity(model: &str, gen_path: &Path) { +pub(in crate::gen) fn process_entity(model: &str, gen_path: &Path) { let entity_src_dir = gen_path.join("entity").join("src"); fs::create_dir_all(entity_src_dir.as_path()).unwrap_or_else(|why| { diff --git a/src/g/entity/registration.rs b/src/gen/entity/registration.rs similarity index 95% rename from src/g/entity/registration.rs rename to src/gen/entity/registration.rs index cccf54e..1acd5dd 100644 --- a/src/g/entity/registration.rs +++ b/src/gen/entity/registration.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, read_dir}; +use crate::gen::{emit_generated_code, read_dir}; use crate::style_print::log_success; use proc_macro2::TokenStream; diff --git a/src/g/graphql/mod.rs b/src/gen/graphql/mod.rs similarity index 100% rename from src/g/graphql/mod.rs rename to src/gen/graphql/mod.rs diff --git a/src/g/graphql/mutation/creation.rs b/src/gen/graphql/mutation/creation.rs similarity index 97% rename from src/g/graphql/mutation/creation.rs rename to src/gen/graphql/mutation/creation.rs index e5ac1aa..545c3c1 100644 --- a/src/g/graphql/mutation/creation.rs +++ b/src/gen/graphql/mutation/creation.rs @@ -1,5 +1,7 @@ -use crate::g::emit_generated_code; -use crate::{g::to_upper_camel, style_print::*}; +use crate::{ + gen::{emit_generated_code, to_upper_camel}, + style_print::*, +}; use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::path::Path; diff --git a/src/g/graphql/mutation/mod.rs b/src/gen/graphql/mutation/mod.rs similarity index 69% rename from src/g/graphql/mutation/mod.rs rename to src/gen/graphql/mutation/mod.rs index 592ce18..f6cd5b0 100644 --- a/src/g/graphql/mutation/mod.rs +++ b/src/gen/graphql/mutation/mod.rs @@ -1,4 +1,4 @@ -use crate::g::graphql::mutation::{creation::create_mutation, registration::register_mutation}; +use crate::gen::graphql::mutation::{creation::create_mutation, registration::register_mutation}; use crate::style_print::log_error; use std::fs; use std::path::Path; @@ -6,7 +6,7 @@ use std::path::Path; mod creation; mod registration; -pub(in crate::g) fn process_graphql_mutation(model: &str, gen_path: &Path) { +pub(in crate::gen) fn process_graphql_mutation(model: &str, gen_path: &Path) { let mutation_dir = gen_path.join("src").join("graphql").join("mutation"); fs::create_dir_all(mutation_dir.as_path()).unwrap_or_else(|why| { diff --git a/src/g/graphql/mutation/registration.rs b/src/gen/graphql/mutation/registration.rs similarity index 95% rename from src/g/graphql/mutation/registration.rs rename to src/gen/graphql/mutation/registration.rs index 27541ef..8363584 100644 --- a/src/g/graphql/mutation/registration.rs +++ b/src/gen/graphql/mutation/registration.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, read_dir, to_upper_camel}; +use crate::gen::{emit_generated_code, read_dir, to_upper_camel}; use crate::style_print::log_success; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/src/g/graphql/query/creation.rs b/src/gen/graphql/query/creation.rs similarity index 96% rename from src/g/graphql/query/creation.rs rename to src/gen/graphql/query/creation.rs index 02606e4..8dab24c 100644 --- a/src/g/graphql/query/creation.rs +++ b/src/gen/graphql/query/creation.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, to_upper_camel}; +use crate::gen::{emit_generated_code, to_upper_camel}; use crate::style_print::log_success; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/src/g/graphql/query/mod.rs b/src/gen/graphql/query/mod.rs similarity index 69% rename from src/g/graphql/query/mod.rs rename to src/gen/graphql/query/mod.rs index 1df46f6..d4e6a80 100644 --- a/src/g/graphql/query/mod.rs +++ b/src/gen/graphql/query/mod.rs @@ -1,4 +1,4 @@ -use crate::g::graphql::query::{creation::create_query, registration::register_query}; +use crate::gen::graphql::query::{creation::create_query, registration::register_query}; use crate::style_print::log_error; use std::fs; use std::path::Path; @@ -6,7 +6,7 @@ use std::path::Path; mod creation; mod registration; -pub(in crate::g) fn process_graphql_query(model: &str, gen_path: &Path) { +pub(in crate::gen) fn process_graphql_query(model: &str, gen_path: &Path) { let query_dir = gen_path.join("src").join("graphql").join("query"); fs::create_dir_all(query_dir.as_path()).unwrap_or_else(|why| { diff --git a/src/g/graphql/query/registration.rs b/src/gen/graphql/query/registration.rs similarity index 95% rename from src/g/graphql/query/registration.rs rename to src/gen/graphql/query/registration.rs index 8d92340..1059a2e 100644 --- a/src/g/graphql/query/registration.rs +++ b/src/gen/graphql/query/registration.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, read_dir, to_upper_camel}; +use crate::gen::{emit_generated_code, read_dir, to_upper_camel}; use crate::style_print::log_success; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/src/g/migration/creation.rs b/src/gen/migration/creation.rs similarity index 98% rename from src/g/migration/creation.rs rename to src/gen/migration/creation.rs index c697ed1..3b3904e 100644 --- a/src/g/migration/creation.rs +++ b/src/gen/migration/creation.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, read_dir}; +use crate::gen::{emit_generated_code, read_dir}; use crate::style_print::log_success; use chrono::NaiveDateTime; use proc_macro2::TokenStream; diff --git a/src/g/migration/mod.rs b/src/gen/migration/mod.rs similarity index 70% rename from src/g/migration/mod.rs rename to src/gen/migration/mod.rs index 5e4a46d..3c09133 100644 --- a/src/g/migration/mod.rs +++ b/src/gen/migration/mod.rs @@ -1,4 +1,4 @@ -use crate::g::migration::{creation::create_migration, registration::register_migration}; +use crate::gen::migration::{creation::create_migration, registration::register_migration}; use crate::style_print::log_error; use chrono::NaiveDateTime; use std::fs; @@ -7,7 +7,7 @@ use std::path::Path; mod creation; mod registration; -pub(in crate::g) fn process_migration(model: &str, dt: NaiveDateTime, gen_path: &Path) { +pub(in crate::gen) fn process_migration(model: &str, dt: NaiveDateTime, gen_path: &Path) { let migration_src_dir = gen_path.join("migration").join("src"); fs::create_dir_all(migration_src_dir.as_path()).unwrap_or_else(|why| { diff --git a/src/g/migration/registration.rs b/src/gen/migration/registration.rs similarity index 96% rename from src/g/migration/registration.rs rename to src/gen/migration/registration.rs index 6062f8f..5a1bdc5 100644 --- a/src/g/migration/registration.rs +++ b/src/gen/migration/registration.rs @@ -1,4 +1,4 @@ -use crate::g::{emit_generated_code, read_dir}; +use crate::gen::{emit_generated_code, read_dir}; use crate::style_print::log_success; use proc_macro2::TokenStream; use quote::{format_ident, quote}; diff --git a/src/g/mod.rs b/src/gen/mod.rs similarity index 83% rename from src/g/mod.rs rename to src/gen/mod.rs index 70e337d..2ec4325 100644 --- a/src/g/mod.rs +++ b/src/gen/mod.rs @@ -1,7 +1,7 @@ -use crate::g::entity::process_entity; -use crate::g::graphql::mutation::process_graphql_mutation; -use crate::g::graphql::query::process_graphql_query; -use crate::g::migration::process_migration; +use crate::gen::entity::process_entity; +use crate::gen::graphql::mutation::process_graphql_mutation; +use crate::gen::graphql::query::process_graphql_query; +use crate::gen::migration::process_migration; use chrono::NaiveDateTime; use convert_case::{Case, Casing}; use proc_macro2::TokenStream; @@ -49,7 +49,7 @@ pub(self) fn emit_generated_code( file_path } -pub fn process_g(model: &str, dt: NaiveDateTime, gen_path: &Path) { +pub fn handle_gen(model: &str, dt: NaiveDateTime, gen_path: &Path) { process_entity(model, gen_path); process_migration(model, dt, gen_path); process_graphql_mutation(model, gen_path); diff --git a/src/lib.rs b/src/lib.rs index 39cfb5d..3b65dae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,8 @@ pub mod compute; pub mod constants; pub mod db; pub mod docker; -pub mod g; pub mod gcloud; +pub mod gen; pub mod gh; pub mod iam; pub mod init; diff --git a/src/main.rs b/src/main.rs index 428c0db..3b5b5dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,13 @@ use std::env::current_dir; use std::fs::File; use std::io::BufReader; use zapp::cli::{ - Cli, Commands, ComputeCommands, DbCommands, DockerCommands, GCommands, GcloudCommands, - GcpConfig, GhCommands, IamCommands, InitCommands, RunCommands, SqlCommands, + Cli, Commands, ComputeCommands, DbCommands, DockerCommands, GcloudCommands, GcpConfig, + GenCommands, GhCommands, IamCommands, InitCommands, RunCommands, SqlCommands, }; use zapp::compute::*; use zapp::db::*; use zapp::docker::*; -use zapp::g::*; +use zapp::gen::*; use zapp::gh::*; use zapp::iam::*; use zapp::init::*; @@ -183,14 +183,14 @@ fn main() { } } } - Commands::G(g) => { - let g_cmd = g.command.unwrap_or(GCommands::Help); - match g_cmd { - GCommands::Model { model, path } => { + Commands::Gen(gen) => { + let gen_cmd = gen.command.unwrap_or(GenCommands::Help); + match gen_cmd { + GenCommands::Model { model, path } => { let gen_path_buf = path.unwrap_or_else(|| current_dir().unwrap()); let gen_path = gen_path_buf.as_path(); let date = Local::now(); - process_g(&model, date.naive_local(), gen_path); + handle_gen(&model, date.naive_local(), gen_path); } _ => { let log = "To see example;\n\n $zapp run --help"; @@ -223,8 +223,6 @@ fn main() { } } - - pub fn get_gcp() -> GcpConfig { let file_name = "gcp_config.json"; let f = File::open(file_name).unwrap(); diff --git a/tests/g/integration_test.rs b/tests/gen/integration_test.rs similarity index 77% rename from tests/g/integration_test.rs rename to tests/gen/integration_test.rs index 2af0f58..a49f001 100644 --- a/tests/g/integration_test.rs +++ b/tests/gen/integration_test.rs @@ -1,17 +1,17 @@ -use crate::g::assert_file_equality; +use crate::gen::assert_file_equality; use chrono::NaiveDate; use std::path::Path; use tempdir::TempDir; -use zapp::g::process_g; +use zapp::gen::handle_gen; #[test] fn gen_one_user_model() { - let tmp_dir = TempDir::new("zapp-g-integration-tests").unwrap(); - let resource_dir = Path::new("tests/g/resources/gen_one_user_model"); + let tmp_dir = TempDir::new("zapp-gen-integration-tests").unwrap(); + let resource_dir = Path::new("tests/gen/resources/gen_one_user_model"); let test_dt = NaiveDate::from_ymd(2022, 7, 16).and_hms(23, 39, 33); - process_g("user", test_dt, tmp_dir.path()); + handle_gen("user", test_dt, tmp_dir.path()); assert_file_equality(resource_dir, tmp_dir.path(), "entity/src/user.rs"); assert_file_equality(resource_dir, tmp_dir.path(), "entity/src/lib.rs"); diff --git a/tests/g/mod.rs b/tests/gen/mod.rs similarity index 100% rename from tests/g/mod.rs rename to tests/gen/mod.rs diff --git a/tests/g/resources/gen_one_user_model/entity/src/lib.rs b/tests/gen/resources/gen_one_user_model/entity/src/lib.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/entity/src/lib.rs rename to tests/gen/resources/gen_one_user_model/entity/src/lib.rs diff --git a/tests/g/resources/gen_one_user_model/entity/src/user.rs b/tests/gen/resources/gen_one_user_model/entity/src/user.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/entity/src/user.rs rename to tests/gen/resources/gen_one_user_model/entity/src/user.rs diff --git a/tests/g/resources/gen_one_user_model/migration/src/lib.rs b/tests/gen/resources/gen_one_user_model/migration/src/lib.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/migration/src/lib.rs rename to tests/gen/resources/gen_one_user_model/migration/src/lib.rs diff --git a/tests/g/resources/gen_one_user_model/migration/src/m20220716_233933_create_user_table.rs b/tests/gen/resources/gen_one_user_model/migration/src/m20220716_233933_create_user_table.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/migration/src/m20220716_233933_create_user_table.rs rename to tests/gen/resources/gen_one_user_model/migration/src/m20220716_233933_create_user_table.rs diff --git a/tests/g/resources/gen_one_user_model/src/graphql/mutation/mod.rs b/tests/gen/resources/gen_one_user_model/src/graphql/mutation/mod.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/src/graphql/mutation/mod.rs rename to tests/gen/resources/gen_one_user_model/src/graphql/mutation/mod.rs diff --git a/tests/g/resources/gen_one_user_model/src/graphql/mutation/user.rs b/tests/gen/resources/gen_one_user_model/src/graphql/mutation/user.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/src/graphql/mutation/user.rs rename to tests/gen/resources/gen_one_user_model/src/graphql/mutation/user.rs diff --git a/tests/g/resources/gen_one_user_model/src/graphql/query/mod.rs b/tests/gen/resources/gen_one_user_model/src/graphql/query/mod.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/src/graphql/query/mod.rs rename to tests/gen/resources/gen_one_user_model/src/graphql/query/mod.rs diff --git a/tests/g/resources/gen_one_user_model/src/graphql/query/user.rs b/tests/gen/resources/gen_one_user_model/src/graphql/query/user.rs similarity index 100% rename from tests/g/resources/gen_one_user_model/src/graphql/query/user.rs rename to tests/gen/resources/gen_one_user_model/src/graphql/query/user.rs diff --git a/tests/mod.rs b/tests/mod.rs index b7ae56f..3778c39 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1 +1 @@ -mod g; +mod gen;