-
Notifications
You must be signed in to change notification settings - Fork 13
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
refactor: localize crud templates #172
Conversation
pkg/cmd/crud/crud.go
Outdated
@@ -109,6 +111,11 @@ func generateCrudFiles() error { | |||
// generateFileFromTemplate uses the passed contents and data object of a | |||
// template to generate a new file using the specified file name and output path | |||
func generateFileFromTemplate(name, path, tmplContent string, tmplData interface{}) error { | |||
// Sets appropriate target path for the locale file | |||
if name == "crud.en.yaml" { | |||
path = "./cmd/abc/locales/en" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this PR to be not merged right now, since the target path for the generated locale file has been hardcoded for now.
Once the charmil init
command has been completely set up, the following change can be made to make the path dynamic:
path = "./cmd/abc/locales/en" | |
path = "./cmd/[NAME_OF_CLI]/locales/en" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
charmil init is working, just a small issue with .git, not working for already initialized git folders.
I have used a templateContext struct in which I have asked github owner, repo, cliname. So I think we can save cliname somewhere to take reference.
you can walk the directory, cmd/CLI_NAME. So you can get the cliname from here right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
charmil init is working, just a small issue with .git, not working for already initialized git folders.
Yes, that's not the issue.
I was hoping we could save the CLI metadata from charmil init
somewhere.
I have used a templateContext struct in which I have asked github owner, repo, cliname. So I think we can save cliname somewhere to take reference.
This is exactly what I was talking about. I'll have a look at the templateContext
.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel the PR will be only ready to merge after the change highlighted above is made and for that we will need to integrate this with the charmil init
command
i am not really sure, if the commands can be integrated
|
Yes, but that can only be done if the CLI is initialized using (Ref: #67 (comment))
Yeah, this is what I prefer too (as mentioned here: #172 (comment)). But I think we will have to finalize what we want to do with this discussion, before proceeding with this PR. |
I can make a file with these fields it will be easy, but we must make sure if that is not unnecessary. We should first think of any way of doing without doing above. Like one way is walking through dir. Other may be leave some signatures of charmil init in files, that this code is generated from charmil init command. And charmil crud should work for the users who haven't used charmil init command. We don't want to enforce this on them ig. |
Exactly, I believe if we plan to use some core features like config later, allowing developers to use only the CLI generated using
Also, the solutions that you have proposed above might not work if we allow the developers to use their own CLI, since the project structure etc., can be different. So that gives us another reason to restrict developers to using |
pinging @wtrocki
|
Without taking any sides here I see two approqches drafted.
My take is to just dump some files into two folders with crud command and let users to connect them with cli aka take 2, but I might be wrong. Core will be automatically imported when running I could be completely wrong here but my first impression is that generator should be dam simple and small. EDIT:
I must clearly miss some context because this restriction doesn't occur to me as needed until we mentioned it. |
@namit-chandwani can you take look on this and push all fixes so we could integrate it. I would love to test CRUD features as as soon as possible and this PR is blocking me right now |
On it |
@aerogear/charmil This is now ready for review :) |
Rebase needed. @ankithans can you review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor changes -
creates a crud folder if this err occurs, means empty folder
lstat ./cmd: no such file or directory
then i try it gives
mkdir ./crud: file exists
I think default path for crud files can be pkg/cmd/ and if this path doesn't exist then root dir
Rest it works great 👍
New release after merge please |
@ankithans Fixed these errors. Please try running now :) |
yeah it works.. great |
current folder is best |
Closes #175
Description
Add a CRUD locale file template for generation (along with the CRUD command files).
Type of change
Checklist