chore(deps): bump argparse from 1.0.10 to 2.0.1 (#14687)

Bumps [argparse](https://github.com/nodeca/argparse) from 1.0.10 to 2.0.1.
- [Release notes](https://github.com/nodeca/argparse/releases)
- [Changelog](https://github.com/nodeca/argparse/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/argparse/compare/1.0.10...2.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mykola Mokhnach <mokhnach@gmail.com>
This commit is contained in:
dependabot-preview[bot]
2020-09-02 22:01:20 +02:00
committed by GitHub
parent a88f51d70b
commit 163b34dc2f
10 changed files with 382 additions and 377 deletions

View File

@@ -70,20 +70,20 @@ gulp.task('docs', gulp.series(['transpile']), function parseDocs () {
const exampleArg = typeof arg[0][1] === 'undefined' ? arg[0][0] : arg[0][1];
const argOpts = arg[1];
// --keystore-path defaultValue contains a user-specific path,
// --keystore-path default contains a user-specific path,
// let's replace it with <user>/...
if (arg[0][0] === '--keystore-path') {
const userPath = process.env.HOME || process.env.USERPROFILE;
argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;');
argOpts.default = argOpts.default.replace(userPath, '&lt;user&gt;');
}
// handle empty objects
if (JSON.stringify(argOpts.defaultValue) === '{}') {
argOpts.defaultValue = '{}';
if (JSON.stringify(argOpts.default) === '{}') {
argOpts.default = '{}';
}
md += '|`' + argNames.join('`, `') + '`';
md += '|' + ((typeof argOpts.defaultValue === 'undefined') ? '' : argOpts.defaultValue);
md += '|' + ((typeof argOpts.default === 'undefined') ? '' : argOpts.default);
md += '|' + argOpts.help;
md += '|' + ((typeof argOpts.example === 'undefined') ? '' : '`' + exampleArg + ' ' + argOpts.example + '`');
md += '|\n';

View File

@@ -254,9 +254,7 @@ class AppiumDriver extends BaseDriver {
async getSessions () {
const sessions = await sessionsListGuard.acquire(AppiumDriver.name, () => this.sessions);
return _.toPairs(sessions)
.map(([id, driver]) => {
return {id, capabilities: driver.caps};
});
.map(([id, driver]) => ({id, capabilities: driver.caps}));
}
printNewSessionAnnouncement (driverName, driverVersion) {

77
lib/argsparse-actions.js Normal file
View File

@@ -0,0 +1,77 @@
import { Action } from 'argparse';
const DEFAULT_CAPS_ARG = '--default-capabilities';
class StoreDeprecatedAction extends Action {
constructor (options = {}) {
const opts = Object.assign({}, options);
let helpPrefix = '[DEPRECATED]';
if (opts.deprecated_for) {
helpPrefix = `[DEPRECATED, use ${opts.deprecated_for} instead]`;
delete opts.deprecated_for;
}
if (opts.help) {
opts.help = `${helpPrefix} - ${opts.help}`;
} else {
opts.help = helpPrefix;
}
super(opts);
}
call (parser, namespace, values) {
namespace[this.dest] = values;
}
}
class StoreDeprecatedTrueAction extends StoreDeprecatedAction {
constructor (options = {}) {
super(Object.assign({}, options, {const: true, nargs: 0}));
}
call (parser, namespace) {
namespace[this.dest] = this.const;
}
}
class StoreDeprecatedDefaultCapabilityAction extends StoreDeprecatedAction {
constructor (options = {}) {
super(Object.assign({}, options, {deprecated_for: DEFAULT_CAPS_ARG}));
}
_writeDefaultCap (namespace, value) {
namespace[this.dest] = value;
if (value === this.default) {
return;
}
if (!namespace.defaultCapabilities) {
namespace.defaultCapabilities = {};
}
namespace.defaultCapabilities[this.dest] = value;
}
call (parser, namespace, values) {
this._writeDefaultCap(namespace, values);
}
}
class StoreDeprecatedDefaultCapabilityTrueAction extends StoreDeprecatedDefaultCapabilityAction {
constructor (options = {}) {
super(Object.assign({}, options, {const: true, nargs: 0}));
}
call (parser, namespace) {
this._writeDefaultCap(namespace, this.const);
}
}
export {
StoreDeprecatedAction, StoreDeprecatedTrueAction,
StoreDeprecatedDefaultCapabilityAction, StoreDeprecatedDefaultCapabilityTrueAction,
DEFAULT_CAPS_ARG,
};

View File

@@ -6,6 +6,9 @@ import { exec } from 'teen_process';
import { rootDir } from './utils';
import logger from './logger';
import semver from 'semver';
import {
StoreDeprecatedDefaultCapabilityAction, DEFAULT_CAPS_ARG,
} from './argsparse-actions';
const npmPackage = require(path.resolve(rootDir, 'package.json'));
@@ -24,6 +27,11 @@ function getNodeVersion () {
return semver.coerce(process.version);
}
function isSubClass (candidateClass, superClass) {
return _.isFunction(superClass) && _.isFunction(candidateClass)
&& (candidateClass.prototype instanceof superClass || candidateClass === superClass);
}
async function updateBuildInfo (useGithubApiFallback = false) {
const sha = await getGitRev(useGithubApiFallback);
if (!sha) {
@@ -136,29 +144,29 @@ async function showConfig () {
}
function getNonDefaultArgs (parser, args) {
let nonDefaults = {};
for (let rawArg of parser.rawArgs) {
let arg = rawArg[1].dest;
if (args[arg] && args[arg] !== rawArg[1].defaultValue) {
nonDefaults[arg] = args[arg];
return parser.rawArgs.reduce((acc, [, {dest, default: defaultValue}]) => {
if (args[dest] && args[dest] !== defaultValue) {
acc[dest] = args[dest];
}
}
return nonDefaults;
return acc;
}, {});
}
function getDeprecatedArgs (parser, args) {
// go through the server command line arguments and figure
// out which of the ones used are deprecated
let deprecated = {};
for (let rawArg of parser.rawArgs) {
let arg = rawArg[1].dest;
let defaultValue = rawArg[1].defaultValue;
let isDeprecated = !!rawArg[1].deprecatedFor;
if (args[arg] && args[arg] !== defaultValue && isDeprecated) {
deprecated[rawArg[0]] = rawArg[1].deprecatedFor;
return parser.rawArgs.reduce((acc, [[name], {dest, default: defaultValue, action}]) => {
if (!args[dest] || args[dest] === defaultValue) {
return acc;
}
}
return deprecated;
if (action?.deprecated_for) {
acc[name] = action.deprecated_for;
} else if (isSubClass(action, StoreDeprecatedDefaultCapabilityAction)) {
acc[name] = DEFAULT_CAPS_ARG;
}
return acc;
}, {});
}
function checkValidPort (port, portName) {
@@ -197,7 +205,7 @@ function validateServerArgs (parser, args) {
bootstrapPort: checkValidPort,
chromedriverPort: checkValidPort,
robotPort: checkValidPort,
backendRetries: (r) => { return r >= 0; }
backendRetries: (r) => r >= 0,
};
const nonDefaultArgs = getNonDefaultArgs(parser, args);

View File

@@ -111,7 +111,7 @@ async function main (args = null) {
}
} else {
// otherwise parse from CLI
args = parser.parseArgs();
args = parser.parse_args();
}
await logsinkInit(args);
if (args.logFilters) {

File diff suppressed because it is too large Load Diff

View File

@@ -55,7 +55,7 @@
"appium-windows-driver": "1.x",
"appium-xcuitest-driver": "^3.22.0",
"appium-youiengine-driver": "^1.2.0",
"argparse": "^1.0.10",
"argparse": "^2.0.1",
"async-lock": "^1.0.0",
"asyncbox": "2.x",
"axios": "^0.20.0",

View File

@@ -203,7 +203,7 @@ describe('Config', function () {
beforeEach(function () {
// give all the defaults
for (let rawArg of parser.rawArgs) {
args[rawArg[1].dest] = rawArg[1].defaultValue;
args[rawArg[1].dest] = rawArg[1].default;
}
});
describe('getNonDefaultArgs', function () {
@@ -296,7 +296,7 @@ describe('Config', function () {
const defaultArgs = {};
// give all the defaults
for (let rawArg of parser.rawArgs) {
defaultArgs[rawArg[1].dest] = rawArg[1].defaultValue;
defaultArgs[rawArg[1].dest] = rawArg[1].default;
}
let args = {};
beforeEach(function () {

View File

@@ -82,7 +82,7 @@ describe('AppiumDriver', function () {
new FakeDriver(),
new FakeDriver(),
];
let mockFakeDrivers = _.map(fakeDrivers, (fd) => {return sinon.mock(fd);});
let mockFakeDrivers = _.map(fakeDrivers, (fd) => sinon.mock(fd));
mockFakeDrivers[0].expects('deleteSession')
.once();
mockFakeDrivers[1].expects('deleteSession')

View File

@@ -12,8 +12,8 @@ describe('Parser', function () {
let p = getParser();
p.debug = true; // throw instead of exit on error; pass as option instead?
it('should return an arg parser', function () {
should.exist(p.parseArgs);
p.parseArgs([]).should.have.property('port');
should.exist(p.parse_args);
p.parse_args([]).should.have.property('port');
});
it('should keep the raw server flags array', function () {
should.exist(p.rawArgs);
@@ -24,45 +24,45 @@ describe('Parser', function () {
}
});
it('should throw an error with unknown argument', function () {
(() => {p.parseArgs(['--apple']);}).should.throw();
(() => {p.parse_args(['--apple']);}).should.throw();
});
it('should parse default capabilities correctly from a string', function () {
let defaultCapabilities = {a: 'b'};
let args = p.parseArgs(['--default-capabilities', JSON.stringify(defaultCapabilities)]);
let args = p.parse_args(['--default-capabilities', JSON.stringify(defaultCapabilities)]);
args.defaultCapabilities.should.eql(defaultCapabilities);
});
it('should parse default capabilities correctly from a file', function () {
let defaultCapabilities = {a: 'b'};
let args = p.parseArgs(['--default-capabilities', 'test/fixtures/caps.json']);
let args = p.parse_args(['--default-capabilities', 'test/fixtures/caps.json']);
args.defaultCapabilities.should.eql(defaultCapabilities);
});
it('should throw an error with invalid arg to default capabilities', function () {
(() => {p.parseArgs(['-dc', '42']);}).should.throw();
(() => {p.parseArgs(['-dc', 'false']);}).should.throw();
(() => {p.parseArgs(['-dc', 'null']);}).should.throw();
(() => {p.parseArgs(['-dc', 'does/not/exist.json']);}).should.throw();
(() => {p.parse_args(['-dc', '42']);}).should.throw();
(() => {p.parse_args(['-dc', 'false']);}).should.throw();
(() => {p.parse_args(['-dc', 'null']);}).should.throw();
(() => {p.parse_args(['-dc', 'does/not/exist.json']);}).should.throw();
});
it('should parse args that are caps into default capabilities', function () {
let defaultCapabilities = {localizableStringsDir: '/my/dir'};
let args = p.parseArgs(['--localizable-strings-dir', '/my/dir']);
let args = p.parse_args(['--localizable-strings-dir', '/my/dir']);
args.defaultCapabilities.should.eql(defaultCapabilities);
});
it('should parse --allow-insecure correctly', function () {
p.parseArgs([]).allowInsecure.should.eql([]);
p.parseArgs(['--allow-insecure', '']).allowInsecure.should.eql([]);
p.parseArgs(['--allow-insecure', 'foo']).allowInsecure.should.eql(['foo']);
p.parseArgs(['--allow-insecure', 'foo,bar']).allowInsecure.should.eql(['foo', 'bar']);
p.parseArgs(['--allow-insecure', 'foo ,bar']).allowInsecure.should.eql(['foo', 'bar']);
p.parse_args([]).allowInsecure.should.eql([]);
p.parse_args(['--allow-insecure', '']).allowInsecure.should.eql([]);
p.parse_args(['--allow-insecure', 'foo']).allowInsecure.should.eql(['foo']);
p.parse_args(['--allow-insecure', 'foo,bar']).allowInsecure.should.eql(['foo', 'bar']);
p.parse_args(['--allow-insecure', 'foo ,bar']).allowInsecure.should.eql(['foo', 'bar']);
});
it('should parse --deny-insecure correctly', function () {
p.parseArgs([]).denyInsecure.should.eql([]);
p.parseArgs(['--deny-insecure', '']).denyInsecure.should.eql([]);
p.parseArgs(['--deny-insecure', 'foo']).denyInsecure.should.eql(['foo']);
p.parseArgs(['--deny-insecure', 'foo,bar']).denyInsecure.should.eql(['foo', 'bar']);
p.parseArgs(['--deny-insecure', 'foo ,bar']).denyInsecure.should.eql(['foo', 'bar']);
p.parse_args([]).denyInsecure.should.eql([]);
p.parse_args(['--deny-insecure', '']).denyInsecure.should.eql([]);
p.parse_args(['--deny-insecure', 'foo']).denyInsecure.should.eql(['foo']);
p.parse_args(['--deny-insecure', 'foo,bar']).denyInsecure.should.eql(['foo', 'bar']);
p.parse_args(['--deny-insecure', 'foo ,bar']).denyInsecure.should.eql(['foo', 'bar']);
});
it('should parse --allow and --deny insecure from files', function () {
const parsed = p.parseArgs([
const parsed = p.parse_args([
'--allow-insecure', ALLOW_FIXTURE, '--deny-insecure', DENY_FIXTURE
]);
parsed.allowInsecure.should.eql(['feature1', 'feature2', 'feature3']);