Skip to content

Commit 8a27175

Browse files
committed
📝 Add module documentations to argument
1 parent 95faeeb commit 8a27175

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

denops_std/argument/mod.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,65 @@
11
/**
2-
* A module to handle Vim's command arguments.
2+
* A module to handle Vim's command arguments like the followings.
33
*
4+
* ```vim
5+
* :MyCommand ++enc=sjis ++ff=dos -f --foo=foo --bar=bar --bar=baz hello world
6+
* ```
7+
*
8+
* Developers should utilize `[<f-args>]` in Vim script to acquire the arguments
9+
* as a string array, adhering to the standard Vim command behavior.
10+
*
11+
* For example:
12+
*
13+
* ```vim
14+
* command! -nargs=* MyCommand call denops#request("myplugin", "test", [[<f-args>]])
15+
* ```
16+
*
17+
* Then, developers can use this module to parse, validate, or format the arguments.
18+
*
19+
* ```typescript
20+
* import type { Denops } from "../mod.ts";
21+
* import {
22+
* builtinOpts,
23+
* formatFlags,
24+
* formatOpts,
25+
* parse,
26+
* validateFlags,
27+
* validateOpts,
28+
* } from "./mod.ts";
29+
*
30+
* export async function main(denops: Denops): Promise<void> {
31+
* denops.dispatcher = {
32+
* test(args: unknown) {
33+
* // Parse string array to extract `opts`, `flags`.
34+
* const [opts, flags, residues] = parse(args as string[]);
35+
*
36+
* console.log(opts);
37+
* // { "enc": "sjis", "ff": "dos" }
38+
* console.log(flags);
39+
* // { "f": "", "foo": "foo", "bar": ["bar", "baz"] }
40+
* console.log(residues);
41+
* // ["hello", "world"]
42+
*
43+
* // Validate if `opts` has unknown options
44+
* validateOpts(opts, ["enc", "ff"]);
45+
*
46+
* // Or use `builtinOpts` to validate Vim's builtin `++opts`
47+
* validateOpts(opts, builtinOpts);
48+
*
49+
* // Validate if `flags` has unknown flags
50+
* validateFlags(flags, ["f", "foo", "bar"]);
51+
*
52+
* // Reformat `opts` to string
53+
* console.log(formatOpts(opts));
54+
* // "++enc=sjis ++ff=dos"
55+
*
56+
* // Reformat `flags` to string
57+
* console.log(formatFlags(flags));
58+
* // "-f --foo=foo --bar=bar --bar=baz"
59+
* },
60+
* };
61+
* }
62+
* ```
463
* @module
564
*/
665
import { Opts, parseOpts } from "./opts.ts";

0 commit comments

Comments
 (0)