Skip to content

Commit d0f7cbd

Browse files
committed
Merge branch 'dev'
2 parents 6b3b0de + c1d4bf7 commit d0f7cbd

File tree

12 files changed

+281
-20
lines changed

12 files changed

+281
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ The main usage of the program:
8282
removeTags|rmt [index] [tags...] Remove one or more tags from a Task
8383
renameList|mvl [oldName] [newName] Rename a List
8484
reset Reset cached task indices
85+
setUrl|su [index] [url] Set the URL of a Task
8586
tags|t Display all tags
8687
uncomp|unc [indices...] Mark one or more Tasks as not complete
88+
url [options] [index...] Display the associated URL of a Task
8789
whoami Display RTM user information
8890
overdue Display incomplete tasks that are overdue
8991
```

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"3": "cyan"
2121
},
2222
"completed": "dim",
23-
"notes": "reset",
23+
"notes": "yellow",
24+
"url": "yellow",
2425
"tags": "magenta",
2526
"due": "green"
2627
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
"copy-paste": "^1.3.0",
3838
"dateformat": "^3.0.2",
3939
"deepmerge": "^2.0.1",
40+
"opn": "^5.4.0",
4041
"ora": "^1.3.0",
41-
"rtm-api": "^1.0.2",
42+
"rtm-api": "^1.3.0",
4243
"window-size": "^1.1.0"
4344
},
4445
"devDependencies": {

src/cli.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ function setup() {
7676
}
7777
});
7878

79+
// Error on Unknown Command
80+
program.on('command:*', function () {
81+
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
82+
process.exit(1);
83+
});
84+
7985
// Add Program Commands
8086
parseCommands();
8187

@@ -403,23 +409,17 @@ function parseAliases() {
403409
*/
404410
function start() {
405411

406-
// Parse the process arguments
407-
program.parse(process.argv);
408-
409-
// Get parsed command
410-
let command = global._program.args[global._program.args.length-1];
411-
412-
// Start interactive mode if no command
413-
if ( command === undefined ) {
412+
// Start interactive mode
413+
if ( process.argv.length <= 2 ) {
414414
startInteractive();
415415
}
416416

417-
// Unknown Command
418-
else if ( typeof command === 'string' ) {
419-
log.spinner.error('ERROR: Unknown Command');
420-
program.help();
417+
// Parse the process arguments
418+
else {
419+
program.parse(process.argv);
421420
}
422421

422+
423423
}
424424

425425

src/cmd/add.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ function _processFinished(count, max) {
8282
* @private
8383
*/
8484
function _parseTask(task) {
85-
task = task.replace(/p:/g, "!");
86-
task = task.replace(/l:/g, "#");
87-
task = task.replace(/t:/g, "#");
88-
task = task.replace(/due:/g, "^");
85+
task = task.replace(/(\s+)p:([0-4]{1})($|[\s\r\n]+)/, " !$2$3").trim();
86+
task = task.replace(/(\s+)l:([\w\d]+)/, " #$2").trim();
87+
task = task.replace(/(\s+)t:([\w\d]+)/g, " #$2").trim();
88+
task = task.replace(/(\s+)due:([\w\d]+)/, " ^$2").trim();
8989
return task;
9090
}
9191

src/cmd/ls.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ function action(args, env) {
9494
// Add the Task Name
9595
log.style(task.name, namestyle);
9696

97+
// Print URL Indicator
98+
let urlstyle = task.isCompleted ? styles.completed : styles.url;
99+
if ( task.url !== undefined ) {
100+
log.style('+', urlstyle);
101+
}
102+
97103
// Print Note Indicators
98104
let notestyle = task.isCompleted ? styles.completed : styles.notes;
99105
for ( let i = 0; i < task.notes.length; i++ ) {

src/cmd/lsd.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ function action(args, env) {
109109
log.style(' ');
110110
log.style(task.name, priStyle);
111111

112+
// Print URL Indicator
113+
let urlstyle = task.isCompleted ? styles.completed : styles.url;
114+
if ( task.url !== undefined ) {
115+
log.style('+', urlstyle);
116+
}
117+
112118
// Print Note Indicators
113119
let notestyle = task.isCompleted ? styles.completed : styles.notes;
114120
for ( let i = 0; i < task.notes.length; i++ ) {

src/cmd/lsp.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ function action(args, env) {
8383
log.style(' ');
8484
log.style(task.name, priStyle);
8585

86+
// Print URL Indicator
87+
let urlstyle = task.isCompleted ? styles.completed : styles.url;
88+
if ( task.url !== undefined ) {
89+
log.style('+', urlstyle);
90+
}
91+
8692
// Print Note Indicators
8793
let notestyle = task.isCompleted ? styles.completed : styles.notes;
8894
for ( let i = 0; i < task.notes.length; i++ ) {

src/cmd/reset.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const log = require('../utils/log.js');
44
const config = require('../utils/config.js');
5+
const parseFilter = require('../utils/filter.js');
56
const finish = require('../utils/finish.js');
67

78

@@ -14,7 +15,7 @@ function action(args, env) {
1415
log.spinner.start("Clearing Task Index Cache...");
1516
user.clearTaskIndexCache();
1617
log.spinner.start("Rebuilding Task Index Cache...");
17-
user.tasks.get(function(err) {
18+
user.tasks.get(parseFilter(), function(err) {
1819
if ( err ) {
1920
log.spinner.error("Could not rebuild Task Index Cache");
2021
}

src/cmd/setUrl.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict';
2+
3+
const log = require('../utils/log.js');
4+
const config = require('../utils/config.js');
5+
const prompt = require('../utils/prompt.js');
6+
const finish = require('../utils/finish.js');
7+
8+
9+
/**
10+
* This command displays a task url
11+
* @param args index
12+
* @param env
13+
*/
14+
function action(args, env) {
15+
16+
// Prompt for task
17+
if ( args.length < 1 ) {
18+
prompt('Task:', 'URL:', _promptFinished);
19+
}
20+
21+
// Use provided args
22+
else {
23+
_process(args[0], args[1]);
24+
}
25+
26+
}
27+
28+
29+
/**
30+
* Process the returned answers
31+
* @private
32+
*/
33+
function _promptFinished(answers) {
34+
for ( let i = 0; i < answers.length; i++ ) {
35+
let answer = answers[i];
36+
_process(answer[0], answer[1],i+1, answers.length);
37+
}
38+
}
39+
40+
41+
/**
42+
* Process the request
43+
* @private
44+
*/
45+
function _process(index, url, count=1, max=1) {
46+
47+
// Make sure URL starts with http
48+
if ( url === undefined || url === "" || url === " " ) {
49+
url = "";
50+
}
51+
else if ( ! (url.startsWith("http://") || url.startsWith("https://")) ) {
52+
url = "http://" + url;
53+
}
54+
55+
// Display info
56+
log.spinner.start("Updating Task(s)...");
57+
58+
// Get User
59+
config.user(function(user) {
60+
61+
// Parse arguments
62+
index = parseInt(index.trim());
63+
64+
// Set URL
65+
user.tasks.setURL(index, url, function(err) {
66+
if ( err ) {
67+
log.spinner.error("Could not set URL for Task #" + index + " (" + err.msg + ")");
68+
}
69+
_processFinished(count, max);
70+
});
71+
72+
});
73+
74+
}
75+
76+
/**
77+
* Request Callback
78+
* @private
79+
*/
80+
function _processFinished(count, max) {
81+
log.spinner.start("Updating Task [" + count + "/" + max + "]...");
82+
83+
// All tasks returned...
84+
if ( count === max ) {
85+
log.spinner.stop();
86+
return finish();
87+
}
88+
89+
90+
}
91+
92+
93+
module.exports = {
94+
command: 'setUrl [index] [url]',
95+
alias: 'su',
96+
description: 'Set the URL of a Task',
97+
action: action
98+
};

0 commit comments

Comments
 (0)