Skip to content

Add index list command - #537

Merged
k8s-ci-robot merged 7 commits into
kubernetes-sigs:masterfrom
chriskim06:index-command
Mar 10, 2020
Merged

k8s-ci-robot merged 7 commits into
kubernetes-sigs:masterfrom
chriskim06:index-command

Conversation

@chriskim06

Copy link
Copy Markdown
Member

Initial implementation of kubectl krew index list. This prints the indexes in a table in the same format as kubectl krew list:

$ KREW_ROOT="/home/kimc/playground" X_KREW_ENABLE_MULTI_INDEX=1 ./bin/krew-linux_amd64 index list
INDEX    URL
default  https://github.com/kubernetes-sigs/krew-index.git

I slightly refactored the exec function in gitutil to return the output of the command. The existing uses of it don't need it but I'm using the output from git config --get remote.origin.url to get the index's remote url. Let me know if there's a better way to get the url from git, that was the only way I knew how.

Related issue: #483

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 6, 2020
@k8s-ci-robot
k8s-ci-robot requested review from ahmetb and soltysh March 6, 2020 00:26
@ahmetb

ahmetb commented Mar 6, 2020 •

Copy link
Copy Markdown
Member

Needs cli integration tests. :)

Comment thread cmd/krew/cmd/index.go Outdated
// indexCmd represents the index command
var indexCmd = &cobra.Command{
Use: "index",
Short: "Perform krew index commands",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this doesn't look good in the help message:

Available Commands:

  index       Perform krew index commands

let's say something more meaningful.

Comment thread cmd/krew/cmd/index.go Outdated
Comment on lines +46 to +56
dirs, err := ioutil.ReadDir(paths.IndexBase())
if err != nil {
return errors.Wrapf(err, "failed to read directory %s", paths.IndexBase())
}
var rows [][]string
for _, dir := range dirs {
indexName := dir.Name()
remote, err := gitutil.GetRemoteURL(paths.IndexPath(indexName))
if err != nil {
return errors.Wrapf(err, "failed to list the remote URL for index %s", indexName)
}

@ahmetb ahmetb Mar 6, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Soon you'll find out you need a package where this lives and is tested.

I propose a package that does

ListIndexes(path string) ([]Index, error)
RemoveIndex(path, name string) error
AddIndex...

We can start small, so let's create a pkg, and let's add tests.

Right now the code I just highlighted here has 0 tests.

Comment thread cmd/krew/cmd/index.go Outdated
Short: "Perform krew index commands",
Long: "Perform krew index commands such as adding and removing indexes.",
Args: cobra.NoArgs,
Hidden: true, // remove this once multi-index is enabled

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use // TODO syntax

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 9, 2020
Comment thread internal/gitutil/git.go Outdated
func GetRemoteURL(dir string) (string, error) {
return exec(dir, "config", "--get", "remote.origin.url")
remote, err := Exec(dir, "config", "--get", "remote.origin.url")
return strings.TrimRight(remote, "\n\r"), err

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use strings.TrimFunc(unicode.IsSpace)

Furthermore, maybe just move this to Exec, as other cmds are likely going to need it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ended up using strings.TrimSpace, the linter complained about strings.TrimFunc('...', unicode.IsSpace)

Comment thread cmd/krew/cmd/index.go Outdated
Use: "index",
Short: "Perform krew index commands",
Long: "Perform krew index commands such as adding and removing indexes.",
Short: "Add, remove, and list indexes",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let鈥檚 just say:

Manage custom plugin indexes

& long

Manage which repositories are used to discover and install plugins from.

@ahmetb

ahmetb commented Mar 10, 2020

Copy link
Copy Markdown
Member

/lgtm
/approve
/hold
only small comments.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 10, 2020
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, chriskim06

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 10, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 10, 2020
@ahmetb

ahmetb commented Mar 10, 2020

Copy link
Copy Markdown
Member

/lgtm
/hold cancel
Thank you. 馃檹

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 10, 2020
@k8s-ci-robot
k8s-ci-robot merged commit fd1755a into kubernetes-sigs:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/multi-index cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants