-
-
Notifications
You must be signed in to change notification settings - Fork 167
reinstate --help #652
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
Open
dominictarr
wants to merge
2
commits into
master
Choose a base branch
from
help
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
reinstate --help #652
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #! /usr/bin/env node | ||
| var fs = require('fs') | ||
| var path = require('path') | ||
| var pull = require('pull-stream') | ||
| var toPull = require('stream-to-pull-stream') | ||
| var File = require('pull-file') | ||
| var explain = require('explain-error') | ||
| var Config = require('ssb-config/inject') | ||
| var Client = require('ssb-client') | ||
| var createHash = require('multiblob/util').createHash | ||
| var minimist = require('minimist') | ||
| var muxrpcli = require('muxrpcli') | ||
| var cmdAliases = require('./lib/cli-cmd-aliases') | ||
| //var ProgressBar = require('./lib/progress') | ||
| var packageJson = require('./package.json') | ||
|
|
||
| //get config as cli options after --, options before that are | ||
| //options to the command. | ||
|
|
||
| module.exports = function (config, argv) { | ||
| // var argv = config._ | ||
| var manifestFile = path.join(config.path, 'manifest.json') | ||
|
|
||
| // normal command: | ||
| // create a client connection to the server | ||
|
|
||
| // read manifest.json | ||
| var manifest | ||
| try { | ||
| manifest = JSON.parse(fs.readFileSync(manifestFile)) | ||
| } catch (err) { | ||
| throw explain(err, | ||
| 'no manifest file' | ||
| + '- should be generated first time server is run' | ||
| ) | ||
| } | ||
|
|
||
| var opts = { | ||
| manifest: manifest, | ||
| port: config.port, | ||
| host: config.host || 'localhost', | ||
| caps: config.caps, | ||
| key: config.key || config.keys.id | ||
| } | ||
|
|
||
| // connect | ||
| Client(config.keys, opts, function (err, rpc) { | ||
| if(err) { | ||
| if (/could not connect/.test(err.message)) { | ||
| console.error('Error: Could not connect to ssb-server ' + opts.host + ':' + opts.port) | ||
| console.error('Use the "start" command to start it.') | ||
| console.error('Use --verbose option to see full error') | ||
| if(config.verbose) throw err | ||
| process.exit(1) | ||
| } | ||
| throw err | ||
| } | ||
|
|
||
| // add aliases | ||
| for (var k in cmdAliases) { | ||
| rpc[k] = rpc[cmdAliases[k]] | ||
| manifest[k] = manifest[cmdAliases[k]] | ||
| } | ||
|
|
||
| // add config command (should we remove this? it's not documented!) | ||
| manifest.config = 'sync' | ||
| rpc.config = function (cb) { | ||
| console.log(JSON.stringify(config, null, 2)) | ||
| cb() | ||
| } | ||
|
|
||
| // HACK | ||
| // we need to output the hash of blobs that are added via blobs.add | ||
| // because muxrpc doesnt support the `sink` callback yet, we need this manual override | ||
| // -prf | ||
| if (process.argv[2] === 'blobs.add') { | ||
| var filename = process.argv[3] | ||
| var source = | ||
| filename ? File(process.argv[3]) | ||
| : !process.stdin.isTTY ? toPull.source(process.stdin) | ||
| : (function () { | ||
| console.error('USAGE:') | ||
| console.error(' blobs.add <filename> # add a file') | ||
| console.error(' source | blobs.add # read from stdin') | ||
| process.exit(1) | ||
| })() | ||
| var hasher = createHash('sha256') | ||
| pull( | ||
| source, | ||
| hasher, | ||
| rpc.blobs.add(function (err) { | ||
| if (err) | ||
| throw err | ||
| console.log('&'+hasher.digest) | ||
| process.exit() | ||
| }) | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| // run commandline flow | ||
| muxrpcli(argv, manifest, rpc, config.verbose) | ||
| }) | ||
| } | ||
|
|
||
| if(!module.parent && process.title != 'browser') { | ||
|
Contributor
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. can there be a comment to describe what this is doing? |
||
| var argv = process.argv.slice(2) | ||
| var i = argv.indexOf('--') | ||
| var conf = argv.slice(i+1) | ||
| argv = ~i ? argv.slice(0, i) : argv | ||
| module.exports(Config(process.env.ssb_appname, minimist(conf)), argv) | ||
|
Contributor
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. there's a lot happening here, but it's hard to tell what is happening, what about: var args = process.argv.slice(2)
var [methodArgs, configArgs] = splitArgsBySeparator(args)
var appName = process.env.ssb_appname
var configOptions = minimist(configArgs)
var config = Config(appName, configOptions)
cli(config, methodArgs)
function splitArgvBySeparator (args) {
var splitIndex = args.indexOf('--')
var methodArgs = splitIndex == -1 ? args : args.slice(0, splitIndex)
var configArgs = args.slice(splitIndex + 1)
return [methodArgs, configArgs]
} |
||
| } | ||
|
|
||
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
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.
can we name this function
clior something?as down at the bottom, we call
module.exports(...)and took me a few moments to grok what was happening.