-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project-update): adds auto-completion for argument and project ids
- Loading branch information
Showing
6 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const config = require('./../../../config.js'); | ||
const miteApi = require('./../../mite-api')(config.get()); | ||
|
||
/** | ||
* 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 ({ prev, line, word }) => { | ||
switch(prev) { | ||
case '--archived': | ||
return ['yes', 'no']; | ||
} | ||
// return a list of project ids | ||
return miteApi.getProjects({ archived: false }) | ||
.then(projects => projects.map(c => ({ | ||
name: String(c.id), | ||
description: c.name | ||
}))) | ||
.then(projects => { | ||
return projects.concat([ | ||
line.indexOf('--archived') === -1 ? { | ||
name: '--archived', | ||
description: 'archive or unarchive a project', | ||
} : undefined, | ||
word < 4 ? { | ||
name: '--help', | ||
description: 'show help message', | ||
} : undefined, | ||
]); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const projectUpdateCompletion = require('./project-update'); | ||
|
||
/** | ||
* 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 function ({ line }) { | ||
// check wheter the update sub-sub command is called and forward completion | ||
// to that command | ||
const thirdArg = line.split(/\s/).splice(2)[0]; | ||
switch (thirdArg) { | ||
case 'update': | ||
// forward auto-completion to sub-sub-command | ||
return projectUpdateCompletion.apply(projectUpdateCompletion, arguments); | ||
} | ||
return [ | ||
{ | ||
name: 'update', | ||
description: 'update a single project by it’s id', | ||
}, | ||
{ | ||
name: '--help', | ||
description: 'show help message', | ||
}, | ||
]; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters