@benev/argv
Advanced tools
Comparing version 0.0.0-dev.0 to 0.0.0-dev.1
{ | ||
"name": "@benev/argv", | ||
"version": "0.0.0-dev.0", | ||
"version": "0.0.0-dev.1", | ||
"description": "command line argument parser", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
# 🎛️ `@benev/argv` *command line argument parser* | ||
# 🎛️ `@benev/argv` | ||
***command line argument parser*** | ||
🤖 for making node cli programs | ||
@@ -5,0 +7,0 @@ 🕵️♂️ designed for proper typescript typings |
@@ -8,3 +8,3 @@ | ||
export function parsingStateMachine<A extends Argspec, P extends Paramspec>( | ||
export function parsingMachine<A extends Argspec, P extends Paramspec>( | ||
spec: Spec<A, P> | ||
@@ -14,3 +14,3 @@ ) { | ||
let paramIndex = 0 | ||
let assignNextValueToField: undefined | keyof P = undefined // TODO rename param | ||
let scheduledParamAssignment: undefined | keyof P = undefined | ||
@@ -28,12 +28,12 @@ const getArgType = (name: keyof A) => spec.args[name] | ||
isScheduledAsParamValue: () => { | ||
return !!assignNextValueToField | ||
return !!scheduledParamAssignment | ||
}, | ||
scheduleNextItemAsParamValue: (item: string) => { | ||
assignNextValueToField = item | ||
scheduledParamAssignment = item | ||
}, | ||
saveParam: (item: string) => { | ||
const name = assignNextValueToField! | ||
assignNextValueToField = undefined | ||
const name = scheduledParamAssignment! | ||
scheduledParamAssignment = undefined | ||
params[name] = parseValue(getParamType(name), item) | ||
@@ -40,0 +40,0 @@ }, |
@@ -6,3 +6,3 @@ | ||
import {Paramspec} from "./types/paramspec.js" | ||
import {parsingStateMachine} from "./internals/machine.js" | ||
import {parsingMachine} from "./internals/machine.js" | ||
@@ -25,3 +25,3 @@ export function parse<A extends Argspec, P extends Paramspec>( | ||
scheduleNextItemAsParamValue, | ||
} = parsingStateMachine(spec) | ||
} = parsingMachine(spec) | ||
@@ -28,0 +28,0 @@ for (const item of items) { |
import { Spec } from "../types/spec.js"; | ||
import { Argspec } from "../types/argspec.js"; | ||
import { Paramspec } from "../types/paramspec.js"; | ||
export declare function parsingStateMachine<A extends Argspec, P extends Paramspec>(spec: Spec<A, P>): { | ||
export declare function parsingMachine<A extends Argspec, P extends Paramspec>(spec: Spec<A, P>): { | ||
args: { [X in keyof A]?: import("../index.js").Primitive<A[X]> | undefined; }; | ||
@@ -6,0 +6,0 @@ params: { [X_1 in keyof P]?: import("../index.js").Primitive<P[X_1]> | undefined; }; |
import { parseValue } from "./parse-value.js"; | ||
export function parsingStateMachine(spec) { | ||
export function parsingMachine(spec) { | ||
let paramIndex = 0; | ||
let assignNextValueToField = undefined; // TODO rename param | ||
let scheduledParamAssignment = undefined; | ||
const getArgType = (name) => spec.args[name]; | ||
@@ -13,10 +13,10 @@ const getParamType = (name) => spec.params[name]; | ||
isScheduledAsParamValue: () => { | ||
return !!assignNextValueToField; | ||
return !!scheduledParamAssignment; | ||
}, | ||
scheduleNextItemAsParamValue: (item) => { | ||
assignNextValueToField = item; | ||
scheduledParamAssignment = item; | ||
}, | ||
saveParam: (item) => { | ||
const name = assignNextValueToField; | ||
assignNextValueToField = undefined; | ||
const name = scheduledParamAssignment; | ||
scheduledParamAssignment = undefined; | ||
params[name] = parseValue(getParamType(name), item); | ||
@@ -23,0 +23,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { parsingStateMachine } from "./internals/machine.js"; | ||
import { parsingMachine } from "./internals/machine.js"; | ||
export function parse(spec) { | ||
@@ -6,3 +6,3 @@ if (spec.argorder.length !== Object.keys(spec.args).length) | ||
const [executable, module, ...items] = spec.argv; | ||
const { args, params, isScheduledAsParamValue, saveArg, saveParam, scheduleNextItemAsParamValue, } = parsingStateMachine(spec); | ||
const { args, params, isScheduledAsParamValue, saveArg, saveParam, scheduleNextItemAsParamValue, } = parsingMachine(spec); | ||
for (const item of items) { | ||
@@ -9,0 +9,0 @@ if (isScheduledAsParamValue()) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73
17316