Skip to content

Commit 163b34d

Browse files
chore(deps): bump argparse from 1.0.10 to 2.0.1 (appium#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](nodeca/argparse@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>
1 parent a88f51d commit 163b34d

10 files changed

+382
-377
lines changed

gulpfile.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ gulp.task('docs', gulp.series(['transpile']), function parseDocs () {
7070
const exampleArg = typeof arg[0][1] === 'undefined' ? arg[0][0] : arg[0][1];
7171
const argOpts = arg[1];
7272

73-
// --keystore-path defaultValue contains a user-specific path,
73+
// --keystore-path default contains a user-specific path,
7474
// let's replace it with <user>/...
7575
if (arg[0][0] === '--keystore-path') {
7676
const userPath = process.env.HOME || process.env.USERPROFILE;
77-
argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;');
77+
argOpts.default = argOpts.default.replace(userPath, '&lt;user&gt;');
7878
}
7979

8080
// handle empty objects
81-
if (JSON.stringify(argOpts.defaultValue) === '{}') {
82-
argOpts.defaultValue = '{}';
81+
if (JSON.stringify(argOpts.default) === '{}') {
82+
argOpts.default = '{}';
8383
}
8484

8585
md += '|`' + argNames.join('`, `') + '`';
86-
md += '|' + ((typeof argOpts.defaultValue === 'undefined') ? '' : argOpts.defaultValue);
86+
md += '|' + ((typeof argOpts.default === 'undefined') ? '' : argOpts.default);
8787
md += '|' + argOpts.help;
8888
md += '|' + ((typeof argOpts.example === 'undefined') ? '' : '`' + exampleArg + ' ' + argOpts.example + '`');
8989
md += '|\n';

lib/appium.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ class AppiumDriver extends BaseDriver {
254254
async getSessions () {
255255
const sessions = await sessionsListGuard.acquire(AppiumDriver.name, () => this.sessions);
256256
return _.toPairs(sessions)
257-
.map(([id, driver]) => {
258-
return {id, capabilities: driver.caps};
259-
});
257+
.map(([id, driver]) => ({id, capabilities: driver.caps}));
260258
}
261259

262260
printNewSessionAnnouncement (driverName, driverVersion) {

lib/argsparse-actions.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { Action } from 'argparse';
2+
3+
4+
const DEFAULT_CAPS_ARG = '--default-capabilities';
5+
6+
7+
class StoreDeprecatedAction extends Action {
8+
constructor (options = {}) {
9+
const opts = Object.assign({}, options);
10+
let helpPrefix = '[DEPRECATED]';
11+
if (opts.deprecated_for) {
12+
helpPrefix = `[DEPRECATED, use ${opts.deprecated_for} instead]`;
13+
delete opts.deprecated_for;
14+
}
15+
if (opts.help) {
16+
opts.help = `${helpPrefix} - ${opts.help}`;
17+
} else {
18+
opts.help = helpPrefix;
19+
}
20+
super(opts);
21+
}
22+
23+
call (parser, namespace, values) {
24+
namespace[this.dest] = values;
25+
}
26+
}
27+
28+
29+
class StoreDeprecatedTrueAction extends StoreDeprecatedAction {
30+
constructor (options = {}) {
31+
super(Object.assign({}, options, {const: true, nargs: 0}));
32+
}
33+
34+
call (parser, namespace) {
35+
namespace[this.dest] = this.const;
36+
}
37+
}
38+
39+
40+
class StoreDeprecatedDefaultCapabilityAction extends StoreDeprecatedAction {
41+
constructor (options = {}) {
42+
super(Object.assign({}, options, {deprecated_for: DEFAULT_CAPS_ARG}));
43+
}
44+
45+
_writeDefaultCap (namespace, value) {
46+
namespace[this.dest] = value;
47+
if (value === this.default) {
48+
return;
49+
}
50+
51+
if (!namespace.defaultCapabilities) {
52+
namespace.defaultCapabilities = {};
53+
}
54+
namespace.defaultCapabilities[this.dest] = value;
55+
}
56+
57+
call (parser, namespace, values) {
58+
this._writeDefaultCap(namespace, values);
59+
}
60+
}
61+
62+
63+
class StoreDeprecatedDefaultCapabilityTrueAction extends StoreDeprecatedDefaultCapabilityAction {
64+
constructor (options = {}) {
65+
super(Object.assign({}, options, {const: true, nargs: 0}));
66+
}
67+
68+
call (parser, namespace) {
69+
this._writeDefaultCap(namespace, this.const);
70+
}
71+
}
72+
73+
export {
74+
StoreDeprecatedAction, StoreDeprecatedTrueAction,
75+
StoreDeprecatedDefaultCapabilityAction, StoreDeprecatedDefaultCapabilityTrueAction,
76+
DEFAULT_CAPS_ARG,
77+
};

lib/config.js

+25-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { exec } from 'teen_process';
66
import { rootDir } from './utils';
77
import logger from './logger';
88
import semver from 'semver';
9+
import {
10+
StoreDeprecatedDefaultCapabilityAction, DEFAULT_CAPS_ARG,
11+
} from './argsparse-actions';
912

1013

1114
const npmPackage = require(path.resolve(rootDir, 'package.json'));
@@ -24,6 +27,11 @@ function getNodeVersion () {
2427
return semver.coerce(process.version);
2528
}
2629

30+
function isSubClass (candidateClass, superClass) {
31+
return _.isFunction(superClass) && _.isFunction(candidateClass)
32+
&& (candidateClass.prototype instanceof superClass || candidateClass === superClass);
33+
}
34+
2735
async function updateBuildInfo (useGithubApiFallback = false) {
2836
const sha = await getGitRev(useGithubApiFallback);
2937
if (!sha) {
@@ -136,29 +144,29 @@ async function showConfig () {
136144
}
137145

138146
function getNonDefaultArgs (parser, args) {
139-
let nonDefaults = {};
140-
for (let rawArg of parser.rawArgs) {
141-
let arg = rawArg[1].dest;
142-
if (args[arg] && args[arg] !== rawArg[1].defaultValue) {
143-
nonDefaults[arg] = args[arg];
147+
return parser.rawArgs.reduce((acc, [, {dest, default: defaultValue}]) => {
148+
if (args[dest] && args[dest] !== defaultValue) {
149+
acc[dest] = args[dest];
144150
}
145-
}
146-
return nonDefaults;
151+
return acc;
152+
}, {});
147153
}
148154

149155
function getDeprecatedArgs (parser, args) {
150156
// go through the server command line arguments and figure
151157
// out which of the ones used are deprecated
152-
let deprecated = {};
153-
for (let rawArg of parser.rawArgs) {
154-
let arg = rawArg[1].dest;
155-
let defaultValue = rawArg[1].defaultValue;
156-
let isDeprecated = !!rawArg[1].deprecatedFor;
157-
if (args[arg] && args[arg] !== defaultValue && isDeprecated) {
158-
deprecated[rawArg[0]] = rawArg[1].deprecatedFor;
158+
return parser.rawArgs.reduce((acc, [[name], {dest, default: defaultValue, action}]) => {
159+
if (!args[dest] || args[dest] === defaultValue) {
160+
return acc;
159161
}
160-
}
161-
return deprecated;
162+
163+
if (action?.deprecated_for) {
164+
acc[name] = action.deprecated_for;
165+
} else if (isSubClass(action, StoreDeprecatedDefaultCapabilityAction)) {
166+
acc[name] = DEFAULT_CAPS_ARG;
167+
}
168+
return acc;
169+
}, {});
162170
}
163171

164172
function checkValidPort (port, portName) {
@@ -197,7 +205,7 @@ function validateServerArgs (parser, args) {
197205
bootstrapPort: checkValidPort,
198206
chromedriverPort: checkValidPort,
199207
robotPort: checkValidPort,
200-
backendRetries: (r) => { return r >= 0; }
208+
backendRetries: (r) => r >= 0,
201209
};
202210

203211
const nonDefaultArgs = getNonDefaultArgs(parser, args);

lib/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async function main (args = null) {
111111
}
112112
} else {
113113
// otherwise parse from CLI
114-
args = parser.parseArgs();
114+
args = parser.parse_args();
115115
}
116116
await logsinkInit(args);
117117
if (args.logFilters) {

0 commit comments

Comments
 (0)