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

Added CLI Flags for Package name customization for Model, Table, View and Enum #424

Merged
merged 8 commits into from
Nov 26, 2024

Conversation

jamius19
Copy link
Contributor

Goal

Jet doesn't currently support custom package names for the generated files for Models, Tables, Views, and Enums. It always uses the fixed model, table, view, and enum names for these packages. This PR will allow users to pass OPTIONAL CLI arguments to Jet for custom package names.

Features Added

Users can customize the package names through these flags,

  1. -model-pkg for the model package name
  2. -table-pkg for the table package name
  3. -view-pkg for the view package name
  4. -enum-pkg for the enum package name

If any or all of these flags are absent, the default package names (e.g., model for Model) will be used making this a NON Breaking change.

I've also added a corresponding integration test for these optional CLI arguments in Postgres. This should be sufficient as all databases use the main.go:genTemplate() function that was changed to accommodate this feature.

For additional context, please see Issue #413

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.25%. Comparing base (3ca1776) to head (71ae4ed).
Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #424   +/-   ##
=======================================
  Coverage   91.25%   91.25%           
=======================================
  Files         134      134           
  Lines        7755     7755           
=======================================
  Hits         7077     7077           
  Misses        509      509           
  Partials      169      169           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cmd/jet/main.go Outdated Show resolved Hide resolved
cmd/jet/main.go Outdated Show resolved Hide resolved
@jamius19
Copy link
Contributor Author

Rebased my branch with master

@jamius19
Copy link
Contributor Author

@go-jet Please don't merge this PR yet, relative directory names starting with ./ or .\ and nested directory names don't work on Windows. Most probably related to Issue #426

I'll investigate and update here.

@jamius19
Copy link
Contributor Author

Issue #426 is related to how PowerShell handles arguments.
TL;DR Arguments should be passed as quoted strings in PowerShell.

However, if a quoted nested directory is passed as the value of -model-pkg, it breaks on Windows.
I'm checking up on it now.

@jamius19
Copy link
Contributor Author

Fixed path compatibility issues on Windows.

@jamius19
Copy link
Contributor Author

Since we're passing a path for the model package, wouldn't it be better if the flag was model-pkg-dir?

Same goes for the other three as well.

@go-jet
Copy link
Owner

go-jet commented Nov 25, 2024

Since we're passing a path for the model package, wouldn't it be better if the flag was model-pkg-dir?

Same goes for the other three as well.

Shouldn't be path then (model-pkg-path)? Since directory is technically just a container.
Maybe we can also drop pkg(it kind of implies), and add rel. - rel-model-path, rel-table-path, rel-enum-path, rel-view-path

@jamius19
Copy link
Contributor Author

I agree with both points that it should be path and that the pkg is redundant.
I also think the addition of rel in these new flags will help indicate that they are relative to something (the path flag in this case).

I'm changing the flags like this -rel-model-path then.

cmd/jet/main.go Outdated Show resolved Hide resolved
cmd/jet/main.go Outdated
@@ -170,6 +178,7 @@ func usage() {
"source", "dsn", "host", "port", "user", "password", "dbname", "schema", "params", "sslmode",
"path",
"ignore-tables", "ignore-views", "ignore-enums",
"model-pkg", "table-pkg", "view-pkg", "enum-pkg",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to update this names as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my bad.
Pushed the changes already.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. LGTM. 👍

@go-jet go-jet merged commit 072b58c into go-jet:master Nov 26, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants