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

fix(cli): self host cmds listing #188

Merged
merged 1 commit into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))
}
})