-
-
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
ipfs config command with git-style option value getters and setters #16
Conversation
Adds "ipfs config" command designed in git style. See specific config's values with: $ipfs config datastore.path ~/.go-ipfs/datastore Assign a new value with: $ipfs config datastore.path ~/.go-ipfs/datastore Open the config file in your default editor(as taken from $EDITOR enviroment variable): ipfs config edit
This is great, and totally needed. Thanks! I'll CR shortly-- i'll probably have some comments. One comment is that, right now, the main codebase is progressing in the dht branch. We can merge later, but might be annoying (thanks to my inconsistent Another comment is that i implemented something similar we can draw from in https://github.com/jbenet/data/blob/master/data_config.go months ago. It probably sucks (and uses yaml), but putting it here for reference. |
Merging this PR into |
can you resubmit the pull request against the dht branch then? (not sure if github allows you to change the target branch on the fly) |
var cfg interface{} | ||
var exists bool | ||
|
||
err = json.Unmarshal(buf, &cfg) |
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.
The more idiomatic go way of doing this would be to just open the file os.Open
and then use json.NewDecoder
to do the decoding.
fi,err := os.Open(filename)
if err != nil {//whatever}
dec := json.NewDecoder(fi)
var cfg map[string]interface{}
err := dec.Decode(&cfg)
if err != nil {//whatever}
(obviously written cleaner than my chicken scratch)
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.
I can rewrite it using json.Decoder
, but I don't really see that much of a difference.
Could you please comment on why this way is preferable / more idiomatic?
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.
@jmoiron does a good job explaining it in one of his articles: http://jmoiron.net/blog/crossing-streams-a-love-letter-to-ioreader/
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.
That's a good post!
@dborzov I can rewrite it-- there's a few more stylistic things i'll fix that don't want to annoy with.
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.
Thanks for the link, that article makes good sense to me.
Awesome, merged manually in 4b1bae8...639d196 (onto master), thanks! |
Note the new help message, for some of the changes I made.
|
Great, the rewrite looks very nice, thanks! There is a related thing I wanted to ask about. There are hooks all over the place to pass the custom path to config file with a flag. There is also a TODO comment on that at
|
Hm, yeah, we could use an env variable. Am on the fence about that-- there are many programs on either camp. shrug I don't care much either way. |
Fix SIGSEGV due to incorrect usage of sync.Pool
Add "jpeg" as an alias to "jpg".
add a Clone function
add a Clone function
add a Clone function
add a Clone function
gx publish 1.1.15
Hi there! i wanted to add something small and simple and attempted to make the "ipfs config" command. The idea was to follow git's command line syntax style.
So now we can get specific config's key values with:
And assign new values to the keys with:
Plus, in the style similar to:
we can open the config file in the default editor(as taken from $EDITOR environment variable):
One thing to address in the future is that the config keys here are simply read (or assigned) from config's JSON, and just ignore the actual go-ipfs/config structures.
The other one is to add support for custom config file's path.
I would very much appreciate any feedback. Thanks!