quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Add codestart data option in CLI and Maven plugin

Open ia3andy opened this issue 3 years ago • 21 comments

Description

It would be nice extension codestart to have user customizable data. This is already possible in codestarts but not yet connected in the tooling.

It would behave like this:

quarkus create app -x=my-ext -d=my-ext-codestart.foo.bar=hello,my-ext-codestart.foo.hello=andy

The my-ext-codestart prefix is required by the codestart system to know the data is targeting this particular codestart data (and avoid conflicts)

The default value is in the codestart.yml:

name: my-ext-codestart
language:
  base:
    data:
      foo:
        bar: baz
        hello: world

FYI: I created this issue because @gsmet has a need for this.

ia3andy avatar Oct 04 '22 08:10 ia3andy

/cc @ebullient, @maxandersen, @quarkusio/devtools

quarkus-bot[bot] avatar Oct 04 '22 08:10 quarkus-bot[bot]

Let me know if i pick it up and start working on this.

arpitbhardwaj avatar Oct 05 '22 15:10 arpitbhardwaj

Does that mean you have to know each individual codestart's requirements to make this useful? There is already a way to pass in initial configuration with existing options. This seems like something that is useful if you write codestarts frequently, but is difficult to document (where the goal of the CLI, e.g., is to ensure it is generally useful without having to go look at docs).

ebullient avatar Oct 07 '22 12:10 ebullient

The idea is to be able to pass some additional data for a specific extension codestart. AFAIK there's no way to do that right now. And in the case of the GitHub Action extension, I'd like to have the ability to pass the GitHub repository where the action will be hosted.

gsmet avatar Oct 07 '22 17:10 gsmet

yes.. can't that be passed in using the existing config mechanism? Something like --app-config=whatever.github.repo=gsmet/awesomesauce?

ebullient avatar Oct 07 '22 17:10 ebullient

It's not a config property I want. It's something that I can actually use in the templates when generating the project.

gsmet avatar Oct 10 '22 14:10 gsmet

@arpitbhardwaj you can have a look if you can figure out where to do this.

gsmet avatar Oct 10 '22 14:10 gsmet

This might give you a good idea about where to poke: https://github.com/quarkusio/quarkus/pull/28325

gsmet avatar Oct 11 '22 12:10 gsmet

@ia3andy would it not "just work" if you use -D to set properties today?

maxandersen avatar Oct 11 '22 13:10 maxandersen

@gsmet I thought app config was available to codestarts ?

maxandersen avatar Oct 11 '22 13:10 maxandersen

I don't want to push these things to the app config.

gsmet avatar Oct 11 '22 13:10 gsmet

but -D are just system properties - shouldn't be ending up in you generated app config.

maxandersen avatar Oct 11 '22 13:10 maxandersen

i.e.

quarkus create app -x=my-ext -Dmy-ext-codestart.foo.bar=hello -Dmy-ext-codestart.foo.hello=andy

should be possible to make work.

maxandersen avatar Oct 11 '22 13:10 maxandersen

So that could work but is there a way to access system properties from the Qute template directly? I might be missing something obvious.

gsmet avatar Oct 11 '22 14:10 gsmet

https://github.com/quarkusio/quarkus/blob/f7509ba1e11f7522730fba3ef780b67b1761ef4a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java#L213 -- we do set the system properties here..

We could also set them as template values by calling this: https://github.com/quarkusio/quarkus/blob/f7509ba1e11f7522730fba3ef780b67b1761ef4a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java#L188

ebullient avatar Oct 11 '22 15:10 ebullient

But why would we do that instead of something cleaner with the data thing?

gsmet avatar Oct 11 '22 15:10 gsmet

We already use -D to pass an arbitrary keys to maven/gradle/jbang so not sure how much value it brings to add yet-another open-ended key/value command option?

maxandersen avatar Oct 11 '22 19:10 maxandersen

Ok, my concern using plain system properties is that we would have to find a way to filter them before passing them as data to codestarts if we don't want to have weird behaviors.

In the top level where we pass the data, we don't know how it will be consumed by codestarts.

ia3andy avatar Oct 14 '22 07:10 ia3andy

IMO we should reproduce the same syntax as for config on another named option (data or whatever), parse it using the same code as the data and passing the map to codestart data.

We need a new key and setter in the CreateProject for this (like we do for config): https://github.com/quarkusio/quarkus/blob/main/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProject.java#L43

Unlike the config this data needs to be directly passed to the builder here: https://github.com/quarkusio/quarkus/blob/main/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/CreateProjectCommandHandler.java#L150

https://github.com/quarkusio/quarkus/blob/main/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/CodestartProjectInputBuilder.java#L46

ia3andy avatar Oct 14 '22 07:10 ia3andy

@arpitbhardwaj would you give it a try?

ia3andy avatar Oct 14 '22 07:10 ia3andy

Yeah I will it a try. Currently setting up the environment.

arpitbhardwaj avatar Oct 14 '22 07:10 arpitbhardwaj

@arpitbhardwaj any update on this?

ia3andy avatar Dec 02 '22 09:12 ia3andy

I'd really like to have it for 2.15 so I think I will drive this puppy home.

gsmet avatar Dec 02 '22 09:12 gsmet

I created a PR here: https://github.com/quarkusio/quarkus/pull/29644 .

gsmet avatar Dec 02 '22 16:12 gsmet

Just to be clear - my suggestion was not to use global system properties. Simply that -D is defining data keys for the command.

What is the difference now between --data and -D ?

maxandersen avatar Dec 06 '22 02:12 maxandersen

so I now got to import the code and realize that -D already exist in more generic form. somehow I had in my head for codestarts we had separate dedicated command.

so all good - my only gripe is that it relies on command separated "blob" which limits what you can pass in but we can fix that if usecase arises by adding support for i.e. -QDkey=value or similar.

maxandersen avatar Dec 06 '22 05:12 maxandersen