-
Notifications
You must be signed in to change notification settings - Fork 376
PT-2368 - refactor all tools cli #1096
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
base: 3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -129,6 +129,10 @@ Supported Flags | |||||||||||||||
|
|
||||||||||||||||
| List of Percona Toolkit configuration file(s) separated by a comma without an equal sign. Must be a first flag. Uses default config file locations if not specified. | ||||||||||||||||
|
|
||||||||||||||||
| ``--help`` | ||||||||||||||||
|
|
||||||||||||||||
| Show help and exit. | ||||||||||||||||
|
|
||||||||||||||||
| ``--resource`` | ||||||||||||||||
|
|
||||||||||||||||
| Targeted custom resource name. Supported values: | ||||||||||||||||
|
|
@@ -177,6 +181,18 @@ Default: ``auto`` | |||||||||||||||
| ``--skip-pod-summary`` | ||||||||||||||||
| Skip the collection of pod-specific summary data. | ||||||||||||||||
|
|
||||||||||||||||
| ``--skip-pod-summary`` | ||||||||||||||||
|
|
||||||||||||||||
| Skip pod summary collection. | ||||||||||||||||
|
|
||||||||||||||||
| ``--version-check`` | ||||||||||||||||
|
|
||||||||||||||||
| Check for updates (enabled by default). | ||||||||||||||||
|
|
||||||||||||||||
| ``--no-version-check`` | ||||||||||||||||
|
|
||||||||||||||||
| Disable update checks. | ||||||||||||||||
|
|
||||||||||||||||
| ``--version`` | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||
| Print version info. | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -244,4 +260,3 @@ VERSION | |||||||||||||||
| ======= | ||||||||||||||||
|
|
||||||||||||||||
| :program:`pt-k8s-debug-collector` 3.7.1 | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "text/template" | ||
| "time" | ||
|
|
@@ -29,16 +30,29 @@ import ( | |
| "go.mongodb.org/mongo-driver/mongo" | ||
| "go.mongodb.org/mongo-driver/mongo/options" | ||
|
|
||
| "github.com/percona/percona-toolkit/src/go/lib/config" | ||
| "github.com/percona/percona-toolkit/src/go/lib/versioncheck" | ||
| "github.com/percona/percona-toolkit/src/go/pt-mongodb-index-check/indexes" | ||
| "github.com/percona/percona-toolkit/src/go/pt-mongodb-index-check/templates" | ||
| ) | ||
|
|
||
| type cmdlineArgs struct { | ||
| const ( | ||
| toolname = "pt-mongodb-index-check" | ||
| ) | ||
|
|
||
| // We do not set anything here, these variables are defined by the Makefile | ||
| var ( | ||
| Build string //nolint | ||
| GoVersion string //nolint | ||
| Version string //nolint | ||
| Commit string //nolint | ||
| ) | ||
|
|
||
| type CmdlineArgs struct { | ||
| config.ConfigFlag | ||
| CheckUnused struct{} `cmd:"" name:"check-unused" help:"Check for unused indexes."` | ||
| CheckDuplicated struct{} `cmd:"" name:"check-duplicates" help:"Check for duplicated indexes."` | ||
| CheckAll struct{} `cmd:"" name:"check-all" help:"Check for unused and duplicated indexes."` | ||
| ShowHelp struct{} `cmd:"" default:"1"` | ||
| Version kong.VersionFlag | ||
|
|
||
| AllDatabases bool `name:"all-databases" xor:"db" help:"Check in all databases excluding system dbs"` | ||
| Databases []string `name:"databases" xor:"db" help:"Comma separated list of databases to check"` | ||
|
|
@@ -47,30 +61,50 @@ type cmdlineArgs struct { | |
| Collections []string `name:"collections" xor:"colls" help:"Comma separated list of collections to check"` | ||
| URI string `name:"mongodb.uri" required:"" placeholder:"mongodb://host:port/admindb?options" help:"Connection URI"` | ||
| JSON bool `name:"json" help:"Show output as JSON"` | ||
|
|
||
| config.VersionFlag | ||
| config.VersionCheckFlag | ||
| } | ||
|
|
||
| func (c *CmdlineArgs) AfterApply() error { | ||
| if c.VersionCheck { | ||
| advice, err := versioncheck.CheckUpdates(toolname, Version) | ||
| if err != nil { | ||
| log.Errorf("cannot check version updates: %s", err.Error()) | ||
| } else if advice != "" { | ||
| log.Infof("%s", advice) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| type response struct { | ||
| Unused []indexes.IndexStat | ||
| Duplicated []indexes.Duplicate | ||
| } | ||
|
|
||
| const ( | ||
| toolname = "pt-mongodb-index-check" | ||
| ) | ||
|
|
||
| // We do not set anything here, these variables are defined by the Makefile | ||
| var ( | ||
| Build string //nolint | ||
| GoVersion string //nolint | ||
| Version string //nolint | ||
| Commit string //nolint | ||
| ) | ||
|
|
||
| func main() { | ||
| var args cmdlineArgs | ||
| kongctx := kong.Parse(&args, kong.UsageOnError(), | ||
| kong.Vars{"version": fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s", | ||
| toolname, Version, Build, GoVersion, Commit)}) | ||
| var args CmdlineArgs | ||
| kongctx, _, err := config.Setup( | ||
| toolname, | ||
| &args, | ||
| kong.UsageOnError(), | ||
| kong.Vars{ | ||
| "version": fmt.Sprintf( | ||
| "%s\nVersion %s\nBuild: %s using %s\nCommit: %s", | ||
| toolname, Version, Build, GoVersion, Commit, | ||
| ), | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| log.Errorf("cannot get parameters: %s", err.Error()) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if args.Version { | ||
| return | ||
| } | ||
|
Comment on lines
+105
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that this is redundant. Kong exits automatically for version flag. |
||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) | ||
| defer cancel() | ||
|
|
||
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.
Duplicate