Skip to content

Commit

Permalink
refactor!: upgrade deps drop Node 6/8 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Oct 2, 2020
1 parent 48b16a9 commit c686882
Show file tree
Hide file tree
Showing 5 changed files with 785 additions and 529 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [6, 8, 10, 14]
node: [10, 12, 14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ If you `coerce` in weird ways, things might not work correctly.
`$ npm test`
`$ npm test -- --watch` during development

## Supported Node.js Versions

Libraries in this ecosystem make a best effort to track
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).

## License

Expand Down
39 changes: 35 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const yargs = require('yargs/yargs');
const flatten = require('flat');
const camelcase = require('camelcase');
const decamelize = require('decamelize');
Expand All @@ -24,6 +23,40 @@ function keyToFlag(key) {
return key.length === 1 ? `-${key}` : `--${key}`;
}

function parseCommand(cmd) {
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
const bregex = /\.*[\][<>]/g;
const firstCommand = splitCommand.shift();

if (!firstCommand) { throw new Error(`No command found in: ${cmd}`); }
const parsedCommand = {
cmd: firstCommand.replace(bregex, ''),
demanded: [],
optional: [],
};

splitCommand.forEach((cmd, i) => {
let variadic = false;

cmd = cmd.replace(/\s/g, '');
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1) { variadic = true; }
if (/^\[/.test(cmd)) {
parsedCommand.optional.push({
cmd: cmd.replace(bregex, '').split('|'),
variadic,
});
} else {
parsedCommand.demanded.push({
cmd: cmd.replace(bregex, '').split('|'),
variadic,
});
}
});

return parsedCommand;
}

function unparseOption(key, value, unparsed) {
if (typeof value === 'string') {
unparsed.push(keyToFlag(key), value);
Expand Down Expand Up @@ -54,9 +87,7 @@ function unparsePositional(argv, options, unparsed) {
// e.g.: build <first> <second> <rest...>
if (options.command) {
const { 0: cmd, index } = options.command.match(/[^<[]*/);
const { demanded, optional } = yargs()
.getCommandInstance()
.parseCommand(`foo ${options.command.substr(index + cmd.length)}`);
const { demanded, optional } = parseCommand(`foo ${options.command.substr(index + cmd.length)}`);

// Push command (can be a deep command)
unparsed.push(...cmd.trim().split(/\s+/));
Expand Down
Loading

0 comments on commit c686882

Please sign in to comment.