-
Notifications
You must be signed in to change notification settings - Fork 62
Migrate urfave/cli to v3 #750
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
Open
javuto
wants to merge
1
commit into
main
Choose a base branch
from
migrate-urfave-cli-v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "crypto/tls" | ||||||
| "fmt" | ||||||
| "net/http" | ||||||
|
|
@@ -26,7 +27,7 @@ import ( | |||||
| "github.com/jmpsec/osctrl/pkg/version" | ||||||
| "github.com/rs/zerolog" | ||||||
| "github.com/rs/zerolog/log" | ||||||
| "github.com/urfave/cli/v2" | ||||||
| "github.com/urfave/cli/v3" | ||||||
|
|
||||||
| "github.com/spf13/viper" | ||||||
| ) | ||||||
|
|
@@ -102,7 +103,7 @@ var ( | |||||
| queriesmgr *queries.Queries | ||||||
| filecarves *carves.Carves | ||||||
| handlersApi *handlers.HandlersApi | ||||||
| app *cli.App | ||||||
| app *cli.Command | ||||||
| flags []cli.Flag | ||||||
| flagParams config.ServiceFlagParams | ||||||
| auditLog *auditlog.AuditLogManager | ||||||
|
|
@@ -438,7 +439,7 @@ func osctrlAPIService() { | |||||
| } | ||||||
|
|
||||||
| // Action to run when no flags are provided to run checks and prepare data | ||||||
| func cliAction(c *cli.Context) error { | ||||||
| func cliAction(ctx context.Context, cmd *cli.Command) error { | ||||||
| // Load configuration if external JSON config file is used | ||||||
| if flagParams.ConfigFlag { | ||||||
| flagParams.ConfigValues, err = loadConfiguration(flagParams.ServiceConfigFile, config.ServiceAPI) | ||||||
|
|
@@ -500,44 +501,45 @@ func initializeLoggers(cfg config.JSONConfigurationService) { | |||||
|
|
||||||
| func main() { | ||||||
| // Initiate CLI and parse arguments | ||||||
| app = cli.NewApp() | ||||||
| app.Name = serviceName | ||||||
| app.Usage = appDescription | ||||||
| app.Version = buildVersion | ||||||
| app.Description = appDescription | ||||||
| app.Flags = flags | ||||||
| // Customize version output (supports `--version` and `version` command) | ||||||
| cli.VersionPrinter = func(c *cli.Context) { | ||||||
| fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate) | ||||||
| } | ||||||
| // Add -v alias to the global --version flag | ||||||
| cli.VersionFlag = &cli.BoolFlag{ | ||||||
| Name: "version", | ||||||
| Aliases: []string{"v"}, | ||||||
| Usage: "Print version information", | ||||||
| } | ||||||
| // Define this command for help to exit when help flag is passed | ||||||
| app.Commands = []*cli.Command{ | ||||||
| { | ||||||
| Name: "help", | ||||||
| Action: func(c *cli.Context) error { | ||||||
| cli.ShowAppHelpAndExit(c, 0) | ||||||
| app = &cli.Command{ | ||||||
| Name: serviceName, | ||||||
| Usage: appDescription, | ||||||
| Version: buildVersion, | ||||||
| Description: appDescription, | ||||||
| Flags: append(flags, &cli.BoolFlag{ | ||||||
| Name: "version", | ||||||
| Aliases: []string{"v"}, | ||||||
| Usage: "Print version information", | ||||||
| Action: func(ctx context.Context, cmd *cli.Command, b bool) error { | ||||||
| if b { | ||||||
| fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate) | ||||||
| os.Exit(0) | ||||||
| } | ||||||
| return nil | ||||||
| }, | ||||||
| }), | ||||||
| HideVersion: true, | ||||||
| Commands: []*cli.Command{ | ||||||
| { | ||||||
| Name: "help", | ||||||
| Action: func(ctx context.Context, cmd *cli.Command) error { | ||||||
| cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0) | ||||||
|
||||||
| cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0) | |
| cli.ShowCommandHelpAndExit(ctx, cmd, "", 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
cmd.Name(which is "help") as the command name parameter is incorrect. This should show the app-level help. Change tocli.ShowCommandHelpAndExit(ctx, cmd.Parent, \"\", 0)or use an empty string for the command name.