Skip to content

Commit 8b3edae

Browse files
committed
Drop support for Node versions < 12.17
upgrade deps, dates, CI Now an ES Module
1 parent 25f7538 commit 8b3edae

File tree

12 files changed

+387
-3355
lines changed

12 files changed

+387
-3355
lines changed

.github/workflows/node.js.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
2+
3+
name: Node.js CI
4+
5+
on:
6+
push:
7+
branches: [ master ]
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ${{ matrix.os }}
15+
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest]
19+
node-version: [12, 14, 16, 18, 20, 22]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
- run: npm install
29+
- run: npm i -g @75lb/nature
30+
- run: npm run test:ci

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-21 Lloyd Brookes <[email protected]>
3+
Copyright (c) 2015-25 Lloyd Brookes <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.hbs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[![view on npm](http://img.shields.io/npm/v/command-line-commands.svg)](https://www.npmjs.org/package/command-line-commands)
2-
[![npm module downloads](http://img.shields.io/npm/dt/command-line-commands.svg)](https://www.npmjs.org/package/command-line-commands)
3-
[![Build Status](https://travis-ci.org/75lb/command-line-commands.svg?branch=master)](https://travis-ci.org/75lb/command-line-commands)
4-
[![Coverage Status](https://coveralls.io/repos/github/75lb/command-line-commands/badge.svg?branch=master)](https://coveralls.io/github/75lb/command-line-commands?branch=master)
5-
[![Dependency Status](https://badgen.net/david/dep/75lb/command-line-commands)](https://david-dm.org/75lb/command-line-commands)
1+
[![view on npm](https://badgen.net/npm/v/command-line-commands)](https://www.npmjs.org/package/command-line-commands)
2+
[![npm module downloads](https://badgen.net/npm/dt/command-line-commands)](https://www.npmjs.org/package/command-line-commands)
3+
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/command-line-commands)](https://github.com/75lb/command-line-commands/network/dependents?dependent_type=REPOSITORY)
4+
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/command-line-commands)](https://github.com/75lb/command-line-commands/network/dependents?dependent_type=PACKAGE)
5+
[![Node.js CI](https://github.com/75lb/command-line-commands/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/command-line-commands/actions/workflows/node.js.yml)
66
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
77

88
# command-line-commands
9+
910
A lightweight module to help build a git-like command interface for your app.
1011

1112
Its job is to extract the command (the first argument, unless it's an option), check it's valid and either return it or throw. From there, you can parse the remaining args using your preferred option parser (e.g. [command-line-args](https://github.com/75lb/command-line-args), [minimist](https://github.com/substack/minimist) etc.).
@@ -103,4 +104,4 @@ Usage guides can be generated by [command-line-usage](https://github.com/75lb/co
103104

104105
* * *
105106

106-
&copy; 2015-21 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
107+
&copy; 2015-25 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[![view on npm](http://img.shields.io/npm/v/command-line-commands.svg)](https://www.npmjs.org/package/command-line-commands)
2-
[![npm module downloads](http://img.shields.io/npm/dt/command-line-commands.svg)](https://www.npmjs.org/package/command-line-commands)
3-
[![Build Status](https://travis-ci.org/75lb/command-line-commands.svg?branch=master)](https://travis-ci.org/75lb/command-line-commands)
4-
[![Coverage Status](https://coveralls.io/repos/github/75lb/command-line-commands/badge.svg?branch=master)](https://coveralls.io/github/75lb/command-line-commands?branch=master)
5-
[![Dependency Status](https://badgen.net/david/dep/75lb/command-line-commands)](https://david-dm.org/75lb/command-line-commands)
1+
[![view on npm](https://badgen.net/npm/v/command-line-commands)](https://www.npmjs.org/package/command-line-commands)
2+
[![npm module downloads](https://badgen.net/npm/dt/command-line-commands)](https://www.npmjs.org/package/command-line-commands)
3+
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/command-line-commands)](https://github.com/75lb/command-line-commands/network/dependents?dependent_type=REPOSITORY)
4+
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/command-line-commands)](https://github.com/75lb/command-line-commands/network/dependents?dependent_type=PACKAGE)
5+
[![Node.js CI](https://github.com/75lb/command-line-commands/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/command-line-commands/actions/workflows/node.js.yml)
66
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
77

88
# command-line-commands
9+
910
A lightweight module to help build a git-like command interface for your app.
1011

1112
Its job is to extract the command (the first argument, unless it's an option), check it's valid and either return it or throw. From there, you can parse the remaining args using your preferred option parser (e.g. [command-line-args](https://github.com/75lb/command-line-args), [minimist](https://github.com/substack/minimist) etc.).
@@ -117,4 +118,4 @@ Parses the `argv` value supplied (or `process.argv` by default), extracting and
117118

118119
* * *
119120

120-
&copy; 2015-21 Lloyd Brookes \<[email protected]\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).
121+
&copy; 2015-25 Lloyd Brookes \<[email protected]\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).

dist/index.cjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
3+
var arrayify = require('array-back');
4+
5+
/**
6+
* A module for testing for and extracting names from options (e.g. `--one`, `-o`)
7+
*/
8+
9+
class Arg {
10+
constructor (re) {
11+
this.re = re;
12+
}
13+
14+
test (arg) {
15+
return this.re.test(arg)
16+
}
17+
}
18+
19+
const isShort = new Arg(/^-([^\d-])$/);
20+
const isLong = new Arg(/^--(\S+)/);
21+
const isCombined = new Arg(/^-([^\d-]{2,})$/);
22+
const isOption = function (arg) {
23+
return isShort.test(arg) || isLong.test(arg) || isCombined.test(arg)
24+
};
25+
26+
/**
27+
* @module command-line-commands
28+
* @example
29+
* const commandLineCommands = require('command-line-commands')
30+
*/
31+
32+
/**
33+
* Parses the `argv` value supplied (or `process.argv` by default), extracting and returning the `command` and remainder of `argv`. The command will be the first value in the `argv` array unless it is an option (e.g. `--help`).
34+
*
35+
* @param {string|string[]} - One or more command strings, one of which the user must supply. Include `null` to represent "no command" (effectively making a command optional).
36+
* @param [argv] {string[]} - An argv array, defaults to the global `process.argv` if not supplied.
37+
* @returns {{ command: string, argv: string[] }}
38+
* @throws `INVALID_COMMAND` - user supplied a command not specified in `commands`.
39+
* @alias module:command-line-commands
40+
*/
41+
function commandLineCommands (commands, argv) {
42+
if (!commands || (Array.isArray(commands) && !commands.length)) {
43+
throw new Error('Please supply one or more commands')
44+
}
45+
if (argv) {
46+
argv = arrayify(argv);
47+
} else {
48+
/* if no argv supplied, assume we are parsing process.argv. */
49+
/* never modify the global process.argv directly. */
50+
argv = process.argv.slice(0);
51+
argv.splice(0, 2);
52+
}
53+
54+
/* the command is the first arg, unless it's an option (e.g. --help) */
55+
const command = (isOption(argv[0]) || !argv.length) ? null : argv.shift();
56+
57+
if (arrayify(commands).indexOf(command) === -1) {
58+
const err = new Error('Command not recognised: ' + command);
59+
err.command = command;
60+
err.name = 'INVALID_COMMAND';
61+
throw err
62+
}
63+
64+
return { command, argv }
65+
}
66+
67+
module.exports = commandLineCommands;

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import arrayify from 'array-back'
2+
import { isOption } from './option.js'
3+
14
/**
25
* @module command-line-commands
36
* @example
47
* const commandLineCommands = require('command-line-commands')
58
*/
6-
module.exports = commandLineCommands
79

810
/**
911
* Parses the `argv` value supplied (or `process.argv` by default), extracting and returning the `command` and remainder of `argv`. The command will be the first value in the `argv` array unless it is an option (e.g. `--help`).
@@ -15,9 +17,6 @@ module.exports = commandLineCommands
1517
* @alias module:command-line-commands
1618
*/
1719
function commandLineCommands (commands, argv) {
18-
const arrayify = require('array-back')
19-
const option = require('./option')
20-
2120
if (!commands || (Array.isArray(commands) && !commands.length)) {
2221
throw new Error('Please supply one or more commands')
2322
}
@@ -31,7 +30,7 @@ function commandLineCommands (commands, argv) {
3130
}
3231

3332
/* the command is the first arg, unless it's an option (e.g. --help) */
34-
const command = (option.isOption(argv[0]) || !argv.length) ? null : argv.shift()
33+
const command = (isOption(argv[0]) || !argv.length) ? null : argv.shift()
3534

3635
if (arrayify(commands).indexOf(command) === -1) {
3736
const err = new Error('Command not recognised: ' + command)
@@ -42,3 +41,5 @@ function commandLineCommands (commands, argv) {
4241

4342
return { command, argv }
4443
}
44+
45+
export default commandLineCommands

option.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ class Arg {
1212
}
1313
}
1414

15-
exports.isShort = new Arg(/^-([^\d-])$/)
16-
exports.isLong = new Arg(/^--(\S+)/)
17-
exports.isCombined = new Arg(/^-([^\d-]{2,})$/)
18-
exports.isOption = function (arg) {
19-
return this.isShort.test(arg) || this.isLong.test(arg) || this.isCombined.test(arg)
15+
const isShort = new Arg(/^-([^\d-])$/)
16+
const isLong = new Arg(/^--(\S+)/)
17+
const isCombined = new Arg(/^-([^\d-]{2,})$/)
18+
const isOption = function (arg) {
19+
return isShort.test(arg) || isLong.test(arg) || isCombined.test(arg)
2020
}
21-
exports.optEquals = new Arg(/^(--\S+)=(.*)/)
21+
const optEquals = new Arg(/^(--\S+)=(.*)/)
22+
23+
export { isShort, isLong, isCombined, isOption, optEquals }

0 commit comments

Comments
 (0)