-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Assume config value to be json-formatted in cli #1355
Conversation
There were the following issues with your Pull Request
Guidelines are available at: https://github.com/ipfs/community/blob/master/docs/commit-message.md Your feedback on GitCop is welcome on the following issue: ipfs/infra#23 This message was auto-generated by https://gitcop.com |
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
This deprecates explicit '--bool' and '--json' flag. The reason is, if explicit type has to be specified, then '--integer', '--float' also need to be implemented. But json parser already knows how to handle these types, so why not just use it. License: MIT Signed-off-by: rht <rhtbot@gmail.com>
we should re-run the tests here. everything appears to have failed |
if err := json.Unmarshal([]byte(value), &jsonVal); err != nil { | ||
err = fmt.Errorf("failed to unmarshal json. %s", err) | ||
res.SetError(err, cmds.ErrNormal) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so always default to json? that makes sense, but does that mean that we now have to do:
# used to work
> ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
# must now be
> ipfs config Addresses.API "/ip4/127.0.0.1/tcp/5001"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Thu, Jun 11, 2015 at 01:34:07PM -0700, Juan Batiz-Benet wrote:
must now be
ipfs config Addresses.API "/ip4/127.0.0.1/tcp/5001"
Implementations differ in how strictly they enforce this, but I've
seen a number of folks suggest that strings are not valid JSON root
objects (e.g. 1). That's also how it's written up in RFC 4627 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
still works in this case (golang/pkg/encoding/json).
So I will have to check which implementation (RFC 4627 vs ECMA-262 5 and newer) is among the majority today.
edit: from here on 'ECMA-262 5' is renamed RFC 7159 https://tools.ietf.org/html/rfc7159#section-2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
still works
ok great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accept stand-alone strings, numbers (RFC 7159):
- Go 1.3+
- Major browsers (IE 8+, everything else not IE)[1]
- Python 2.7+[1]
else (RFC 4627):
- Ruby 2.1.1 stdlib "json" [2]
Pending:
http://json.org/ (150-ish of those)
[1] http://stackoverflow.com/questions/18202532/can-a-single-stand-alone-literal-form-a-valid-json-document
[2] manual check & "JSON.generate only allows objects or arrays to be converted to JSON syntax." in http://ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html
Or since RFC 7159 supersedes RFC 4627, any legacy system will move toward it anyway.
I re-ran the tests. something bad's going on.
|
I see, I likely didn't type the beginning slash when testing With this commit, all strings must be explicitly formatted as "string". I suppose the options now are:
|
|
maybe we can be a little smart about things. things like: if |
I'd prefer being simple and explicit. Smartness can introduce weird edge cases |
I think
The only breaking change in (1.) is the necessity of "--string". (4.) by itself blurs the edge cases, i.e. it emulates the flexibility "smartness" of a human parser, but also its sloppiness. But this can still be fine because the config struct's are explicitly typed. And so this will always detect a malformed bool/int/float/array/object as a final check. This 2nd type check doesn't exist for user-specified values, however (and if this is hard to debug...). Also doesn't exist in dynamically typed languages. There is actually option (5.): use https://github.com/vstakhov/libucl (as a superset of json) just for parsing then serialize to json.
It looks like strings can be inferred unambiguously and efficiently. But this is not a sufficient reason to integrate the whole library though (and also more formats to keep track of for compatibility: json, ucl, go types, other ipfs implementation types). |
@rht not sure here. i think we should make sure not to
if you want to try (4.) then let's do it, but we'll need good tests to make sure various things get set correctly to what we expect. |
The only edge case with (4) is with user-specified values. The |
This deprecates explicit '--bool' and '--json' flag.
The reason is, if explicit type has to be specified, then '--integer',
'--float' also need to be implemented. But json parser already knows how
to handle these types, so why not just reuse it.
ref: #740