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

feat: add printer supporting tree, table and yaml format #174

Conversation

ycyaoxdu
Copy link
Member

Signed-off-by: ycyaoxdu [email protected]

@openshift-ci openshift-ci bot requested review from itdove and qiujian16 March 24, 2022 07:12
@ycyaoxdu
Copy link
Member Author

#133
some command may do not need yaml output? such as hub-info, klusterlet-info? so i just added -o flag for which may need yaml output.
i think i need more suggestions on this...

@ycyaoxdu
Copy link
Member Author

/hold

@itdove
Copy link
Member

itdove commented Apr 1, 2022

@ycyaoxdu Can't you use something like this:

return o.printer.PrintObj(table, o.Streams.Out)
which gives you all the -o options instead only the YAML.

@ycyaoxdu
Copy link
Member Author

ycyaoxdu commented Apr 2, 2022

@itdove i've added a field to genericclioptions called Printer c90782a
and then the usage is like f50b50f
, how about this?


return o.printer.PrintObj(table, o.Streams.Out)

and also used this resourcePrinter to do this.

@ycyaoxdu ycyaoxdu force-pushed the feat/general-printers branch 3 times, most recently from f50b50f to 6c87d4d Compare April 2, 2022 01:51
@itdove
Copy link
Member

itdove commented Apr 4, 2022

I don't think a genericoption is the good choice as I think -o doesn't apply to all commands but only on get commands...
as you can see here https://github.com/stolostron/cm-cli/blob/5bbe69bf8312ef615d31d5b5037ae0c0174cb0c7/pkg/cmd/get/clusterclaim/cmd.go#L52-L54 I added the -o to each command I think they can use it. I didn't add it to all gets because some of the get cmd are not supposed to have a -o like cm get config cluster.

@ycyaoxdu
Copy link
Member Author

I don't think a genericoption is the good choice as I think -o doesn't apply to all commands but only on get commands... as you can see here https://github.com/stolostron/cm-cli/blob/5bbe69bf8312ef615d31d5b5037ae0c0174cb0c7/pkg/cmd/get/clusterclaim/cmd.go#L52-L54 I added the -o to each command I think they can use it. I didn't add it to all gets because some of the get cmd are not supposed to have a -o like cm get config cluster.

hi @itdove I've noticed that we need to add apis to generalize the --output ? could you please help to contribute this feature? or give me some advice on this? thanks a lot.

@ycyaoxdu ycyaoxdu changed the title feat: add -o yaml output for cluster, clusterset, work [wip]feat: add -o yaml output for cluster, clusterset, work Sep 28, 2022
@ycyaoxdu ycyaoxdu force-pushed the feat/general-printers branch 2 times, most recently from 4336c6d to add786c Compare September 29, 2022 03:50
@ycyaoxdu
Copy link
Member Author

@qiujian16 PTAL
add a printer supporting tree, table, yaml format

➜  clusteradm git:(feat/general-printers) clusteradm get clusters
<ManagedCluster> 
└── <cluster1> 
│   ├── <KubernetesVersion> v1.24.0
│   ├── <Capacity> 
│   │   ├── <Cpu> 16
│   │   ├── <Memory> 32763764Ki
│   ├── <Accepted> true
│   ├── <Available> True
│   ├── <ClusterSet> default
└── <cluster2> 
    └── <Capacity> 
    │   ├── <Cpu> 16
    │   ├── <Memory> 32763764Ki
    └── <Accepted> true
    └── <Available> True
    └── <ClusterSet> default
    └── <KubernetesVersion> v1.24.0
➜  clusteradm git:(feat/general-printers) clusteradm get clustersets
<ManagedClusterSet> 
└── <default> 
│   ├── <Status> 2 ManagedClusters selected
│   ├── <BoundNamespace> default
└── <global> 
    └── <BoundNamespace> 
    └── <Status> 2 ManagedClusters selected
➜  clusteradm git:(feat/general-printers) clusteradm get works --cluster cluster1
<ManifestWork> 
└── <my-first-work> 
│   ├── <Cluster> cluster1
│   ├── <Number of Manifests> 2
│   ├── <Applied> False
│   ├── <Available> True
└── <example-manifestwork> 
    └── <Cluster> cluster1
    └── <Number of Manifests> 2
    └── <Applied> True
    └── <Available> True

default format has set to tree.

@ycyaoxdu
Copy link
Member Author

/assign @qiujian16

@ycyaoxdu ycyaoxdu changed the title [wip]feat: add -o yaml output for cluster, clusterset, work [wip]feat: add printer supporting tree, table and yaml format Sep 29, 2022
@ycyaoxdu ycyaoxdu changed the title [wip]feat: add printer supporting tree, table and yaml format feat: add printer supporting tree, table and yaml format Sep 30, 2022
pkg/helpers/printer/Trie.go Outdated Show resolved Hide resolved
pkg/cmd/get/cluster/cmd.go Outdated Show resolved Hide resolved
@ycyaoxdu ycyaoxdu force-pushed the feat/general-printers branch 4 times, most recently from fec3728 to 8fdf005 Compare October 11, 2022 06:30
@ycyaoxdu ycyaoxdu force-pushed the feat/general-printers branch 2 times, most recently from a53c51a to 1d4e300 Compare October 12, 2022 03:06
Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Oct 12, 2022
@openshift-ci
Copy link

openshift-ci bot commented Oct 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, ycyaoxdu

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

@ycyaoxdu
Copy link
Member Author

/unhold

@openshift-merge-robot openshift-merge-robot merged commit 2548749 into open-cluster-management-io:main Oct 12, 2022
@ycyaoxdu ycyaoxdu deleted the feat/general-printers branch October 12, 2022 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants