Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toyobayashi/getopt
GNU getopt Node-API binding.
https://github.com/toyobayashi/getopt
Last synced: 12 days ago
JSON representation
GNU getopt Node-API binding.
- Host: GitHub
- URL: https://github.com/toyobayashi/getopt
- Owner: toyobayashi
- Created: 2021-06-27T12:51:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-29T08:58:23.000Z (over 3 years ago)
- Last Synced: 2024-11-05T22:46:19.245Z (2 months ago)
- Language: C
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# getopt
GNU getopt Node-API binding.
```js
const binding = require('@tybys/getopt') // not published yet;(function main (argc, argv) {
let c
while ((c = binding.getopt(argc, argv, 'abc:')) !== -1) {
const char = String.fromCharCode(c)
switch (char) {
case 'a':
console.log('option a')
break
case 'b':
console.log('option b')
break
case 'c':
console.log("option c with value '%s'", binding.optarg === null ? '(null)' : binding.optarg)
break
case '?':
process.exit(1)
default:
console.log(`?? getopt returned character code ${c} ??`)
}
}
if (binding.optind < argc) {
process.stdout.write('non-option ARGV-elements: ')
while (binding.optind < argc)
process.stdout.write('%s ', argv[binding.optind++])
process.stdout.write('\n')
}
process.exit(0)
})(process.argv.length - 1, process.argv.slice(1))
``````ts
declare namespace mod {
export const optarg: string | null;
export let optind: number;
export const optopt: number;
export let opterr: number;export const no_argument: 0;
export const required_argument: 1;
export const optional_argument: 2;export type Pointer = { value: T };
export class Option {
name: string;
has_arg: 0 | 1 | 2;
flag: undefined | null | Pointer;
val: number;
constructor (name: string, hasArg?: 0 | 1 | 2, flag?: null | Pointer, val?: string | number);
}export function getopt (argc: number, argv: string[], shortopts: string): number;
export function getopt_long (argc: number, argv: string[], shortopts: string,
longopts?: Option[], ind?: null | Pointer): number;
export function getopt_long_only (argc: number, argv: string[], shortopts: string,
longopts?: Option[], ind?: null | Pointer): number;
}export = mod;
```