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

Commit

Permalink
fix(cli): self host cmds listing
Browse files Browse the repository at this point in the history
Fixes Node.js 6 compat
  • Loading branch information
dignifiedquire committed May 3, 2016
1 parent 1251dea commit a415dc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: node_js
node_js:
- 4
- 5
- stable

# Make sure we have new NPM.
before_install:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"bs58": "^3.0.0",
"debug": "^2.2.0",
"fs-blob-store": "^5.2.1",
"glob": "^7.0.3",
"hapi": "^13.3.0",
"ipfs-api": "^3.0.1",
"ipfs-block": "^0.3.0",
Expand Down
25 changes: 15 additions & 10 deletions src/cli/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

const Command = require('ronin').Command
const path = require('path')
const ronin = require('ronin')
const glob = require('glob').sync

module.exports = Command.extend({
desc: 'List all available commands',

run: (name) => {
const cli = ronin(path.resolve(__dirname, '..'))
run (name) {
const basePath = path.resolve(__dirname, '..')

cli.setupCommands()
// modeled after https://github.com/vdemedes/ronin/blob/master/lib/program.js#L78
const files = glob(path.join(basePath, 'commands', '**', '*.js'))
const cmds = files.map((p) => {
return p.replace(/\//g, path.sep)
.replace(/^./, ($1) => $1.toUpperCase())
.replace(path.join(basePath, 'commands'), '')
.replace(path.sep, '')
.split(path.sep)
.join(' ')
.replace('.js', '')
}).sort().map((cmd) => `ipfs ${cmd}`)

const commands = ['']
.concat(Object.keys(cli.commands))
.map((command) => 'ipfs ' + command)
.join('\n')

console.log(commands)
console.log(['ipfs'].concat(cmds).join('\n'))
}
})

0 comments on commit a415dc1

Please sign in to comment.