mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 16:26:28 +00:00
Nicco
d7e5a34b14
* move to packages * update deps * update deps * actions maintenance * don't use blob * cli * fix default import * use synthetic default imports * remove comment * cli packaging * node 18 guard * packages * build system * testing * test pipeline * pipelines * changelog * version bump * update locales * update deps * update deps * update dependecies
28 lines
773 B
TypeScript
28 lines
773 B
TypeScript
import { InvalidArgumentError, InvalidOptionArgumentError } from '@commander-js/extra-typings'
|
|
import { accessSync, constants } from 'node:fs'
|
|
import { resolve } from 'node:path'
|
|
|
|
export function parseFile(value: string, before: string[] = []) {
|
|
try {
|
|
const file = resolve(value)
|
|
accessSync(file, constants.R_OK)
|
|
return [...before, file]
|
|
} catch {
|
|
throw new InvalidArgumentError('cannot access file')
|
|
}
|
|
}
|
|
|
|
export function parseURL(value: string, _: URL): URL {
|
|
try {
|
|
return new URL(value)
|
|
} catch {
|
|
throw new InvalidArgumentError('is not a valid url')
|
|
}
|
|
}
|
|
|
|
export function parseNumber(value: string, _: number): number {
|
|
const n = parseInt(value, 10)
|
|
if (isNaN(n)) throw new InvalidOptionArgumentError('invalid number')
|
|
return n
|
|
}
|