savory
Version:
A command-line interface for operating your Codefresh account
41 lines (38 loc) • 1.51 kB
JavaScript
const
fp = require('lodash/fp'),
moment = require('moment'),
{ middleware: apiMiddleware } = require('../../lib/api_client'),
{ errorFormatter, tableFormatter } = require('../style');
const
DEFAULT_API_RESULT_LIMIT = 25,
CHARS_PIPELINE_NAME = 35;
module.exports = {
command: ["list", "ls"],
describe: "Lists all pipelines in your account",
builder: (yargs)=> {
return yargs
.option('api-limit', {
type: "number",
default: DEFAULT_API_RESULT_LIMIT,
describe: "Limit the amount of results returned from the API"
});
},
handler: fp.pipe(apiMiddleware, ({ _httpClient, apiLimit })=> {
_httpClient('pipelines', { limit: apiLimit })
.then(
fp.pipe(
fp.get('docs'),
fp.map((pipeline)=> {
const [name, created, updated] = fp.at(["metadata.name", "metadata.created_at", "metadata.updated_at"], pipeline);
return [
fp.truncate({ length: CHARS_PIPELINE_NAME, omission: ".." }, name),
moment(created).fromNow(),
moment(updated).fromNow()
];
})
)
)
.then(fp.pipe(tableFormatter({ title: ["Name", "Created", "Updated"] }), console.log))
.catch(fp.pipe(errorFormatter, console.warn));
})
};