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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Options:
## Documentation
For more information please visit the official <a href="http://cli.codefresh.io" target="_blank">CLI documentation</a> site.


7 changes: 7 additions & 0 deletions codefresh-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ version: '1.0'

steps:

main_clone:
title: 'Cloning main repository...'
type: git-clone
repo: codefresh-io/cli
revision: ${{CF_BRANCH}}
git: cf_github

fail_if_not_master:
title: "Validate running on master branch"
image: codefresh/build-cli
Expand Down
7 changes: 7 additions & 0 deletions codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ version: "1.0"

steps:

main_clone:
title: 'Cloning main repository...'
type: git-clone
repo: codefresh-io/cli
revision: ${{CF_BRANCH}}
git: cf_github

install_dependencies:
title: 'Installing testing dependencies'
image: codefresh/node-tester-image:8.8.0
Expand Down
13 changes: 3 additions & 10 deletions lib/interface/cli/commad-line-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const PROCESS_ARGV = require('yargs-parser')(process.argv);
async function startCommandLine() {
const cliConfig = configManager.config();

let files;
let config;

const configOptions = {
configPath: PROCESS_ARGV.cfconfig,
spec: { json: openapi },
Expand All @@ -30,13 +27,9 @@ async function startCommandLine() {
}, cliConfig.request),
};

await Promise.all([
recursive(path.resolve(__dirname, 'commands')).then((result) => {
files = result;
}),
Config.load(configOptions).then((result) => {
config = result;
}),
const [files, config] = await Promise.all([
recursive(path.resolve(__dirname, 'commands')),
Config.load(configOptions),
]);

sdk.configure(config);
Expand Down
5 changes: 2 additions & 3 deletions lib/interface/cli/commands/helm/repo/create.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const command = new Command({
return yargs;
},
handler: async (argv) => {
if (!argv.name) {
throw new Error('Repo name must be provided');
}
if (!argv.name) throw new Error('Repo name must be provided');

const data = {
name: argv.name,
Expand All @@ -43,5 +41,6 @@ const command = new Command({
},
});


module.exports = command;

18 changes: 17 additions & 1 deletion lib/interface/cli/commands/root/root.sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ let deleteCmd = require('./delete.cmd');
let versionCmd = require('./version.cmd');
let approveCmd = require('../workflow/approve.cmd');
let denyCmd = require('../workflow/approve.cmd');
let validateCmd = require('./validate.cmd');

createCmd.requiresAuthentication = false;
replaceCmd.requiresAuthentication = false;
deleteCmd.requiresAuthentication = false;
versionCmd.requiresAuthentication = false;
approveCmd.requiresAuthentication = false;
denyCmd.requiresAuthentication = false;
validateCmd.requiresAuthentication = false;

createCmd = createCmd.toCommand();
replaceCmd = replaceCmd.toCommand();
deleteCmd = deleteCmd.toCommand();
versionCmd = versionCmd.toCommand();
approveCmd = approveCmd.toCommand();
denyCmd = denyCmd.toCommand();

validateCmd = validateCmd.toCommand();

jest.mock('../../helpers/validation', () => { // eslint-disable-line
return {
validatePipelineSpec: () => ({ valid: true }),
validatePipelineYaml: () => ({ valid: false }),
};
});

Expand Down Expand Up @@ -133,6 +136,19 @@ describe('root commands', () => {
});
});

describe('validate', () => {
describe('Not valid yaml ', async () => {
it('should throw error for not valid file', async () => {
const argv = {
filenames: ['./codefresh.yml'],
};
const result = await validateCmd.handler(argv)
.catch(err => err);
expect(result instanceof Error).toBe(true);
});
});
});

describe('version', () => {
describe('api', async () => {
it('should handle getting version', async () => {
Expand Down
29 changes: 21 additions & 8 deletions lib/interface/cli/commands/root/validate.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ const { pathExists, watchFile } = require('../../helpers/general');

const VALID_MESSAGE = Style.green('Yaml is valid!');

function _getResultMessage(result = {}) {
return result.valid
? VALID_MESSAGE
: `${Style.red(result.message)}\n`;
}

function printResult(result) {
console.log(result.valid ? VALID_MESSAGE : Style.red(result.message), '\n');
console.log(_getResultMessage(result));
}

function _handleResult(result = {}, attach) {
if (result.valid || attach) {
return printResult(result);
}
throw Error(_getResultMessage(result));
}

const validateCmd = new Command({
Expand Down Expand Up @@ -41,8 +54,7 @@ const validateCmd = new Command({
filenames = filenames.map(f => path.resolve(process.cwd(), f));

if (_.isEmpty(filenames)) {
console.log('No filename provided!');
return;
return console.log('No filename provided!');
}

const checkPromises = filenames.map((filename) => {
Expand All @@ -66,10 +78,11 @@ const validateCmd = new Command({
return;
}

filenames.forEach(f => validatePipelineYaml(f).then((result) => {
console.log(`Validation result for ${f}:`);
printResult(result);
}));
filenames.forEach(f => validatePipelineYaml(f)
.then((result) => {
console.log(`Validation result for ${f}:`);
printResult(result);
}));
return;
}

Expand All @@ -85,7 +98,7 @@ const validateCmd = new Command({

// even with --attach option validates file for first time
const result = await validatePipelineYaml(filename);
printResult(result);
_handleResult(result, attach);
},
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.36.0",
"version": "0.36.2",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down