Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix(cli): alias add, cat and get to top-level cli
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb committed Sep 22, 2016
1 parent 5c035b6 commit d0141b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ updateNotifier({
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
}).notify()

yargs
const cli = yargs
.commandDir('commands')
.demand(1)
.help()

// NOTE: This creates an alias of
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
const addCmd = require('./commands/files/add')
const catCmd = require('./commands/files/cat')
const getCmd = require('./commands/files/get')
const aliases = [addCmd, catCmd, getCmd]
aliases.forEach((alias) => {
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
})

// finalize cli setup
cli.help()
.strict()
.completion()
.argv
18 changes: 18 additions & 0 deletions test/cli/test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ describe('files', () => {
done()
})
})
it('cat alias', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'cat', 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
expect(stdout[0]).to.equal('hello world')
done()
})
})

it('add', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'files', 'add', 'src/init-files/init-docs/readme'], {env})
Expand All @@ -31,6 +40,15 @@ describe('files', () => {
done()
})
})
it('add alias', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'add', 'src/init-files/init-docs/readme'], {env})
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
expect(stdout[0]).to.equal('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme')
done()
})
})

it('add recursively', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'files', 'add', '-r', 'src/init-files/init-docs'], {env})
Expand Down

0 comments on commit d0141b3

Please sign in to comment.