Deepen all 16 pear-platform scaffolds to production APIs.
Expands spawn, argv, preflight, trust, OTA, pipes, and headless UI modules; bumps to 0.3.1 with fuller tests and registry tier updates. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const { platformStats } = require('../../_shared/pear-platform-base.js')
|
||||
const { isLaunchTarget, platformStats } = require('../../_shared/pear-platform-base.js')
|
||||
|
||||
const PROTOCOL = 'bare-argv-bridge/v1'
|
||||
|
||||
@@ -16,6 +16,7 @@ class HyperBareArgvBridge extends EventEmitter {
|
||||
setArgv (argv) {
|
||||
this._argv = Array.isArray(argv) ? [...argv] : []
|
||||
this._parse()
|
||||
this.emit('parse', { flags: this._flags.size, rest: this._rest.length })
|
||||
return { flags: Object.fromEntries(this._flags), rest: [...this._rest] }
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ class HyperBareArgvBridge extends EventEmitter {
|
||||
this._flags.set(tok.slice(2, eq), tok.slice(eq + 1))
|
||||
} else {
|
||||
const next = a[i + 1]
|
||||
if (next && !next.startsWith('-')) {
|
||||
if (next && !next.startsWith('-') && !isLaunchTarget(next)) {
|
||||
this._flags.set(tok.slice(2), next)
|
||||
i++
|
||||
} else {
|
||||
@@ -40,20 +41,57 @@ class HyperBareArgvBridge extends EventEmitter {
|
||||
}
|
||||
} else if (!tok.startsWith('-')) {
|
||||
this._rest.push(tok)
|
||||
} else if (tok.startsWith('-') && !tok.startsWith('--')) {
|
||||
for (const ch of tok.slice(1)) this._flags.set(ch, true)
|
||||
}
|
||||
}
|
||||
this._stats.parsed++
|
||||
}
|
||||
|
||||
subcommand () {
|
||||
return this._rest[0] || null
|
||||
}
|
||||
|
||||
positional (index = 0) {
|
||||
const off = this.subcommand() ? 1 : 0
|
||||
return this._rest[off + index] || null
|
||||
}
|
||||
|
||||
flag (name) { return this._flags.get(name) }
|
||||
rest () { return [...this._rest] }
|
||||
|
||||
hasFlag (name) { return this._flags.has(name) }
|
||||
|
||||
rest () { return [...this._rest] }
|
||||
|
||||
launchTargets () {
|
||||
return this._rest.filter(isLaunchTarget)
|
||||
}
|
||||
|
||||
passthroughArgs () {
|
||||
const targets = new Set(this.launchTargets())
|
||||
const sub = this.subcommand()
|
||||
return this._rest.filter((t) => t !== sub && !targets.has(t))
|
||||
}
|
||||
|
||||
toRuntimeFlags () {
|
||||
const out = []
|
||||
for (const [k, v] of this._flags) {
|
||||
if (v === true) out.push(`--${k}`)
|
||||
else out.push(`--${k}=${v}`)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return platformStats(this._stats, PROTOCOL, { flags: this._flags.size, rest: this._rest.length })
|
||||
return platformStats(this._stats, PROTOCOL, {
|
||||
flags: this._flags.size,
|
||||
rest: this._rest.length,
|
||||
targets: this.launchTargets().length
|
||||
})
|
||||
}
|
||||
|
||||
async ready () { return this }
|
||||
|
||||
async close () { this.emit('closed') }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hyper-bare-argv-bridge",
|
||||
"version": "0.0.0-scaffold",
|
||||
"version": "0.3.1",
|
||||
"description": "CLI argv and flag parsing for Bare apps.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
|
||||
@@ -4,8 +4,18 @@ const { HyperBareArgvBridge } = require('../index.js')
|
||||
|
||||
test('parse argv', async (t) => {
|
||||
const a = new HyperBareArgvBridge()
|
||||
a.setArgv(['run', '--dev=true', 'pear://x', 'extra'])
|
||||
t.is(a.flag('dev'), 'true')
|
||||
t.ok(a.rest().includes('pear://x'))
|
||||
a.setArgv(['run', '--dev', 'pear://x', 'extra'])
|
||||
t.is(a.flag('dev'), true)
|
||||
t.ok(a.launchTargets().includes('pear://x'))
|
||||
t.ok(a.passthroughArgs().includes('extra'))
|
||||
await a.close()
|
||||
})
|
||||
|
||||
test('subcommand and equals flag', async (t) => {
|
||||
const a = new HyperBareArgvBridge()
|
||||
a.setArgv(['stage', '--trusted=true', 'file:///app'])
|
||||
t.is(a.subcommand(), 'stage')
|
||||
t.is(a.flag('trusted'), 'true')
|
||||
t.ok(a.launchTargets()[0].startsWith('file://'))
|
||||
await a.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user