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

Execute runFlagActions before c.Before #1844

Closed
axelrindle opened this issue Dec 20, 2023 · 3 comments
Closed

Execute runFlagActions before c.Before #1844

axelrindle opened this issue Dec 20, 2023 · 3 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this

Comments

@axelrindle
Copy link

I have a flag named config which specifies the path to an alternative config file to use.
I do the config loading in the c.Before hook.

However I noticed that the flag actions are run after the c.Before hook.

cli/command.go

Lines 216 to 227 in d391482

if c.Before != nil && !cCtx.shellComplete {
beforeErr := c.Before(cCtx)
if beforeErr != nil {
cCtx.App.handleExitCoder(cCtx, beforeErr)
err = beforeErr
return err
}
}
if err = runFlagActions(cCtx, c.Flags); err != nil {
return err
}

How can I achieve the flag action being run before the c.Before hook?

@axelrindle axelrindle added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Dec 20, 2023
@dearchap
Copy link
Contributor

@axelrindle As of now it is not possible. There has been some discussion on lifecycle hooks for v3. See #1273 . If you have suggestions of how you'd like to improve this behavior it would be great.

@axelrindle
Copy link
Author

The concept of lifecycle hooks sounds great to me. I'd like to propose the following:

  • beforeFlags (runs before flags are parsed)
  • afterFlags (runs after flags are parsed, but before commands are run)
  • beforeCommand (runs before command actions are run; maybe merge with the previous?)
  • afterCommand (runs after a command action has been run)

@dearchap
Copy link
Contributor

@axelrindle I'm going to move this conversation to #1273 and close this issue

@dearchap dearchap closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants