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

Commit 2e15235

Browse files
authored
Merge pull request #493 from VictorBjelkholm/add-files-aliases
fix(cli): alias add, cat and get to top-level cli
2 parents 2c5561f + 6ad325b commit 2e15235

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/cli/bin.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ updateNotifier({
1212
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
1313
}).notify()
1414

15-
yargs
15+
const cli = yargs
1616
.commandDir('commands')
1717
.demand(1)
18-
.help()
18+
19+
// NOTE: This creates an alias of
20+
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
21+
// This will stay until https://github.com./ipfs/specs/issues/98 is resolved.
22+
const addCmd = require('./commands/files/add')
23+
const catCmd = require('./commands/files/cat')
24+
const getCmd = require('./commands/files/get')
25+
const aliases = [addCmd, catCmd, getCmd]
26+
aliases.forEach((alias) => {
27+
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
28+
})
29+
30+
// finalize cli setup
31+
cli.help()
1932
.strict()
2033
.completion()
21-
.argv
34+
.argv

test/cli/test-files.js

+31
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ describe('files', () => {
1616
})
1717
})
1818

19+
it('cat alias', () => {
20+
return ipfs('cat QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
21+
expect(out).to.be.eql('hello world')
22+
})
23+
})
24+
1925
it('get', () => {
2026
return ipfs('files get QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
2127
expect(out).to.be.eql(
@@ -33,6 +39,23 @@ describe('files', () => {
3339
})
3440
})
3541

42+
it('get alias', () => {
43+
return ipfs('get QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o').then((out) => {
44+
expect(out).to.be.eql(
45+
'Saving file(s) to QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
46+
)
47+
48+
const file = path.join(process.cwd(), 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o')
49+
expect(
50+
fs.readFileSync(file).toString()
51+
).to.be.eql(
52+
'hello world\n'
53+
)
54+
55+
fs.unlinkSync(file)
56+
})
57+
})
58+
3659
it('add', () => {
3760
return ipfs('files add src/init-files/init-docs/readme').then((out) => {
3861
expect(out).to.be.eql(
@@ -41,6 +64,14 @@ describe('files', () => {
4164
})
4265
})
4366

67+
it('add alias', () => {
68+
return ipfs('add src/init-files/init-docs/readme').then((out) => {
69+
expect(out).to.be.eql(
70+
'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme'
71+
)
72+
})
73+
})
74+
4475
it('add recursively', () => {
4576
return ipfs('files add -r src/init-files/init-docs').then((out) => {
4677
expect(out).to.be.eql([

0 commit comments

Comments
 (0)