cli icon indicating copy to clipboard operation
cli copied to clipboard

Implement generic component generator

Open krzykamil opened this issue 2 years ago • 1 comments

Context:

Hi. I noticed this task in Hanami github projects: https://github.com/orgs/hanami/projects/2?pane=issue&itemId=37953496 Thought I give it a go, to get acquainted with dry-rb and hanami source code more, and maybe be useful to maintainers as a side effect. I know the task was marked as "maybe" but I often wrote generators for rails and wanted to see how much different would it be here.

Solution:

The generator is really simple, as components are general objects with no one interface or anything. It is basically a shortcut to creating a file with the right name in the right scope and slice or no slice. That is what I understood that the idea was behind this task. I also accounted for CLI receiving the name in Pascal Case like Opeations::CreateUser. This is a personal preference, since this is how I usually generate new ruby classes through rubymine, but I think it might be a useful option for some.

TBD:

For my code, the collection of constants with different characters used in lib/hanami/cli/generators/app/view_context.rb was also useful. I noticed the TODO that it should be moved. I would like to do thath, but I am unsure what would be the desired location. Something like lib/hanami/cli/constants.rb seems to generic. I was thinking more along the lines of lib/hanami/cli/formatting since all those constants are used to format the input or output but it also does not seem right (this naming seems like a stretch, or might be misleading, since it is not functional, it would just be a module with constants or something).

Anyway, eager to see any form of feedback. Would you like the generator to do something more, or just general code feedback.

I was also unsure about how to document the code with the version tags.

Some screenshots of usage of my local gem version:

cli_component_slice cli_component

krzykamil avatar Nov 24 '23 13:11 krzykamil

https://github.com/orgs/hanami/projects/2?pane=issue&itemId=37953496

krzykamil avatar Dec 01 '23 09:12 krzykamil

https://github.com/hanami/cli/issues/145

krzykamil avatar May 20 '24 09:05 krzykamil

@timriley I removed private from methods that are already in private scope and changed the version to 2.2.0 on stuff that was added.

krzykamil avatar Jun 05 '24 15:06 krzykamil

Thanks @krzykamil! 😍

timriley avatar Jun 06 '24 10:06 timriley