Skip to content

Commit

Permalink
feat(start): adds auto-completion which shows latest 5 entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia committed Apr 19, 2019
1 parent 26edb09 commit 25201d0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/lib/auto-complete/completions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const NOTE_MAX_LENGTH = (process.stdout.columns || 80) - 20;
* @param {string} env.line - the current complete input line in the cli
* @returns {Promise<Array<string>>}
*/
module.exports = async ({ line, words }) => {
module.exports = async ({ words }) => {
const defaults = [
(words < 3 ? {
name: '--help',
Expand Down
1 change: 1 addition & 0 deletions source/lib/auto-complete/completions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
project: require('./project'),
projects: require('./projects'),
services: require('./services'),
start: require('./start'),
unlock: require('./unlock'),
users: require('./users'),
};
44 changes: 44 additions & 0 deletions source/lib/auto-complete/completions/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
'use strict';

const config = require('./../../../config.js');
const miteApi = require('./../../mite-api')(config.get());

const NOTE_MAX_LENGTH = (process.stdout.columns || 80) - 20;

/**
* https://www.npmjs.com/package/tabtab#3-parsing-env
*
* @param {string} env.lastPartial - the characters entered in the current
* argument before hitting tabtab
* @param {string} env.prev - last given argument value, or previously
* completed value
* @param {string} env.words - the number of argument currently active
* @param {string} env.line - the current complete input line in the cli
* @returns {Promise<Array<string>>}
*/
module.exports = async ({ words }) => {
const defaults = [
(words < 3 ? {
name: '--help',
description: 'show help message'
} : undefined)
];

// try to find the latest entries created by the current user and propose the
// ids of these
return miteApi.getMyRecentTimeEntries()
.then(timeEntries => timeEntries.map(entry => {
let note = entry.note || '[no note]';
if (note.length > NOTE_MAX_LENGTH) {
note = note.substr(0, NOTE_MAX_LENGTH - 1) + '…';
}
return {
name: String(entry.id),
description: `${entry.date_at} ${note}`
};
}))
.then(options => {
return [].concat([], options, defaults);
});
};

0 comments on commit 25201d0

Please sign in to comment.