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

Adds interactive mode for info command #265

Merged
merged 1 commit into from
Jun 23, 2021

Conversation

PuneetPunamiya
Copy link
Member

@PuneetPunamiya PuneetPunamiya commented May 21, 2021

  • This patch interactively ask the users to select

    • Catalog first
    • Resources in the catalog selected
    • All Versions of the resource selected
  • If there is only one catalog or version then
    it will be auto-selected

  • User can also get the information of the resource
    if the user know the catalog name, resource name
    and version of the resource by

    tkn hub info task <task-name> --version <version-number> --from catalog <catalog-name>

Signed-off-by: Puneet Punamiya ppunamiy@redhat.com

demo

Changes

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

@tekton-robot tekton-robot requested review from pratap0007 and sthaha May 21, 2021 06:43
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 21, 2021
@@ -139,8 +139,68 @@ func (opts *options) run() error {
}

hubClient := opts.cli.Hub()

// Get all Catalogs
catalog, err := hubClient.GetCatalogsList()
Copy link
Member

Choose a reason for hiding this comment

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

this can be done when user has not passed catalog

if opt.from == "" {
  get all catalogs
}

Copy link
Member Author

@PuneetPunamiya PuneetPunamiya May 24, 2021

Choose a reason for hiding this comment

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

I think in order to keep default catalog as tekton as mentioned here we'll have to make an api call to get all catalogs, but it will be better to keep the catalog flag i.e. from empty and make an api call first and get the catalogs list and if there is only one catalog then it won't ask for the catalog and select the catalog which is already there

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 keep the from flag empty but if user passes a catalog through the flag then you don't need to get all catalogs.
use that catalog to fetch the resource, whether it exist or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes make sense to get all the catalog if we keep the flag empty

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the PR!

api/pkg/cli/cmd/info/info.go Outdated Show resolved Hide resolved
api/pkg/cli/cmd/info/info.go Outdated Show resolved Hide resolved
api/go.mod Outdated Show resolved Hide resolved
@PuneetPunamiya PuneetPunamiya force-pushed the info-interactive branch 3 times, most recently from ab3ccd7 to d701dea Compare May 25, 2021 03:47
api/pkg/cli/cmd/info/info.go Outdated Show resolved Hide resolved
api/pkg/cli/cmd/info/info.go Outdated Show resolved Hide resolved
@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 25, 2021
@pratap0007
Copy link
Contributor

WDYT, To mention the latest version while displaying all versions of a resource

api/go.mod Outdated Show resolved Hide resolved
if err != nil {
return "", err
}
if len(ver) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

handle if no version

Copy link
Member Author

Choose a reason for hiding this comment

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

If there is no version of the resource then it won't be a hub resource

Copy link
Member Author

Choose a reason for hiding this comment

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

i.e. while parsing the catalog I guess the resource won't be added in the db

if len(ver) == 1 {
return ver[0], nil
} else {
latestVersion := ver[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a field in API response for latest version, better use that in case of versions array is not sorted

if err != nil {
return "", err
}
if len(resources) == 0 {
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 switch here :)

Copy link
Member Author

@PuneetPunamiya PuneetPunamiya Jun 9, 2021

Choose a reason for hiding this comment

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

Will there be any more cases ??
I mean there will be three cases like one with 0 resources, one with 1 resource and last with more than one, should we add switch ??

Copy link
Member

Choose a reason for hiding this comment

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

i would say yes :) [0,1,default]

}

Catalog := data.Catalogs
// // Get all catalog names
Copy link
Member

Choose a reason for hiding this comment

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

nit // Get all catalog names

@@ -172,11 +206,88 @@ func (opts *options) run() error {
return printer.New(out).Tabbed(tmpl, tmplData)
}

func (opts *options) AskCatalogName() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Line no 200-207 won't get be executed now right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think yes it won't be executed but in that case we don't need to even check if the version is empty, should we remove the condition to check if the version is empty ??

  - This patch interactively ask the users to select

	- Catalog first
   	- Resources in the catalog selected
	- All Versions of the resource selected

  - If there is only one catalog or version then
    it will be auto-selected

  - User can also get the information of the resource
    if the user know the catalog name, resource name
    and version of the resource by

    `tkn hub info task <task-name> --version <version-number> --from catalog <catalog-name>`

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
@sm43
Copy link
Member

sm43 commented Jun 14, 2021

/approve
/woof

@tekton-robot
Copy link

@sm43: dog image

In response to this:

/approve
/woof

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sm43

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2021
@pratap0007 pratap0007 self-requested a review June 21, 2021 09:27
@pratap0007
Copy link
Contributor

lgtm

@vinamra28
Copy link
Member

/lgtm
Thanks 🤙

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 23, 2021
@tekton-robot tekton-robot merged commit 2f00293 into tektoncd:main Jun 23, 2021
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. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants