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 Nov 10, 2016
1 parent 2c5561f commit 6ad325b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
19 changes: 16 additions & 3 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
.argv
31 changes: 31 additions & 0 deletions test/cli/test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('files', () => {
})
})

it('cat alias', () => {
return ipfs('cat QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
expect(out).to.be.eql('hello world')
})
})

it('get', () => {
return ipfs('files get QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
expect(out).to.be.eql(
Expand All @@ -33,6 +39,23 @@ describe('files', () => {
})
})

it('get alias', () => {
return ipfs('get QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
expect(out).to.be.eql(
'Saving file(s) to QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
)

const file = path.join(process.cwd(), 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o')
expect(
fs.readFileSync(file).toString()
).to.be.eql(
'hello world\n'
)

fs.unlinkSync(file)
})
})

it('add', () => {
return ipfs('files add src/init-files/init-docs/readme').then((out) => {
expect(out).to.be.eql(
Expand All @@ -41,6 +64,14 @@ describe('files', () => {
})
})

it('add alias', () => {
return ipfs('add src/init-files/init-docs/readme').then((out) => {
expect(out).to.be.eql(
'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme'
)
})
})

it('add recursively', () => {
return ipfs('files add -r src/init-files/init-docs').then((out) => {
expect(out).to.be.eql([
Expand Down

0 comments on commit 6ad325b

Please sign in to comment.