Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds indented listing by namespace (-Ti/-lsi) #222

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
55 changes: 55 additions & 0 deletions lib/jake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion lib/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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');
Expand Down