Skip to content

Commit

Permalink
fixup! docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Sep 29, 2024
1 parent b3663ac commit 7215a86
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ use it only to escape paths, inside double quotes.
This function is meant to be used for tagged template strings.

```js
childProcess.execSync(...common.escapePOSIXShell`cp "${origin}" "${destination}"`);
const { escapePOSIXShell } = require('../common');
const fixtures = require('../common/fixtures');
const { execSync } = require('node:child_process');
const origin = fixtures.path('origin');
const origin = fixtures.path('destination');

execSync(...escapePOSIXShell`cp "${origin}" "${destination}"`);

// When you need to specify specific options, and/or additional env variables:
const [cmd, opts] = common.escapePOSIXShell`cp "${origin}" "${destination}"`;
typeof cmd === 'string'; // true
opts === undefined || typeof opts.env === 'object'; // true
childProcess.execSync(cmd, { ...opts, stdio: 'ignore' });
childProcess.execSync(cmd, { stdio: 'ignore', env: { ...opts?.env, KEY: 'value' } });
const [cmd, opts] = escapePOSIXShell`cp "${origin}" "${destination}"`;
console.log(typeof cmd === 'string'); // true
console.log(opts === undefined || typeof opts.env === 'object'); // true
execSync(cmd, { ...opts, stdio: 'ignore' });
execSync(cmd, { stdio: 'ignore', env: { ...opts?.env, KEY: 'value' } });
```

When possible, avoid using a shell; that way, there's no need to escape values.
Expand Down

0 comments on commit 7215a86

Please sign in to comment.