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

INIT: Enable Extension to Extend Flag in Ignite Command Using Hook #118

Closed
Pantani opened this issue Jul 14, 2024 · 6 comments · Fixed by ignite/cli#4270
Closed

INIT: Enable Extension to Extend Flag in Ignite Command Using Hook #118

Pantani opened this issue Jul 14, 2024 · 6 comments · Fixed by ignite/cli#4270
Assignees

Comments

@Pantani
Copy link
Collaborator

Pantani commented Jul 14, 2024

No description provided.

@julienrbrt
Copy link
Member

I am not sure if this is very useful. What is the use case?

@salmad3 salmad3 changed the title Add the ability to the extension can extend flag from a ignite command using hook PROP: Enable Extension to Extend Flag in Ignite Command Using Hook Jul 18, 2024
@Pantani
Copy link
Collaborator Author

Pantani commented Jul 19, 2024

I am not sure if this is very useful. What is the use case?

If you want to parse the output of a flag from the command into the hooks, for instance, if you create a hook for the chain build command, you can get the --output flag passed to the command. Or, if you want to extend the chain build command, having a new flag, like --run-tests to run tests after the build.

@julienrbrt
Copy link
Member

Alright, but how will an app use that?

@Pantani
Copy link
Collaborator Author

Pantani commented Jul 22, 2024

For instance, if you want to add a flag to the chain build command to run tests after the build:

func (app) Manifest(context.Context) (*plugin.Manifest, error) {
	return &plugin.Manifest{
		Name: "hooks",
		Hooks: []*plugin.Hook{
			{
				Name:        "chain-build",
				PlaceHookOn: "ignite chain build",
				Flags: []*plugin.Flag{
					{
						Name:         "run-test",
						Usage:        "Run tests after build",
						DefaultValue: "false",
						Type:         plugin.FlagTypeString,
					},
				},
			},
		},
		Commands: cmd.GetCommands(),
	}, nil
}

func (app) ExecuteHookPost(_ context.Context, hook *plugin.ExecutedHook, _ plugin.ClientAPI) error {
	var (
		flags = hook.Hook.Flags
		runTests = flags.GetBool("run-test")
	)

	if runTests != "" {
		tests.Run()
	}
	return nil
}

And now you can use ignite chain build --run-test and run tests after build, or maybe you have a plugin to generate something like front-end code as a chain build hook. You can create a flag to pass the path or also a flag to enable the generation.

@julienrbrt
Copy link
Member

Like that, I get it better now. Is it, however, really something we want to allow?
I really like that hooks are just logic running before/after/always-after regardless of the flags.
This adds granularity, sure, but imho worsen a bit the UX.

Do we actually already need this feature for something?

@julienrbrt
Copy link
Member

Discussed on Slack. I get it and it makes sense to add the feature.

@github-project-automation github-project-automation bot moved this from To Discuss to Done in Ignite CLI Masterboard Jul 25, 2024
@salmad3 salmad3 changed the title PROP: Enable Extension to Extend Flag in Ignite Command Using Hook INIT: Enable Extension to Extend Flag in Ignite Command Using Hook Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants