Skip to content

Commit

Permalink
fix(cli): positional file arguments for deploy and publish not respec…
Browse files Browse the repository at this point in the history
…ted (#1091)

fixes #1090
  • Loading branch information
tripodsan authored Jul 18, 2019
1 parent b726da8 commit e139db5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ module.exports = function deploy() {
set executor(value) {
executor = value;
},
command: 'deploy',
command: 'deploy [files..]',
desc: 'Deploy packaged functions to Adobe I/O runtime',
builder: (yargs) => {
yargsOpenwhisk(yargs);
yargsFastly(yargs);
yargsBuild(yargs);
yargs
yargsBuild(yargs)
.option('auto', {
describe: 'Enable auto-deployment',
type: 'boolean',
Expand Down
6 changes: 2 additions & 4 deletions src/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ module.exports = function pack() {
set executor(value) {
executor = value;
},
command: 'package',
command: 'package [files..]',
desc: 'Create Adobe I/O runtime packages',
builder: (yargs) => {
yargsBuild(yargs);
// eslint-disable-next-line global-require
yargs
yargsBuild(yargs)
.option('force', {
describe: 'Forces creation of packages even if the sources are not modified.',
type: 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion src/yargs-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function commonArgs(yargs) {
type: 'string',
})
// allow for comma separated values
.coerce('files', value => (!Array.isArray(value) ? [value] : value).reduce((acc, curr) => {
.coerce('files', value => value.reduce((acc, curr) => {
acc.push(...curr.split(/\s*,\s*/));
return acc;
}, []));
Expand Down
24 changes: 24 additions & 0 deletions test/testDeployCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,28 @@ OpenWhisk Namespace is required`);
sinon.assert.calledWith(mockDeploy.withResolveGitRefService, 'helix-services/foobar');
sinon.assert.calledOnce(mockDeploy.run);
});

it('hlx deploy can set specify files', () => {
new CLI()
.withCommandExecutor('deploy', mockDeploy)
.run(['deploy',
'--files', 'lib/*.htl', 'index.htl',
'--wsk-auth', 'secret-key',
'--wsk-namespace', 'hlx',
]);
sinon.assert.calledWith(mockDeploy.withFiles, ['lib/*.htl', 'index.htl']);
sinon.assert.calledOnce(mockDeploy.run);
});

it('hlx deploy can set specify files without option', () => {
new CLI()
.withCommandExecutor('deploy', mockDeploy)
.run(['deploy',
'lib/*.htl', 'index.htl',
'--wsk-auth', 'secret-key',
'--wsk-namespace', 'hlx',
]);
sinon.assert.calledWith(mockDeploy.withFiles, ['lib/*.htl', 'index.htl']);
sinon.assert.calledOnce(mockDeploy.run);
});
});
25 changes: 25 additions & 0 deletions test/testPackageCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,29 @@ describe('hlx package', () => {
sinon.assert.calledWith(mockPackage.withMinify, true);
sinon.assert.calledOnce(mockPackage.run);
});

it('hlx package can set specify files', () => {
new CLI()
.withCommandExecutor('package', mockPackage)
.run(['package', '--files', 'lib/*.htl', 'index.htl']);
sinon.assert.calledWith(mockPackage.withFiles, ['lib/*.htl', 'index.htl']);
sinon.assert.calledOnce(mockPackage.run);
});

it('hlx package can set specify files without option', () => {
new CLI()
.withCommandExecutor('package', mockPackage)
.run(['package', 'lib/*.htl', 'index.htl']);
sinon.assert.calledWith(mockPackage.withFiles, ['lib/*.htl', 'index.htl']);
sinon.assert.calledOnce(mockPackage.run);
});

it('hlx package can set specify files without option and additional args', () => {
new CLI()
.withCommandExecutor('package', mockPackage)
.run(['package', 'lib/*.htl', 'index.htl', '--target', 'foo']);
sinon.assert.calledWith(mockPackage.withFiles, ['lib/*.htl', 'index.htl']);
sinon.assert.calledWith(mockPackage.withTarget, 'foo');
sinon.assert.calledOnce(mockPackage.run);
});
});

0 comments on commit e139db5

Please sign in to comment.