diff -Nru node-commist-2.0.0/debian/changelog node-commist-3.1.2+ds/debian/changelog --- node-commist-2.0.0/debian/changelog 2021-08-31 04:39:46.000000000 +0000 +++ node-commist-3.1.2+ds/debian/changelog 2022-11-21 15:13:32.000000000 +0000 @@ -1,3 +1,31 @@ +node-commist (3.1.2+ds-2) unstable; urgency=medium + + [ Debian Janitor ] + * Apply multi-arch hints. + node-commist: Add Multi-Arch: foreign. + + -- Jelmer Vernooij Mon, 21 Nov 2022 15:13:32 +0000 + +node-commist (3.1.2+ds-1) unstable; urgency=medium + + * Team upload + * Drop dependency to nodejs + * Download from GitHub, not from npm registry + * Exclude leven.js from import (Closes: #1019916), repack and add related + patch + * Drop useless dependency to node-minimist + + -- Yadd Fri, 16 Sep 2022 16:25:47 +0200 + +node-commist (3.1.2-1) unstable; urgency=low + + [ Debian Janitor ] + * Update standards version to 4.6.1, no changes needed. + + [ Ying-Chun Liu (PaulLiu) ] + * New upstream version 3.1.2 + + -- Ying-Chun Liu (PaulLiu) Fri, 16 Sep 2022 16:17:54 +0800 + node-commist (2.0.0-1) unstable; urgency=low * Team upload diff -Nru node-commist-2.0.0/debian/control node-commist-3.1.2+ds/debian/control --- node-commist-2.0.0/debian/control 2021-08-31 04:26:24.000000000 +0000 +++ node-commist-3.1.2+ds/debian/control 2022-11-21 15:13:32.000000000 +0000 @@ -6,12 +6,11 @@ Priority: optional Build-Depends: debhelper-compat (= 13) - , nodejs - , node-minimist + , dh-sequence-nodejs , node-leven + , node-minimist , node-tape - , dh-sequence-nodejs -Standards-Version: 4.5.1 +Standards-Version: 4.6.1 Vcs-Browser: https://salsa.debian.org/js-team/node-commist Vcs-Git: https://salsa.debian.org/js-team/node-commist.git Homepage: https://github.com/mcollina/commist @@ -21,9 +20,8 @@ Architecture: all Depends: ${misc:Depends} - , nodejs - , node-minimist , node-leven +Multi-Arch: foreign Description: build commands on node-minimist Build command line application with multiple commands the easy way. To be used with minimist. diff -Nru node-commist-2.0.0/debian/copyright node-commist-3.1.2+ds/debian/copyright --- node-commist-2.0.0/debian/copyright 2021-08-31 04:26:24.000000000 +0000 +++ node-commist-3.1.2+ds/debian/copyright 2022-11-21 15:13:32.000000000 +0000 @@ -2,15 +2,16 @@ Upstream-Name: commist Upstream-Contact: https://github.com/mcollina/commist/issues Source: https://github.com/mcollina/commist +Files-Excluded: leven.js Files: * -Copyright: 2014, Matteo Collina +Copyright: 2014-2022, Matteo Collina License: Expat Files: debian/* Copyright: 2017, Ying-Chun Liu (PaulLiu) 2017, DT42.io - 2019, Yadd + 2019-2022, Yadd License: Expat License: Expat diff -Nru node-commist-2.0.0/debian/patches/fix-leven-calls.patch node-commist-3.1.2+ds/debian/patches/fix-leven-calls.patch --- node-commist-2.0.0/debian/patches/fix-leven-calls.patch 1970-01-01 00:00:00.000000000 +0000 +++ node-commist-3.1.2+ds/debian/patches/fix-leven-calls.patch 2022-11-21 15:13:32.000000000 +0000 @@ -0,0 +1,28 @@ +Description: replace ./leven.js by node-leven +Author: Yadd +Bug-Debian: https://bugs.debian.org/1019916 +Forwarded: not-needed +Last-Update: 2022-09-16 + +--- a/index.js ++++ b/index.js +@@ -24,7 +24,7 @@ + + 'use strict' + +-const leven = require('./leven') ++const leven = require('leven') + + function commist (opts) { + opts = opts || {} +--- a/test.js ++++ b/test.js +@@ -3,7 +3,7 @@ + const test = require('tape').test + + const commist = require('./') +-const leven = require('./leven') ++const leven = require('leven') + + test('registering a command', function (t) { + t.plan(2) diff -Nru node-commist-2.0.0/debian/patches/series node-commist-3.1.2+ds/debian/patches/series --- node-commist-2.0.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ node-commist-3.1.2+ds/debian/patches/series 2022-11-21 15:13:32.000000000 +0000 @@ -0,0 +1 @@ +fix-leven-calls.patch diff -Nru node-commist-2.0.0/debian/watch node-commist-3.1.2+ds/debian/watch --- node-commist-2.0.0/debian/watch 2021-08-31 04:26:24.000000000 +0000 +++ node-commist-3.1.2+ds/debian/watch 2022-11-21 15:13:32.000000000 +0000 @@ -1,5 +1,7 @@ version=4 -# It is not recommended use npmregistry. Please investigate more. -# Take a look at https://wiki.debian.org/debian/watch/ -opts="searchmode=plain,pgpmode=none" \ - https://registry.npmjs.org/commist https://registry.npmjs.org/commist/-/commist-(\d[\d\.]*)@ARCHIVE_EXT@ +opts=\ +ctype=nodejs,\ +repacksuffix=+ds,\ +dversionmangle=auto,\ +filenamemangle=s/.*?(\d[\d\.-]*@ARCHIVE_EXT@)/node-commist-$1/ \ + https://github.com/mcollina/commist/tags .*/archive.*/v?([\d\.]+).tar.gz diff -Nru node-commist-2.0.0/.github/workflows/ci.yml node-commist-3.1.2+ds/.github/workflows/ci.yml --- node-commist-2.0.0/.github/workflows/ci.yml 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/.github/workflows/ci.yml 2022-09-06 14:54:07.000000000 +0000 @@ -8,13 +8,13 @@ strategy: matrix: - node-version: [10.x, 12.x, 14.x, 16.x] + node-version: [14.x, 16.x, 18.x] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} diff -Nru node-commist-2.0.0/.gitignore node-commist-3.1.2+ds/.gitignore --- node-commist-2.0.0/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ node-commist-3.1.2+ds/.gitignore 2022-09-06 14:54:07.000000000 +0000 @@ -0,0 +1,25 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules diff -Nru node-commist-2.0.0/index.js node-commist-3.1.2+ds/index.js --- node-commist-2.0.0/index.js 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/index.js 2022-09-06 14:54:07.000000000 +0000 @@ -1,7 +1,7 @@ /* The MIT License (MIT) -Copyright (c) 2014-2021 Matteo Collina +Copyright (c) 2014-2022 Matteo Collina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -24,27 +24,42 @@ 'use strict' -const leven = require('leven') +const leven = require('./leven') -function commist () { +function commist (opts) { + opts = opts || {} const commands = [] + const maxDistance = opts.maxDistance || Infinity function lookup (array) { if (typeof array === 'string') { array = array.split(' ') } - return commands.map(function (cmd) { + let res = commands.map(function (cmd) { return cmd.match(array) - }).filter(function (match) { - return match.partsNotMatched === 0 - }).sort(function (a, b) { + }) + + res = res.filter(function (match) { + if (match.partsNotMatched !== 0) { + return false + } + return match.distances.reduce(function (acc, curr) { + return acc && curr <= maxDistance + }, true) + }) + + res = res.sort(function (a, b) { if (a.inputNotMatched > b.inputNotMatched) { return 1 } if (a.inputNotMatched === b.inputNotMatched && a.totalDistance > b.totalDistance) { return 1 } return -1 - }).map(function (match) { + }) + + res = res.map(function (match) { return match.cmd }) + + return res } function parse (args) { @@ -64,7 +79,7 @@ let commandOptions = { command: inputCommand, strict: false, - func: func + func } if (typeof inputCommand === 'object') { @@ -83,9 +98,9 @@ } return { - register: register, - parse: parse, - lookup: lookup + register, + parse, + lookup } } @@ -95,10 +110,6 @@ this.parts = this.string.split(' ') this.length = this.parts.length this.func = options.func - - this.parts.forEach(function (part) { - if (part.length < 3) { throw new Error('command words must be at least 3 chars: ' + options.command) } - }) } Command.prototype.call = function call (argv) { @@ -120,12 +131,13 @@ } } else { return undefined } }).filter(function (distance, i) { - return distance !== undefined && distance < cmd.parts[i].length - 2 + return distance !== undefined && distance < cmd.parts[i].length }) this.partsNotMatched = cmd.length - this.distances.length this.inputNotMatched = array.length - this.distances.length this.totalDistance = this.distances.reduce(function (acc, i) { return acc + i }, 0) + // console.log(this, array) } module.exports = commist diff -Nru node-commist-2.0.0/LICENSE node-commist-3.1.2+ds/LICENSE --- node-commist-2.0.0/LICENSE 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/LICENSE 2022-09-06 14:54:07.000000000 +0000 @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Matteo Collina +Copyright (c) 2014-2022 Matteo Collina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff -Nru node-commist-2.0.0/package.json node-commist-3.1.2+ds/package.json --- node-commist-2.0.0/package.json 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/package.json 2022-09-06 14:54:07.000000000 +0000 @@ -1,6 +1,6 @@ { "name": "commist", - "version": "2.0.0", + "version": "3.1.2", "description": "Build your commands on minimist!", "main": "index.js", "scripts": { @@ -18,13 +18,11 @@ }, "homepage": "https://github.com/mcollina/commist", "dependencies": { - "leven": "^3.1.0", - "minimist": "^1.1.0" }, "devDependencies": { "minimist": "^1.1.0", "pre-commit": "^1.0.0", - "standard": "^16.0.0", + "standard": "^17.0.0", "tape": "^5.0.0" } } diff -Nru node-commist-2.0.0/README.md node-commist-3.1.2+ds/README.md --- node-commist-2.0.0/README.md 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/README.md 2022-09-06 14:54:07.000000000 +0000 @@ -1,17 +1,14 @@ commist ======= -[![Build Status](https://travis-ci.com/mcollina/commist.svg?branch=master)](https://travis-ci.com/mcollina/commist) - Build command line application with multiple commands the easy way. To be used with [minimist](http://npm.im/minimist). ```js -var program = require('commist')() - , minimist = require('minimist') - , result +'use strict' -result = program +const program = require('commist')() +const result = program .register('abcd', function(args) { console.log('just do', args) }) @@ -59,10 +56,36 @@ }) ``` -Acknowledgements ----------------- +If you want to limit the maximum levenshtein distance of your commands, +you can use `maxDistance: 2`: + +```js +const program = require('commist')() +const minimist = require('minimist') -This project was kindly sponsored by [nearForm](http://nearform.com). +const result = program + .register('abcd', function(args) { + console.log('just do', args) + }) + .register({ command: 'restore', equals: true }, function(args) { + console.log('restore', args) + }) + .register('args', function(args) { + args = minimist(args) + console.log('just do', args) + }) + .register('abcde code', function(args) { + console.log('doing something', args) + }) + .register('another command', function(args) { + console.log('anothering', args) + }) + .parse(process.argv.splice(2)) + +if (result) { + console.log('no command called, args', result) +} +``` License ------- diff -Nru node-commist-2.0.0/test.js node-commist-3.1.2+ds/test.js --- node-commist-2.0.0/test.js 1985-10-26 08:15:00.000000000 +0000 +++ node-commist-3.1.2+ds/test.js 2022-09-06 14:54:07.000000000 +0000 @@ -3,6 +3,7 @@ const test = require('tape').test const commist = require('./') +const leven = require('./leven') test('registering a command', function (t) { t.plan(2) @@ -168,16 +169,24 @@ program.parse(['hel', 'a', '-x', '23']) }) -test('a command must be at least 3 chars', function (t) { +test('one char command', function (t) { const program = commist() function noop1 () {} - try { - program.register('h', noop1) - t.ok(false, 'not thrown') - } catch (err) { - } + program.register('h', noop1) + t.equal(program.lookup('h')[0].func, noop1) + + t.end() +}) + +test('two char command', function (t) { + const program = commist() + + function noop1 () {} + + program.register('he', noop1) + t.equal(program.lookup('he')[0].func, noop1) t.end() }) @@ -187,11 +196,94 @@ function noop1 () {} - try { - program.register('h b', noop1) - t.ok(false, 'not thrown') - } catch (err) { - } + program.register('h b', noop1) + + t.equal(program.lookup('h b')[0].func, noop1) + + t.end() +}) + +test('short commands match exactly', function (t) { + const program = commist() + + function noop1 () {} + function noop2 () {} + + program.register('h', noop1) + program.register('help', noop2) + t.equal(program.lookup('h')[0].func, noop1) + t.equal(program.lookup('he')[0].func, noop2) + t.equal(program.lookup('hel')[0].func, noop2) + t.equal(program.lookup('help')[0].func, noop2) + + t.end() +}) + +test('leven', function (t) { + t.is(leven('a', 'b'), 1) + t.is(leven('ab', 'ac'), 1) + t.is(leven('ac', 'bc'), 1) + t.is(leven('abc', 'axc'), 1) + t.is(leven('kitten', 'sitting'), 3) + t.is(leven('xabxcdxxefxgx', '1ab2cd34ef5g6'), 6) + t.is(leven('cat', 'cow'), 2) + t.is(leven('xabxcdxxefxgx', 'abcdefg'), 6) + t.is(leven('javawasneat', 'scalaisgreat'), 7) + t.is(leven('example', 'samples'), 3) + t.is(leven('sturgeon', 'urgently'), 6) + t.is(leven('levenshtein', 'frankenstein'), 6) + t.is(leven('distance', 'difference'), 5) + t.is(leven('因為我是中國人所以我會說中文', '因為我是英國人所以我會說英文'), 2) t.end() }) + +test('max distance', function (t) { + const program = commist({ maxDistance: 2 }) + + function noop1 () {} + function noop2 () {} + function noop3 () {} + + program.register('hello', noop1) + program.register('hello world matteo', noop3) + program.register('hello world', noop2) + + t.equal(program.lookup('hel')[0].func, noop1) + t.equal(program.lookup('hel wor mat')[0].func, noop2) + t.equal(program.lookup('hello world matt')[0].func, noop3) + t.equal(program.lookup('hello wor')[0].func, noop2) + t.deepEqual(program.lookup('he wor'), []) + + t.end() +}) + +test('help foobar vs start', function (t) { + const program = commist({ maxDistance: 2 }) + + function noop1 () {} + function noop2 () {} + + program.register('help', noop1) + program.register('start', noop2) + + t.equal(program.lookup('help')[0].func, noop1) + t.deepEqual(program.lookup('help foobar')[0].func, noop1) + t.equal(program.lookup('start')[0].func, noop2) + + t.end() +}) + +test('registering a command with maxDistance', function (t) { + t.plan(2) + + const program = commist({ maxDistance: 2 }) + + program.register('hello', function (args) { + t.deepEqual(args, ['a', '-x', '23']) + }) + + const result = program.parse(['hello', 'a', '-x', '23']) + + t.notOk(result, 'must return null, the command have been handled') +})