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

Add --json option to get balance as JSON #103

Merged
merged 5 commits into from
May 23, 2022
Merged

Conversation

sculptex
Copy link
Contributor

@sculptex sculptex commented Mar 22, 2022

usd - Current USD value,
zcn - ZCN amount (float)
fmt - Formatted zcn value (mZCN etc.)

A brief description of the changes in this PR:

Tasks to complete before merging PR:

  • Ensure system tests are passing. If not Run them manually to check for any regressions 📋
  • Do any new system tests need added to test this change? do any existing system tests need updated? If so create a PR at 0chain/system_test
  • Merge your system tests PR to master AFTER merging this PR

Associated PRs (Link as appropriate):

  • blobber:
  • gosdk:
  • system_test:
  • zboxcli:
  • 0chain:
  • Other: ...

@sculptex
Copy link
Contributor Author

sculptex commented Mar 22, 2022

Actually, for true JSON support for such commands, we could have a success variable. Only when success:true would the user then read the rest of the values. An alternative would be just to return relevant parameters of ZCN being 0.

For now, I will just class invalid JSON as 0.

@@ -14,6 +15,8 @@ var getbalancecmd = &cobra.Command{
Long: `Get balance from sharders`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
doJSON, _ := cmd.Flags().GetBool("json")
Copy link
Member

Choose a reason for hiding this comment

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

Check error in case use invalid value is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--json is bool so requires no parameter. But feel free to change however is best way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterlimg do you agree? there is no parameter to check?

cmd/getbalance.go Show resolved Hide resolved
@sculptex
Copy link
Contributor Author

sculptex commented Apr 4, 2022

@peterlimg what is your opinion on having success field?
So that with --json, valid json is always returned, even if just {"success"=false} or whatever.
But then client only checks other values if success=true?

@peterlimg
Copy link
Member

@peterlimg what is your opinion on having success field? So that with --json, valid json is always returned, even if just {"success"=false} or whatever. But then client only checks other values if success=true?

I would suggest to not add the success field, we can return json value when success, and return error directly. We can put the command in RunE(), so when error happens, it will have a formatted message returned, i.e, "Error: xxxx", so if the CLI is used by other services, the prefix of "Error" could be checked.

@sculptex
Copy link
Contributor Author

sculptex commented Apr 4, 2022

Okay, sure.

@sculptex
Copy link
Contributor Author

sculptex commented Apr 5, 2022

@peterlimg sorry, I'm not too hot with GitHub, am I required to implement your changes before you can approve and close?

@sculptex
Copy link
Contributor Author

@peterlimg can this be merged now?

Copy link
Contributor

@cnlangzi cnlangzi left a comment

Choose a reason for hiding this comment

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

LGTM

usd - Current USD value,
zcn - ZCN amount (float)
fmt - Formatted zcn value (mZCN etc.)
@cnlangzi cnlangzi force-pushed the sculptex-json-getbalance branch from ca0e294 to c6b95b3 Compare April 21, 2022 10:02
@sculptex
Copy link
Contributor Author

why wasn't this merged? now its conflicting again..

@cnlangzi cnlangzi merged commit 1cfc74e into staging May 23, 2022
@cnlangzi cnlangzi deleted the sculptex-json-getbalance branch May 23, 2022 02:37
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.

3 participants