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

feature: add --format option for pouch ps #2844

Closed

Conversation

aohang111
Copy link

@aohang111 aohang111 commented May 14, 2019

Ⅰ. Describe what this PR did

for the issue #2827. CLI compatibility between Pouch and Docker

solve the pouch ps --format option.
if other command(such as pouch history/images/network/volume/stats/version) also need --format option.
can done similarly

Ⅱ. Does this pull request fix one issue?

fixes #2827,

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

have add unit test and integration test

Ⅳ. Describe how to verify it

root@ahsh-main:~/go/src/github.com/alibaba/pouch# pouch ps
Name ID Status Created Image Runtime
58b7de 58b7de Up 40 minutes 40 minutes ago registry.hub.docker.com/library/ubuntu:latest runc

root@ahsh-main:~/go/src/github.com/alibaba/pouch# pouch ps -a --format "table {{.ID}}\t{{.Status}}\t{{.Created}}"
ID Status Created
58b7de Up 11 seconds 11 seconds ago

root@ahsh-main:~/go/src/github.com/alibaba/pouch# pouch ps -a --format "table {{.ID}}\t{{.Status}}\t{{.Created}}\t{{.Name}}"
ID Status Created Name
58b7de Up 40 minutes 40 minutes ago 58b7de

root@ahsh-main:~/go/src/github.com/alibaba/pouch# pouch ps -a --format "raw"
Name:58b7de
ID:58b7de
Status:Up 4 seconds
Created:4 seconds ago
Image:registry.hub.docker.com/library/ubuntu:latest
Runtime:runc

Ⅴ. Special notes for reviews

with @houstar's help.

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #2844 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2844      +/-   ##
==========================================
- Coverage   69.09%   69.05%   -0.04%     
==========================================
  Files         285      285              
  Lines       17844    17844              
==========================================
- Hits        12330    12323       -7     
- Misses       4114     4122       +8     
+ Partials     1400     1399       -1     
Flag Coverage Δ
criv1alpha2_test 38.97% <ø> (-0.04%) ⬇️
integration_test_0 36.62% <ø> (+0.05%) ⬆️
integration_test_1 35.33% <ø> (-0.43%) ⬇️
integration_test_2 36.57% <ø> (+0.10%) ⬆️
integration_test_3 35.39% <ø> (-0.07%) ⬇️
node_e2e_test 34.81% <ø> (+0.03%) ⬆️
unittest 28.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/streams/utils.go 82.14% <0.00%> (-7.15%) ⬇️
ctrd/watch.go 72.97% <0.00%> (-5.41%) ⬇️
pkg/meta/store.go 67.44% <0.00%> (-1.56%) ⬇️
daemon/mgr/container_utils.go 76.76% <0.00%> (-1.02%) ⬇️
daemon/mgr/container.go 59.72% <0.00%> (-0.63%) ⬇️
ctrd/container.go 54.30% <0.00%> (+0.38%) ⬆️
cri/v1alpha2/cri.go 69.57% <0.00%> (+0.50%) ⬆️
daemon/mgr/spec_linux.go 80.21% <0.00%> (+1.06%) ⬆️
daemon/containerio/io.go 74.75% <0.00%> (+1.94%) ⬆️
daemon/logger/crilog/log.go 82.60% <0.00%> (+2.89%) ⬆️

@pouchrobot
Copy link
Collaborator

We found this is your first time to contribute to Pouch, @aohang111
👏 We really appreciate it.
Just remind that you have read the contribution guide: https://github.com/alibaba/pouch/blob/master/CONTRIBUTING.md
If you didn't, you should do that first. If done, welcome again and please enjoy hacking! 🍻

@CLAassistant
Copy link

CLAassistant commented May 14, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@houstar
Copy link
Contributor

houstar commented May 14, 2019

@aohang111 Could you use gofmt -s to format your source code as officially style? thanks

@aohang111 aohang111 changed the title Issue 2827 add --format option for pouch ps May 14, 2019
@allencloud
Copy link
Collaborator

