Skip to content

Commit

Permalink
chore(deps): bump argparse from 1.0.10 to 2.0.1 (appium#14687)
Browse files Browse the repository at this point in the history
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] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mykola Mokhnach <[email protected]>
  • Loading branch information
1 parent a88f51d commit 163b34d
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 377 deletions.
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 1 addition & 3 deletions lib/appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
77 changes: 77 additions & 0 deletions lib/argsparse-actions.js
Original file line number Diff line number Diff line change
@@ -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,
};
42 changes: 25 additions & 17 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 163b34d

Please sign in to comment.