Skip to content

Commit

Permalink
improve matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Oct 6, 2023
1 parent f960ad0 commit 511fb9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
9 changes: 3 additions & 6 deletions oui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@ async function main() {
if (!args._.length || args._[0] === "help" || args.help) {
process.stdout.write(`${[
"",
" Usage: oui [mac]|[command] [options]",
" Usage: oui [mac]",
"",
" Commands:",
" [mac] look up a MAC address in the database",
" version print the version",
"",
" Examples:",
" oui 20:37:06:12:34:56",
" oui 20_37_06",
" oui 203706",
" oui update",
" oui search cisco theory",
" echo 20:37:06:12:34:56 | oui",
" echo 203706 | oui",
].join("\n")}\n\n`);
process.exit(0);
} else if (args._[0] === "version" || args.v || args.V || args.version) {
process.stdout.write(`${import.meta.VERSION || "0.0.0"}\n`);
} else {
const {default: ouiData} = await import("oui-data", {assert: {type: "json"}});
const result = ouiData[args._[0].replace(/:/g, "").toUpperCase().substring(0, 6)];
const result = ouiData[args._[0].replace(/[^0-9a-f]/gi, "").toUpperCase().substring(0, 6)];
if (result) {
process.stdout.write(`${result}\n`);
} else {
Expand Down
12 changes: 11 additions & 1 deletion oui.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import {execa} from "execa";

test("cli", async () => {
const {stdout, exitCode} = await execa("node", ["--no-warnings", "./bin/oui.js", "20:37:06:12:34:56"]);
let stdout, exitCode;

({stdout, exitCode} = await execa("node", ["./bin/oui.js", "20:37:06:12:34:56"]));
expect(stdout).toMatchSnapshot();
expect(exitCode).toEqual(0);

({stdout, exitCode} = await execa("node", ["./bin/oui.js", "20_37_06"]));
expect(stdout).toMatchSnapshot();
expect(exitCode).toEqual(0);

({stdout, exitCode} = await execa("node", ["./bin/oui.js", "203706"]));
expect(stdout).toMatchSnapshot();
expect(exitCode).toEqual(0);
});
14 changes: 14 additions & 0 deletions snapshots/oui.test.js.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 511fb9e

Please sign in to comment.