chore: migrate urfave cli to v3#430
Conversation
b4205b6 to
7cbdad4
Compare
|
Note for reviewer: I removed yaml license from |
7cbdad4 to
a2c2930
Compare
| if cmd.IsSet(cliLogLevel) { | ||
| logLevelSrc = "command line" | ||
| } | ||
|
|
There was a problem hiding this comment.
Before these changes, we were verifying the config file in the beforeaction section. Should we consider it?
There was a problem hiding this comment.
Hi, good question. I was also brainstorming about this.
The 2 functions NewTomlSourceFromFile and ApplyInputSourceValues do not exist anymore in v3, and v3 unfortunately does not have a 1-to-1 solution for this. There are basically 2 problems:
- How do we keep validating the config file before every command action runs? (this is the one you are probably asking about)
- How do we propagate errors and return an error code upon parsing failure?
There are multiple approaches:
- Do it the
v3idiomatic way. This is the approach I currently proposed with the new commit.
- That means - do not validate the config file in beforeAction (validate only in
main()) - Do not report or catch parsing errors.
- Set the
URFAVE_CLI_TRACING=onenv variable (for example in the .spec file). With this variable, the logs will show that the parsing failed, but this will not affect the program. - Add some custom functionality to validate the toml. I am doubtful about this one because it would require some 3rd party lib to be imported. This would probably look something like this.
import "github.com/pelletier/go-toml"
func beforeAction(ctx context.Context, cmd *cli.Command) (context.Context, error) {
// some code ...
configPath := cmd.String("config")
if configPath != "" {
if _, err := os.Stat(configPath); err == nil {
// File exists, validate it's parseable TOML
if _, err := toml.LoadFile(configPath); err != nil {
return ctx, fmt.Errorf("invalid config file %s: %w", configPath, err)
}
}
// some more code ...
}
What do you think should be our approach to this? Do you have any other ideas?
FYI, the only toml-connected function in v3 is the TOML function that we are using in the new version, for example here altsrctoml.TOML(cliCertFile, configSource).
Here is the documentation for toml in v3
c94acf4 to
3f273a3
Compare
3f273a3 to
ebe944c
Compare
pkoprda
left a comment
There was a problem hiding this comment.
Please resolve conflicts
Update rhc to use urfave/cli v3 while preserving existing command behavior.