Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#21] rename g to gen command #25

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ SUBCOMMANDS:
compute
db
docker
g
gen
gcloud
gh
help Print this message or the help of the given subcommand(s)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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<GCommands>,
pub command: Option<GenCommands>,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion src/docker/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/g/entity/creation.rs → src/gen/entity/creation.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/g/entity/mod.rs → src/gen/entity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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;

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| {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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;

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| {
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/g/graphql/query/mod.rs → src/gen/graphql/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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;

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| {
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/g/migration/mod.rs → src/gen/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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| {
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
10 changes: 5 additions & 5 deletions src/g/mod.rs → src/gen/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -223,8 +223,6 @@ fn main() {
}
}



pub fn get_gcp() -> GcpConfig {
let file_name = "gcp_config.json";
let f = File::open(file_name).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions tests/g/integration_test.rs → tests/gen/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod g;
mod gen;