Skip to content
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

Add index list command #537

Merged
merged 7 commits into from
Mar 10, 2020
Merged

Conversation

chriskim06
Copy link
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
@ahmetb
Copy link
Member

ahmetb commented Mar 6, 2020

Needs cli integration tests. :)

// indexCmd represents the index command
var indexCmd = &cobra.Command{
Use: "index",
Short: "Perform krew index commands",
Copy link
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 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)
}
Copy link
Member

@ahmetb ahmetb Mar 6, 2020

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.

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
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
@@ -72,10 +72,11 @@ func EnsureUpdated(uri, destinationPath string) error {

// GetRemoteURL returns the url of the remote origin
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
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
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)

"sigs.k8s.io/krew/pkg/constants"
)

// indexCmd represents the index command
var indexCmd = &cobra.Command{
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
Member

Choose a reason for hiding this comment

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

Let’s just say:

Manage custom plugin indexes

& long

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

@ahmetb
Copy link
Member

ahmetb commented Mar 10, 2020

/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
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

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
Copy link
Member

ahmetb commented Mar 10, 2020

/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