Skip to content
Merged
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
14 changes: 14 additions & 0 deletions lib/interface/cli/commands/root/get.cmd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Command = require('../../Command');
const { crudFilenameOption } = require('../../helpers/general');
const DEFAULTS = require('../../defaults');


const get = new Command({
Expand All @@ -24,8 +25,21 @@ const get = new Command({
describe: 'Output format',
alias: 'o',
choices: ['json', 'yaml', 'wide', 'name'],
})
.option('watch', {
describe: 'Watching updates to a particular resource',
alias: 'w',
type: Boolean,
default: false,
})
.option('watch_interval', {
describe: 'Interval time at watching mode (in seconds)',
})
.coerce('watch_interval', (watchInterval) => {
return Math.max(watchInterval * 1000 , DEFAULTS.WATCH_INTERVAL);
});


crudFilenameOption(yargs);

return yargs
Expand Down
1 change: 1 addition & 0 deletions lib/interface/cli/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const DEFAULTS = {
GET_LIMIT_RESULTS: 25,
GET_PAGINATED_PAGE: 1,
CODEFRESH_REGISTRIES: ['r.cfcr.io'],
WATCH_INTERVAL: 3000,
};

module.exports = DEFAULTS;
2 changes: 1 addition & 1 deletion lib/interface/cli/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const printError = (error) => {
const wrapHandler = (handler) => {
return async (argv) => {
try {
await handler(argv);
argv.watch ? setInterval(async () => { await handler(argv)}, argv.watch_interval) : await handler(argv);
} catch (err) {
printError(err);
process.exit(1);
Expand Down
19 changes: 11 additions & 8 deletions lib/interface/cli/helpers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const _ = require('lodash');
const columnify = require('columnify');
const yaml = require('js-yaml');
const logUpdate = require('log-update');

//i tried that this function will be dynamic (with the keys). it is also possible to add an array with all the fields if you think it better
const _printArrayTable = (data) => {
Expand All @@ -19,7 +20,7 @@ const _printArrayTable = (data) => {
res.push(obj);
});
const columns = columnify(res);
console.log(columns);
logUpdate(columns);
};

const _printSingleTable = (info) => {
Expand All @@ -31,20 +32,21 @@ const _printSingleTable = (info) => {
});
res.push(obj);
const columns = columnify(res);
console.log(columns);
logUpdate(columns);
};


const specifyOutputForSingle = (type, enitity) => {
logUpdate.clear();
switch (type) {
case 'json':
console.log(enitity.toJson());
logUpdate(enitity.toJson());
break;
case 'yaml':
console.log(enitity.toYaml());
logUpdate(enitity.toYaml());
break;
case 'name':
console.log(enitity.toName());
logUpdate(enitity.toName());
break;
case 'wide':
_printSingleTable(enitity.toWide());
Expand All @@ -56,13 +58,14 @@ const specifyOutputForSingle = (type, enitity) => {


const specifyOutputForArray = (type, enitities) => {
logUpdate.clear();
switch (type) {
case 'json':
const jsonArray = [];
_.forEach(enitities, (entity) => {
jsonArray.push(entity.info);
});
console.log(JSON.stringify(jsonArray, null, '\t'));
logUpdate(JSON.stringify(jsonArray, null, '\t'));
break;
case 'yaml':
let yamlArray = {
Expand All @@ -71,11 +74,11 @@ const specifyOutputForArray = (type, enitities) => {
_.forEach(enitities, (entity) => {
yamlArray.items.push(entity.info);
});
console.log(yaml.safeDump(yamlArray));
logUpdate(yaml.safeDump(yamlArray));
break;
case 'name':
_.forEach(enitities, (entity) => {
console.log(entity.toName());
logUpdate(entity.toName());
});
break;
case 'wide':
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.2.9",
"version": "0.3.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down Expand Up @@ -29,6 +29,7 @@
"jsonwebtoken": "^8.1.0",
"kefir": "^3.8.0",
"lodash": "^4.17.4",
"log-update": "^2.3.0",
"mkdirp": "^0.5.1",
"moment": "^2.19.4",
"prettyjson": "^1.2.1",
Expand Down
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ cli-cursor@^1.0.1:
dependencies:
restore-cursor "^1.0.1"

cli-cursor@^2.1.0:
cli-cursor@^2.0.0, cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
dependencies:
Expand Down Expand Up @@ -2427,6 +2427,14 @@ lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

log-update@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/log-update/-/log-update-2.3.0.tgz#88328fd7d1ce7938b29283746f0b1bc126b24708"
dependencies:
ansi-escapes "^3.0.0"
cli-cursor "^2.0.0"
wrap-ansi "^3.0.1"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -3871,6 +3879,13 @@ wrap-ansi@^2.0.0:
string-width "^1.0.1"
strip-ansi "^3.0.1"

wrap-ansi@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-3.0.1.tgz#288a04d87eda5c286e060dfe8f135ce8d007f8ba"
dependencies:
string-width "^2.1.1"
strip-ansi "^4.0.0"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
Expand Down