Comparing version 0.1.3 to 1.0.0
145
bin/cmd.js
@@ -10,4 +10,9 @@ #!/usr/bin/env node | ||
var through = require('through'); | ||
var editor = require('editor'); | ||
var os = require('os'); | ||
var tmpdir = (os.tmpdir || os.tmpDir)(); | ||
var argv = minimist(process.argv.slice(2)); | ||
var argv = minimist(process.argv.slice(2), { | ||
alias: { m: 'message', v: 'verbose' } | ||
}); | ||
var HOME = process.env.HOME || process.env.USERPROFILE; | ||
@@ -37,2 +42,3 @@ var datadir = argv.d || path.join(HOME, '.clocker'); | ||
s.once('data', function (row) { | ||
if (argv.message) row.value.message = argv.message; | ||
row.value.end = strftime('%F %T', d); | ||
@@ -133,2 +139,10 @@ db.put(row.key, row.value, error); | ||
); | ||
if (argv.verbose && row.value.message) { | ||
var lines = row.value.message.split('\n'); | ||
console.log(); | ||
lines.forEach(function (line) { | ||
console.log(' ' + line); | ||
}); | ||
console.log(); | ||
} | ||
})); | ||
@@ -147,44 +161,41 @@ } | ||
} | ||
else if (argv._[0] === 'adjust') { | ||
if (argv._.length < 4) { | ||
return error('clocker adjust STAMP {start|end} STAMP'); | ||
else if (argv._[0] === 'set') { | ||
if (argv._.length < 3) { | ||
return error('clocker set STAMP KEY VALUE'); | ||
} | ||
var key = getKey(argv._[1]); | ||
var k = argv._[2]; | ||
var stamp = argv._[1]; | ||
var prop = argv._[2]; | ||
var value = argv._.slice(3).join(' '); | ||
set(stamp, prop, value); | ||
} | ||
else if (argv._[0] === 'edit') { | ||
var stamp = argv._[1]; | ||
var key = getKey(stamp); | ||
var prop = argv._[2]; | ||
if (k === 'end') { | ||
db.get(key, function (err, row) { | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
var src = JSON.stringify(prop ? row[prop] : row, null, 2); | ||
edit(src, function (err, src_) { | ||
if (err) return error(err); | ||
row[k] = updateDate(value, row[k]); | ||
db.put(key, row, error); | ||
if (prop) { | ||
row[prop] = src_; | ||
return set(stamp, prop, row); | ||
} | ||
row = JSON.parse(src_); | ||
try { var x = JSON.parse(src_) } | ||
catch (err) { | ||
return error('error parsing json'); | ||
} | ||
db.put(key, x, function (err) { | ||
if (err) return error(err); | ||
if (!x || typeof x !== 'object') { | ||
return error('not an object: ' + x); | ||
} | ||
if (x.type !== row.type) { | ||
set(stamp, 'type', x.type, row.type); | ||
} | ||
}); | ||
}); | ||
} | ||
else if (k === 'start') { | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
var newKey = 'time!' + updateDate(value, key.split('!')[1]); | ||
db.batch([ | ||
{ type: 'put', key: newKey, value: row }, | ||
{ type: 'del', key: key } | ||
], error); | ||
}); | ||
} | ||
else return error('clocker adjust STAMP {start|end} STAMP'); | ||
} | ||
else if (argv._[0] === 'move') { | ||
if (argv._.length < 2) { | ||
return error('clocker move STAMP type'); | ||
} | ||
var key = getKey(argv._[1]); | ||
var target = argv._[2]; | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
var prevType = row.type; | ||
row.type = target; | ||
db.batch([ | ||
prevType && { type: 'del', key: prevType }, | ||
{ type: 'put', key: key, value: row } | ||
].filter(Boolean), error); | ||
}); | ||
@@ -194,2 +205,18 @@ } | ||
function edit (src, cb) { | ||
var file = path.join(tmpdir, 'clocker-' + Math.random()); | ||
fs.writeFile(file, src || '', function (err) { | ||
if (err) error(err) | ||
else editor(file, function (code, sig) { | ||
if (code !== 0) { | ||
return error('non-zero exit code from $EDITOR'); | ||
} | ||
fs.readFile(file, function (err, src) { | ||
if (err) error(err) | ||
else cb(null, src) | ||
}); | ||
}); | ||
}); | ||
} | ||
function usage (code) { | ||
@@ -215,2 +242,44 @@ var rs = fs.createReadStream(__dirname + '/usage.txt'); | ||
function set (stamp, prop, value, originalValue) { | ||
var key = getKey(stamp); | ||
if (prop === 'end') { | ||
db.get(prop, function (err, row) { | ||
if (err) return error(err); | ||
row[prop] = updateDate(value, originalValue || row[prop]); | ||
db.put(key, row, error); | ||
}); | ||
} | ||
else if (prop === 'start') { | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
var newKey = 'time!' + updateDate(value, key.split('!')[1]); | ||
db.batch([ | ||
{ type: 'put', key: newKey, value: row }, | ||
{ type: 'del', key: key } | ||
], error); | ||
}); | ||
} | ||
else if (prop === 'type') { | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
var prevType = originalValue || row.type; | ||
row.type = value; | ||
db.batch([ | ||
prevType && { type: 'del', key: prevType }, | ||
{ type: 'put', key: key, value: row } | ||
].filter(Boolean), error); | ||
}); | ||
} | ||
else { | ||
db.get(key, function (err, row) { | ||
if (err) return error(err); | ||
if (value === '') delete row[prop]; | ||
else row[prop] = value; | ||
db.put(key, row, error); | ||
}); | ||
} | ||
} | ||
function error (err) { | ||
@@ -217,0 +286,0 @@ if (!err) return; |
@@ -15,4 +15,5 @@ usage: | ||
clocker list | ||
clocker list {-v} | ||
Show hourly data with STAMPS on the leftmost column. | ||
In verbose mode (-v), also show clocked messages. | ||
@@ -25,7 +26,8 @@ clocker get STAMP | ||
clocker adjust STAMP {start|end} DATE | ||
Adjust the start or end DATE at STAMP. | ||
clocker set STAMP KEY VALUE | ||
Adjust time stamp boundaries or other properties. | ||
clocker move STAMP TYPE | ||
Change the TYPE at STAMP. | ||
clocker edit STAMP {KEY} | ||
Launch $EDITOR to edit the record at STAMP. | ||
Optionally edit a single KEY. | ||
{ | ||
"name": "clocker", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "track project hours", | ||
@@ -14,3 +14,4 @@ "bin": { | ||
"sprintf": "~0.1.3", | ||
"through": "~2.3.4" | ||
"through": "~2.3.4", | ||
"editor": "~0.1.0" | ||
}, | ||
@@ -17,0 +18,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13898
282
0
116
7
+ Addededitor@~0.1.0
+ Addededitor@0.1.0(transitive)