https://github.com/ocpu/typed-flags-deno
Strictly type your program flags in deno
https://github.com/ocpu/typed-flags-deno
deno flags module
Last synced: about 1 month ago
JSON representation
Strictly type your program flags in deno
- Host: GitHub
- URL: https://github.com/ocpu/typed-flags-deno
- Owner: ocpu
- License: mit
- Created: 2021-05-20T13:50:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-18T07:33:19.000Z (over 4 years ago)
- Last Synced: 2026-02-19T04:40:11.515Z (4 months ago)
- Topics: deno, flags, module
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Typed Flags for Deno
This is a simple module to to declaratively set the type of the flags you accept. It uses the std/flags under the hood so parsing of flags is handled by it and type ensuring is provided by this module. All parts of the flag definition are strictly type defined (you event get some auto completion at places).
```typescript
import { parseFlags } from 'https://deno.land/x/typed_flags@v1.0.1/mod.ts'
const { _: args, ...flags } = parseFlags({
help: Boolean, // Use either of Boolean, String, or Number constructors to define your type
port: { // Make the definition an object if you want to specify more than type
type: Number,
default: 3000, // Default values must be in the type you specify
alias: 'p', // Define an alias or an array of them
},
name: String,
h: 'help', // Another way of specifying an alias to a command (these can be auto completed)
}/*, */)
type MyFlags = typeof flags // { help: boolean, post: number, name: string | undefined }
type MyArgs = typeof args // string[]
```