feat(appium): Print the list of available extension scripts if no script name is provided (#19539)

This commit is contained in:
Mykola Mokhnach
2023-12-20 14:09:48 +01:00
committed by GitHub
parent a30286b6e7
commit dc2cedfecd
4 changed files with 42 additions and 6 deletions

View File

@@ -45,6 +45,10 @@ on:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
prepare_matrix:
runs-on: ubuntu-latest

View File

@@ -245,10 +245,12 @@ function makeRunArgs(type) {
['scriptName'],
{
default: null,
nargs: '?',
type: 'str',
help:
`Name of the script to run from the ${type}. The script name must be a key ` +
`inside the "appium.scripts" field inside the ${type}'s "package.json" file`,
`inside the "appium.scripts" field inside the ${type}'s "package.json" file. ` +
`If not provided then all available script names are going to be listed.`,
},
],
]);

View File

@@ -810,6 +810,24 @@ class ExtensionCliCommand {
);
}
if (!scriptName) {
const allScripts = _.toPairs(extScripts);
const root = this.config.getInstallPath(installSpec);
const existingScripts = await B.filter(
allScripts,
async ([, p]) => await fs.exists(path.join(root, p))
);
if (_.isEmpty(existingScripts)) {
this.log.info(`The ${this.type} named '${installSpec}' does not contain any scripts`);
} else {
this.log.info(`The ${this.type} named '${installSpec}' contains ` +
`${util.pluralize('script', existingScripts.length, true)}:`);
existingScripts.forEach(([name]) => this.log.info(` - ${name}`));
}
this.log.ok(`Successfully retrieved the list of scripts`.green);
return {};
}
if (!(scriptName in /** @type {Record<string,string>} */ (extScripts))) {
throw this._createFatalError(
`The ${this.type} named '${installSpec}' does not support the script: '${scriptName}'`
@@ -955,7 +973,8 @@ export {ExtensionCliCommand as ExtensionCommand};
* Options for {@linkcode ExtensionCliCommand._run}.
* @typedef RunOptions
* @property {string} installSpec - name of the extension to run a script from
* @property {string} scriptName - name of the script to run
* @property {string} [scriptName] - name of the script to run. If not provided
* then all available script names will be printed
* @property {string[]} [extraArgs] - arguments to pass to the script
* @property {boolean} [bufferOutput] - if true, will buffer the output of the script and return it
*/

View File

@@ -1,3 +1,4 @@
import _ from 'lodash';
import {DRIVER_TYPE, PLUGIN_TYPE} from '../../lib/constants';
import {getParser} from '../../lib/cli/parser';
import {INSTALL_TYPES} from '../../lib/extension/extension-config';
@@ -349,8 +350,13 @@ describe('parser', function () {
it('should not allow an empty driver argument list', function () {
(() => p.parseArgs([DRIVER_TYPE, 'run'])).should.throw();
});
it('should not allow no driver scriptName', function () {
(() => p.parseArgs([DRIVER_TYPE, 'run', 'foo'])).should.throw();
it('should allow no driver scriptName', function () {
const args = p.parseArgs([DRIVER_TYPE, 'run', 'foo']);
args.subcommand.should.eql(DRIVER_TYPE);
args.driverCommand.should.eql('run');
args.driver.should.eql('foo');
_.isNull(args.scriptName).should.be.true;
args.json.should.eql(false);
});
it('should take a driverName and scriptName to run', function () {
const args = p.parseArgs([DRIVER_TYPE, 'run', 'foo', 'bar']);
@@ -367,8 +373,13 @@ describe('parser', function () {
it('should not allow an empty plugin argument list', function () {
(() => p.parseArgs([PLUGIN_TYPE, 'run'])).should.throw();
});
it('should not allow no plugin scriptName', function () {
(() => p.parseArgs([PLUGIN_TYPE, 'run', 'foo'])).should.throw();
it('should allow no plugin scriptName', function () {
const args = p.parseArgs([PLUGIN_TYPE, 'run', 'foo']);
args.subcommand.should.eql(PLUGIN_TYPE);
args.pluginCommand.should.eql('run');
args.plugin.should.eql('foo');
_.isNull(args.scriptName).should.be.true;
args.json.should.eql(false);
});
it('should take a pluginName and scriptName to run', function () {
const args = p.parseArgs([PLUGIN_TYPE, 'run', 'foo', 'bar']);