Skip to content

chore: migrate urfave cli to v3#430

Open
Peto-RH wants to merge 2 commits into
mainfrom
pschrimp/migrate-unfave-cli-from-v2-to-v3
Open

chore: migrate urfave cli to v3#430
Peto-RH wants to merge 2 commits into
mainfrom
pschrimp/migrate-unfave-cli-from-v2-to-v3

Conversation

@Peto-RH
Copy link
Copy Markdown
Contributor

@Peto-RH Peto-RH commented May 7, 2026

Update rhc to use urfave/cli v3 while preserving existing command behavior.

@Peto-RH Peto-RH force-pushed the pschrimp/migrate-unfave-cli-from-v2-to-v3 branch 4 times, most recently from b4205b6 to 7cbdad4 Compare May 14, 2026 12:07
@Peto-RH
Copy link
Copy Markdown
Contributor Author

Peto-RH commented May 14, 2026

Note for reviewer: I removed yaml license from go-vendor-tools.toml as cli/v3 no longer needs that yaml dependency

@Peto-RH Peto-RH force-pushed the pschrimp/migrate-unfave-cli-from-v2-to-v3 branch from 7cbdad4 to a2c2930 Compare May 14, 2026 12:57
@Peto-RH Peto-RH marked this pull request as ready for review May 14, 2026 13:38
@Peto-RH Peto-RH requested a review from pkoprda May 14, 2026 13:38
Copy link
Copy Markdown
Contributor

@mjcr99 mjcr99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ @Peto-RH, I leave you a couple of comments.
I would also consider referring to the Card ID in the second commit.

Comment thread cmd/rhc/main.go Outdated
Comment thread cmd/rhc/main.go
if cmd.IsSet(cliLogLevel) {
logLevelSrc = "command line"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before these changes, we were verifying the config file in the beforeaction section. Should we consider it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. How do we keep validating the config file before every command action runs? (this is the one you are probably asking about)
  2. How do we propagate errors and return an error code upon parsing failure?

There are multiple approaches:

  1. Do it the v3 idiomatic 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.
  1. Set the URFAVE_CLI_TRACING=on env 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.
  2. 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

@Peto-RH Peto-RH force-pushed the pschrimp/migrate-unfave-cli-from-v2-to-v3 branch 2 times, most recently from c94acf4 to 3f273a3 Compare May 21, 2026 08:54
Peto-RH added 2 commits May 21, 2026 10:54
* Card ID: CCT-2122

Update rhc to use urfave/cli v3 while preserving existing command
behavior.
* Card ID: CCT-2122

There is no need to use goxtx when we don't have to differentiate
between cli.Context and context.Context anymore. cli.Context does not
exist in cli/v3.
@Peto-RH Peto-RH force-pushed the pschrimp/migrate-unfave-cli-from-v2-to-v3 branch from 3f273a3 to ebe944c Compare May 21, 2026 08:54
Copy link
Copy Markdown
Contributor

@pkoprda pkoprda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants