diff --git a/packages/xo-cli/README.md b/packages/xo-cli/README.md index b415a61ff..49fcd65e4 100644 --- a/packages/xo-cli/README.md +++ b/packages/xo-cli/README.md @@ -22,9 +22,11 @@ Usage: xo-cli --register [] [] [] Registers the XO instance to use. - xo-cli --list-commands [--json] + xo-cli --list-commands [--json] []... Returns the list of available commands on the current XO instance. + The patterns can be used to filter on command names. + xo-cli --list-objects [=]... Returns a list of XO objects. @@ -62,6 +64,12 @@ all VM templates: > xo-cli --list-commands ``` +Commands can be filtered using patterns: + +``` +> xo-cli --list-commands '{user,group}.*' +``` + #### Execute a command The same syntax is used for all commands: `xo-cli ] [] [] Registers the XO instance to use. - $name --list-commands [--json] + $name --list-commands [--json] []... Returns the list of available commands on the current XO instance. + The patterns can be used to filter on command names. + $name --list-objects [=]... Returns a list of XO objects. @@ -197,7 +201,21 @@ function listCommands (args) { return connect().then(function getMethodsInfo (xo) { return xo.call('system.getMethodsInfo') }).then(function formatMethodsInfo (methods) { - if (args.indexOf('--json') !== -1) { + var json = false + var patterns = [] + forEach(args, function (arg) { + if (arg === -'--json') { + json = true + } + + patterns.push(arg) + }) + + if (patterns.length) { + methods = pick(methods, micromatch(Object.keys(methods), patterns)) + } + + if (json) { return methods } diff --git a/packages/xo-cli/package.json b/packages/xo-cli/package.json index 68eb02663..e2762cd63 100644 --- a/packages/xo-cli/package.json +++ b/packages/xo-cli/package.json @@ -38,6 +38,8 @@ "lodash.isobject": "^3.0.2", "lodash.keys": "^3.1.2", "lodash.pairs": "^3.0.1", + "lodash.pick": "^3.1.0", + "micromatch": "^2.2.0", "mkdirp": "^0.5.0", "multiline": "^1.0.2", "nice-pipe": "0.0.0",