Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

cli: add --human flag to repo stat & stats repo #2102

Closed
wants to merge 2 commits into from

Conversation

chirag-shinde
Copy link
Contributor

@chirag-shinde chirag-shinde commented May 23, 2019

  • Added a humanize object to /src/cli/utils with Bytes method
    that takes bytes and returns Human readable size.
  • Used humanize.Bytes() method in /commands/stats/repo and
    /commands/repo/stat if --human flag is passed.

solves #1996

License: MIT
Signed-off-by: Chirag Shinde shinde.chirag2204@gmail.com

@chirag-shinde
Copy link
Contributor Author

Screenshot of the output
Screenshot 2019-05-23 at 8 56 38 PM

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

Please would you add a unit test for this handler to assert that it is converting the values to human readable form when the human flag is passed?

Note you can make this easier to test by changing the handler to return the value you want to print (it'll be printed automatically) instead of using the print function.

src/cli/utils.js Outdated
} while (Math.abs(bytes) >= thresh && unit < units.length - 1)
return bytes.toFixed(1) + ' ' + units[unit]
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we please use a tested module on npm for this? ipfs-http-response already uses filesize - can we use the same module?

- Added a `humanize` object to /src/cli/utils with `Bytes` method
that takes bytes and returns Human readable size.
- Used `humanize.Bytes()` method in /commands/stats/repo and
/commands/repo/stat if `--human` flag is passed.

License: MIT
Signed-off-by: Chirag Shinde <shinde.chirag2204@gmail.com>
- Use filesize to return human readable sizes.
- handler now returns stats instead of printing them.

License: MIT
Signed-off-by: Chirag Shinde <shinde.chirag2204@gmail.com>
@chirag-shinde
Copy link
Contributor Author

I'd like some help with writing the unit test for handler please.
As it is returning a string of stats I'm not sure how to go about testing for the --human flag as the only difference between the two strings would be with or without size units.
Thanks.

@daviddias
Copy link
Member

Hi! js-ipfs master just got a whole new set of automated tests with #2528, #2440 and also running some of the test suites from our early testers (hi5 to @achingbrain for setting it all up!). Would you mind rebasing the master branch on this PR to ensure it runs all the latest tests? Thank you!

@chirag-shinde chirag-shinde deleted the humanize-repo-stat branch October 23, 2019 11:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants