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

fix(commands): support --enc=json in stat #5620

Closed
wants to merge 1 commit into from

Conversation

overbool
Copy link
Contributor

Fixes: #5594

License: MIT
Signed-off-by: Overbool overbool.xu@gmail.com

License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
@overbool overbool requested a review from Kubuxu as a code owner October 21, 2018 03:59
@overbool
Copy link
Contributor Author

@magik6k could u help me review it?


if polling {
fmt.Fprintln(os.Stdout, "Total Up Total Down Rate Up Rate Down")
// print only once in `--poll` flag
once.Do(func() {
Copy link
Member

Choose a reason for hiding this comment

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

This won't work for multiple invocations of the command, not sure what's the best way to do that. cc @keks

Copy link
Contributor

Choose a reason for hiding this comment

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

The proper way to do this is using PostRun. Encoders are for processing individual elements, while PostRun is passed the stream that is emitted by Run and can do transport (e.g. cli or http) specific presentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify: I think we need a second PostRunFunc in the PostRun map with index cmds.JSON.

}
},

fmt.Fprintf(os.Stdout, "%8s ", humanize.Bytes(uint64(bs.TotalOut)))
Copy link
Member

Choose a reason for hiding this comment

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

We should be also probably be printing into the writer instead of directly to Stdout.

@Stebalien
Copy link
Member

(closing due to inactivity)

@Stebalien Stebalien closed this Mar 5, 2019
jbouwman pushed a commit to jbouwman/go-ipfs-cmds that referenced this pull request Aug 19, 2021
Several open issues mention problems with interaction of the
global `--encoding=` flag and the Encoders and PostRun fields of
command structs. This branch contains experimental refactors that
explore approaches to consistent command execution patterns across
offline, online and http modes.

Specific tickets:

- ipfs/kubo#7050 json encoding for `ls`
- ipfs/kubo#1121 json encoding for `add`
- ipfs/kubo#5594 json encoding for `stats bw`
- ipfs#115 postrun design

Possibly related:

- ipfs/kubo#6640 global flags on subcommands

Incomplete PRs:

- ipfs/kubo#5620 json for 'stat'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants