]> zoso.dev Git - nano-pow.git/commitdiff
Move validate parsing. Add CLI help text. Whitespace.
authorChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 23:31:47 +0000 (16:31 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 23:31:47 +0000 (16:31 -0700)
cli.js

diff --git a/cli.js b/cli.js
index d969774fe89b09c4a46f87eb64de259f7b43141c..b7b8431ba1ba115eea217cca50098ac7b68d326a 100755 (executable)
--- a/cli.js
+++ b/cli.js
@@ -6,6 +6,29 @@ import * as puppeteer from 'puppeteer'
 import * as fs from 'node:fs/promises'
 
 const args = process.argv.slice(2)
+if (args.length === 0 || args.some(v => v === '--help' || v === '-h')) {
+       console.log(`Usage: nano-pow [OPTION]... BLOCKHASH...
+Generate work for BLOCKHASH, or multiple work values for BLOCKHASH(es)
+Multiple blockhash values must be separated by spaces.
+All command options are optional.
+
+  -h, --help                  show this dialog
+  -d, --debug                 enable additional logging output
+  -e, --effort <value>        increase demand on GPU processing
+  -t, --threshold <value>     override the minimum threshold value
+  -v, --validate <value>      check an existing work value instead of searching for one
+
+Blockhash(es) must be 64-character hexadecimal values.
+If validating a nonce, it must be a 16-character hexadecimal value.
+Effort must be a decimal number between 1 - 32.
+Threshold must be a hexadecimal number between 0x0 - 0xFFFFFFFF.
+
+Report bugs: <bug-nano-pow@zoso.dev>
+Full documentation: <https://www.npmjs.com/package/nano-pow>
+`)
+       process.exit()
+}
+
 const hashes = []
 while (/^[0-9A-Fa-f]{64}$/.test(args[args.length - 1] ?? '')) {
        hashes.unshift(args.pop())
@@ -20,6 +43,14 @@ let work = ''
 const options = {}
 for (let i = 0; i < args.length; i++) {
        switch (args[i]) {
+               case ('--validate'):
+               case ('-v'): {
+                       if (args[i + 1] == null) throw new Error('Missing argument for work validation')
+                       if (!/^[0-9A-Fa-f]{16}$/.test(args[i + 1])) throw new Error('Invalid work to validate')
+                       fn = 'validate'
+                       work = `'${args[i + 1]}', `
+                       break
+               }
                case ('--threshold'):
                case ('-t'): {
                        if (args[i + 1] == null) throw new Error('Missing argument for threshold')
@@ -39,19 +70,16 @@ for (let i = 0; i < args.length; i++) {
                        options['debug'] = true
                        break
                }
-               case ('--validate'):
-               case ('-v'): {
-                       if (args[i + 1] == null) throw new Error('Missing argument for work validation')
-                       if (!/^[0-9A-Fa-f]{16}$/.test(args[i + 1])) throw new Error('Invalid work to validate')
-                       fn = 'validate'
-                       work = `'${args[i + 1]}', `
-                       break
-               }
        }
 }
+
 if (options['debug']) console.log(`NanoPowCli.${fn}()`)
-if (options['debug']) console.log(`${fn} options`, JSON.stringify(options));
+if (options['debug']) console.log(`${fn} options`, JSON.stringify(options))
 
+       ;
+/**
+* Main
+*/
 (async () => {
        const NanoPow = await fs.readFile(`${import.meta.dirname}/main.min.js`, 'utf-8')
        const browser = await puppeteer.launch({