Thank you greatly for your work. @aohang111
While I am wondering if we could add integration test for the pull request, not only the unit test.
Please feel free to tell us if you have some questions. Thanks again.

@houstar
Copy link
Contributor

houstar commented May 15, 2019

Could you squash previous four commits into one commits ?

@aohang111
Copy link
Author

aohang111 commented May 15, 2019

@allencloud
I am trying to add the integration test. by the way.
@houstar
will squash the commits into one commits.thanks

@aohang111
Copy link
Author

aohang111 commented May 16, 2019

@allencloud ,I have added the integration test. please assign someone to review this code ASAP
@houstar thanks for your guide and help

@houstar
Copy link
Contributor

houstar commented May 16, 2019

Well done. @aohang111 You've made this happen as your first contribution to pouch project

cli/cli.go Outdated Show resolved Hide resolved
cli/formatter/container.go Outdated Show resolved Hide resolved
cli/formatter/formatter_test.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Show resolved Hide resolved
cli/formatter/container.go Outdated Show resolved Hide resolved
cli/formatter/container.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Outdated Show resolved Hide resolved
cli/formatter/container.go Outdated Show resolved Hide resolved
@aohang111
Copy link
Author

@ZYecho ,modified and comments. pls review. thanks

cli/formatter/container.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Outdated Show resolved Hide resolved
cli/formatter/formatter.go Show resolved Hide resolved
cli/formatter/formatter.go Outdated Show resolved Hide resolved
@ZYecho
Copy link
Contributor

ZYecho commented May 20, 2019

@ZYecho ,modified and comments. pls review. thanks

Thanks for your contribution, just minor suggestions. Good Job!

@aohang111 aohang111 force-pushed the issue_2827 branch 2 times, most recently from 5f7d9ee to 00922cc Compare May 20, 2019 10:01
@aohang111
Copy link
Author

@ZYecho commit again. pls review. thanks

@aohang111
Copy link
Author

@ZYecho .done.

@pouchrobot
Copy link
Collaborator

ping @aohang111
Conflict happens after merging a previous commit.
Please rebase the branch against master and push it back again. Thanks a lot.

@cardyok cardyok requested a review from cxz66666 July 7, 2022 12:15
@cxz66666
Copy link
Collaborator

cxz66666 commented Jul 8, 2022

@fuweid ,if the user specify the quite mode. we just need to output the shorted container id . no need to care about if the format is specified. so I thought it is split with the logic of format display. what's your opinion .

I also think it's needless to care about the output format in quite mode, please resolve some conflicts ASAP and latter it will be merged into master!

@@ -5,6 +5,7 @@ import (
"os"
"strconv"
"text/tabwriter"
"text/template"
Copy link
Collaborator

Choose a reason for hiding this comment

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

There will be a merge conflict, please handle and rebase it!

if flagNoTrunc {
id = c.ID
}
runningFor, err := utils.FormatTimeInterval(c.Created)
Copy link
Collaborator

Choose a reason for hiding this comment

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

utils.FormatTimeInterval function have an extra new param, please fix it!

for _, c := range containers {
created, err := utils.FormatTimeInterval(c.Created)
containerContext, err := formatter.NewContainerContext(c, p.flagNoTrunc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a merge conflict, please handle it!

format = formatter.PreFormat(format)
if tableOrRaw {
containerHeader := formatter.ContainerHeader
p.cli.FormatDisplay(format, tmplH, containerHeader, w)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we handle the possible error at here and follow?
In my opinion, we should care about possible error during parsing the template, at least print some error messages.

}
display.Flush()
w.Flush()
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use _=w.Flush() instead of it!

@cxz66666
Copy link
Collaborator

Thank you for your contribution! because you don't response for a long time, I will close this PR and reopen #3037. ❤️

@cxz66666 cxz66666 closed this Jul 18, 2022
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.

[bug] CLI compatibility between Pouch and Docker
8 participants