This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
level-up #420
Merged
Merged
level-up #420
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
76b6670
feat(config): make the config impl spec compliant
daviddias 97af048
fix(style): apply CR
daviddias b28ae1f
wip
daviddias cc0c8fd
feat(bitswap tests, config, id): cope with the nuances of the config …
daviddias df02596
fix(core): all tests passing
daviddias 31f673d
feat(http): Refactor inject tests, made them all pass again
daviddias 56904fd
feat(http): refactor ipfs-api tests and make them all pass again
daviddias a3d98a8
fix(config): support null values (0 or empty string) on get and set
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const _get = require('lodash.get') | ||
const _set = require('lodash.set') | ||
|
||
module.exports = function config (self) { | ||
return { | ||
// cli only feature built with show and replace | ||
// edit: (callback) => {}, | ||
replace: (config, callback) => { | ||
get: promisify((key, callback) => { | ||
if (typeof key === 'function') { | ||
callback = key | ||
key = undefined | ||
} | ||
|
||
if (!key) { | ||
return self._repo.config.get(callback) | ||
} | ||
|
||
if (typeof key !== 'string') { | ||
return callback(new Error('Invalid key type')) | ||
} | ||
|
||
self._repo.config.get((err, config) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
const value = _get(config, key, undefined) | ||
if (!value) { | ||
callback(new Error('Key does not exist in config')) | ||
} else { | ||
callback(null, value) | ||
} | ||
}) | ||
}), | ||
set: promisify((key, value, callback) => { | ||
if (!key || typeof key !== 'string') { | ||
return callback(new Error('Invalid key type')) | ||
} | ||
|
||
if (!value || Buffer.isBuffer(value)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as above, can't set values to |
||
return callback(new Error('Invalid value type')) | ||
} | ||
|
||
self._repo.config.get((err, config) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
_set(config, key, value) | ||
self.config.replace(config, callback) | ||
}) | ||
}), | ||
replace: promisify((config, callback) => { | ||
self._repo.config.set(config, callback) | ||
}, | ||
show: (callback) => { | ||
self._repo.config.get(callback) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
'use strict' | ||
|
||
const pkg = require('../../../package.json') | ||
const promisify = require('promisify-es6') | ||
|
||
module.exports = function version (self) { | ||
return (opts, callback) => { | ||
return promisify((opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
|
||
callback(null, pkg.version) | ||
} | ||
callback(null, { | ||
version: pkg.version, | ||
repo: '', | ||
commit: '' | ||
}) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is not entirely accurate,
value
could be an empty string for0
, and would as such evaluate totrue
in this check.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.
good catch!