diff --git a/README.md b/README.md index 8edf946a..3ef44300 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,9 @@ Add the directory of node.exe to the environment PATH variable. -T/ls --tasks Display the tasks (matching optional PATTERN) with descriptions, then exit. + + -Ti/lsi + --indent-tasks Display the tasks indented by namespace, then exit. ### Jakefile syntax @@ -656,6 +659,18 @@ Setting a value for -T/--tasks will filter the list by that value: The list displayed will be all tasks whose namespace/name contain the filter-string. +You can also use `-Ti/lsi` to print a list of tasks indented by namespace. + + $ jake -Ti + task default # This is the default task. + task asdf # This is the asdf task. + task concat.txt # File task, concating two files together + task failure # Failing task. + task lookup # Jake task lookup by name. + namespace foo + task bar # This the foo:bar task + task fonebone # This the foo:fonebone task + ## Breaking things up into multiple files Jake will automatically look for files with a .jake extension in a 'jakelib' diff --git a/lib/jake.js b/lib/jake.js index 59ceefb2..1e81de19 100644 --- a/lib/jake.js +++ b/lib/jake.js @@ -152,6 +152,61 @@ utils.mixin(jake, new (function () { } }; + this.showAllTaskDescriptionsIndented = function (f) { + var p + , namespace + , recursivePrint + , i + , filter = typeof f == 'string' ? f : null; + + // Recursively print the namespaces and tasks + recursivePrint = function (n, depth) { + // If depth is not passed it is 0 + depth = typeof depth !== 'undefined' ? depth : 0; + + // Print the spaces for the depth + var depthSpaces = '' + for (i = 0; i < depth; i++) { + depthSpaces = depthSpaces + ' ' + } + + // Print the namespace name + console.log(depthSpaces + '\033[36m' + 'namespace ' + '\033[32m' + n.name); + + // Print the namespace tasks + for (task in n.tasks) { + task = n.tasks[task]; + process.stdout.write(depthSpaces); + process.stdout.write('\033[36m' + ' ' + 'task ' + '\033[32m' + task.name); + process.stdout.write('\033[90m' + ' # ' + task.description + '\033[39m'); + process.stdout.write('\n'); + } + + // Do the recursive bit + if (n.childNamespaces) { + for (childNamespace in n.childNamespaces) { + recursivePrint(n.childNamespaces[childNamespace], depth + 1); + } + } + }; + + // Loop through the top level tasks and print them + for (p in jake.Task) { + task = jake.Task[p] + if (typeof task != "function") { + if (task.namespace.name == 'default') { + console.log('\033[36m' + 'task ' + '\033[32m' + task.name); + } + } + } + + // Loop through the toplevel namespaces and recursively print them + for (p in jake.defaultNamespace.childNamespaces) { + namespace = jake.defaultNamespace.childNamespaces[p] + recursivePrint(namespace); + } + }; + this.createTask = function () { var args = Array.prototype.slice.call(arguments) , arg diff --git a/lib/program.js b/lib/program.js index 6a800eca..680c1feb 100644 --- a/lib/program.js +++ b/lib/program.js @@ -55,6 +55,17 @@ optsReg = [ , abbr: 'ls' , preempts: true } +, { full: 'indent-tasks' + , abbr: 'Ti' + , preempts: true + , expectValue: false + } +// Alias lsi +, { full: 'indent-tasks' + , abbr: 'lsi' + , preempts: true + , expectValue: false + } , { full: 'trace' , abbr: 't' , preempts: false @@ -101,7 +112,8 @@ usage = '' + ' -C, --directory DIRECTORY Change to DIRECTORY before running tasks.\n' + ' -q, --quiet Do not log messages to standard output.\n' + ' -B, --always-make Unconditionally make all targets.\n' - + ' -T/ls, --tasks Display the tasks (matching optional PATTERN) with descriptions, then exit.\n' + + ' -T/ls, --tasks Display the tasks (matching optional PATTERN) with descriptions, then exit.\n' + + ' -Ti/lsi --indent-tasks Display the tasks indented by namespace, then exit.\n' + ' -J, --jakelibdir JAKELIBDIR Auto-import any .jake files in JAKELIBDIR. (default is \'jakelib\')\n' + ' -t, --trace Enable full backtrace.\n' + ' -h, --help Display this help message.\n' @@ -200,6 +212,11 @@ Program.prototype = new (function () { return jake.showAllTaskDescriptions(opts.tasks); } + // Run with `jake -Ti/lsi` to show tasks indented by namespace + if (opts['indent-tasks']) { + return jake.showAllTaskDescriptionsIndented(opts.tasks); + } + taskNames = this.taskNames; if (!(Array.isArray(taskNames) && taskNames.length)) { throw new Error('Please pass jake.runTasks an array of task-names');