Skip to content

Commit

Permalink
Added --ipv6 + --mac CLI options to generate different address types
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed May 9, 2024
1 parent 1785a32 commit 8b50546
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions generate-ip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ Parameter options:
--qty=n Generate n IP address(es).
Boolean options:
-6, --ipv6 Generate IPv6 address.
-m, --mac Generate MAC address.
-q, --quiet Suppress all logging except errors.
Info commands:
Expand Down
2 changes: 2 additions & 0 deletions generate-ip/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ Parameter options:
--qty=n Generate n IP address(es).
Boolean options:
-6, --ipv6 Generate IPv6 address.
-m, --mac Generate MAC address.
-q, --quiet Suppress all logging except errors.
Info commands:
Expand Down
15 changes: 12 additions & 3 deletions generate-ip/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const pkgName = 'generate-ip',
(async () => {

// Import LIBS
const { ipv4 } = require(__dirname.match(/src/) ? './generate-ip' : './generate-ip.min'),
const { ipv4, ipv6, mac } = require(__dirname.match(/src/) ? './generate-ip' : './generate-ip.min'),
fs = require('fs'), path = require('path'),
{ execSync } = require('child_process'); // for --version cmd + cross-platform copying

Expand Down Expand Up @@ -58,7 +58,11 @@ const pkgName = 'generate-ip',
const config = {};
const reArgs = {
paramOptions: { 'qty': /^--?qu?a?n?ti?t?y(?:=.*|$)/ },
flags: { 'quietMode': /^--?q(?:uiet)?(?:-?mode)?$/ },
flags: {
'ipv6mode': /^--?(?:ip)?v?6(?:-?mode)?$/,
'macMode': /^--?m(?:ac)?(?:-?mode)?$/,
'quietMode': /^--?q(?:uiet)?(?:-?mode)?$/
},
infoCmds: { 'help': /^--?h(?:elp)?$/, 'version': /^--?ve?r?s?i?o?n?$/ }
};
process.argv.forEach(arg => {
Expand Down Expand Up @@ -111,7 +115,10 @@ const pkgName = 'generate-ip',
console.info(`${ msgs.prefix_localVer || 'Local version' }: ${localVer}`);

} else { // log/copy RESULT(S)
const ipResult = ipv4.generate({ qty: config.qty || 1, verbose: !config.quietMode });
const genOptions = { qty: config.qty || 1, verbose: !config.quietMode },
ipResult = config.ipv6mode ? ipv6.generate(genOptions)
: config.macMode ? mac.generate(genOptions)
: ipv4.generate(genOptions);
printIfNotQuiet(`\n${ msgs.info_copying || 'Copying to clipboard' }...`);
copyToClipboard(Array.isArray(ipResult) ? ipResult.join('\n') : ipResult);
}
Expand Down Expand Up @@ -146,6 +153,8 @@ const pkgName = 'generate-ip',
],
'flags': [
`\n${bw}o ${ msgs.helpSection_flags || 'Boolean options' }:${nc}`,
' -6, --ipv6 Generate IPv6 address.',
' -m, --mac Generate MAC address.',
` -q, --quiet ${ msgs.optionDesc_quiet || 'Suppress all logging except errors' }.`
],
'infoCmds': [
Expand Down

0 comments on commit 8b50546

Please sign in to comment.