@optique/run 0.1.0-dev.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,30 +2,25 @@
|
|
|
2
2
|
============
|
|
3
3
|
|
|
4
4
|
> [!CAUTION]
|
|
5
|
-
> Optique is currently in early development
|
|
6
|
-
>
|
|
7
|
-
> and there may be bugs or missing features.
|
|
5
|
+
> Optique is currently in early development and may change significantly.
|
|
6
|
+
> Expect breaking changes as we refine the API and features.
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
that automatically handles `process.argv`, `process.exit()`, and terminal
|
|
13
|
-
capabilities. It eliminates the manual setup required by the core library,
|
|
14
|
-
making it perfect for building CLI applications in server-side JavaScript
|
|
15
|
-
runtimes.
|
|
8
|
+
Process-integrated CLI parser for Node.js, Bun, and Deno that provides a
|
|
9
|
+
batteries-included interface for *@optique/core* with automatic `process.argv`
|
|
10
|
+
handling, `process.exit()`, and terminal capabilities.
|
|
16
11
|
|
|
17
12
|
|
|
18
13
|
When to use @optique/run
|
|
19
14
|
------------------------
|
|
20
15
|
|
|
21
|
-
Use
|
|
16
|
+
Use *@optique/run* when:
|
|
22
17
|
|
|
23
18
|
- Building CLI applications for Node.js, Bun, or Deno
|
|
24
19
|
- You want automatic `process.argv` parsing and `process.exit()` handling
|
|
25
20
|
- You need automatic terminal capability detection (colors, width)
|
|
26
21
|
- You prefer a simple, batteries-included approach
|
|
27
22
|
|
|
28
|
-
Use
|
|
23
|
+
Use *@optique/core* instead when:
|
|
29
24
|
|
|
30
25
|
- Building web applications or libraries
|
|
31
26
|
- You need full control over argument sources and error handling
|
|
@@ -62,12 +57,8 @@ const parser = object({
|
|
|
62
57
|
const config = run(parser);
|
|
63
58
|
|
|
64
59
|
console.log(`Hello ${config.name}!`);
|
|
65
|
-
if (config.age) {
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
if (config.verbose) {
|
|
69
|
-
console.log("Verbose mode enabled.");
|
|
70
|
-
}
|
|
60
|
+
if (config.age) console.log(`You are ${config.age} years old.`);
|
|
61
|
+
if (config.verbose) console.log("Verbose mode enabled.");
|
|
71
62
|
~~~~
|
|
72
63
|
|
|
73
64
|
Run it:
|
|
@@ -79,56 +70,6 @@ You are 25 years old.
|
|
|
79
70
|
Verbose mode enabled.
|
|
80
71
|
~~~~
|
|
81
72
|
|
|
73
|
+
For more resources, see the [docs] and the [*examples/*](/examples/) directory.
|
|
82
74
|
|
|
83
|
-
|
|
84
|
-
----------------------------------
|
|
85
|
-
|
|
86
|
-
| Feature | @optique/core | @optique/run |
|
|
87
|
-
|--------------------|-----------------------------------------|----------------------------------|
|
|
88
|
-
| Argument source | Manual (`run(parser, "program", args)`) | Automatic (`process.argv`) |
|
|
89
|
-
| Error handling | Return value or callback | Automatic `process.exit()` |
|
|
90
|
-
| Help display | Manual implementation | Automatic help option/command |
|
|
91
|
-
| Terminal detection | Manual specification | Automatic TTY/width detection |
|
|
92
|
-
| Program name | Manual parameter | Automatic from `process.argv[1]` |
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Configuration options
|
|
96
|
-
---------------------
|
|
97
|
-
|
|
98
|
-
~~~~ typescript
|
|
99
|
-
const result = run(parser, {
|
|
100
|
-
programName: "my-cli", // Override detected program name
|
|
101
|
-
args: ["custom", "args"], // Override process.argv
|
|
102
|
-
colors: true, // Force colored output
|
|
103
|
-
maxWidth: 100, // Set output width
|
|
104
|
-
help: "both", // Enable --help and help command
|
|
105
|
-
aboveError: "usage", // Show usage on errors
|
|
106
|
-
errorExitCode: 1, // Exit code for errors
|
|
107
|
-
});
|
|
108
|
-
~~~~
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Help system
|
|
112
|
-
-----------
|
|
113
|
-
|
|
114
|
-
Enable built-in help functionality:
|
|
115
|
-
|
|
116
|
-
~~~~ typescript
|
|
117
|
-
const result = run(parser, {
|
|
118
|
-
help: "option", // Adds --help option
|
|
119
|
-
help: "command", // Adds help subcommand
|
|
120
|
-
help: "both", // Adds both --help and help command
|
|
121
|
-
help: "none", // No help (default)
|
|
122
|
-
});
|
|
123
|
-
~~~~
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
Error handling
|
|
127
|
-
--------------
|
|
128
|
-
|
|
129
|
-
The `run()` function automatically:
|
|
130
|
-
|
|
131
|
-
- Prints usage information and error messages to stderr
|
|
132
|
-
- Exits with code `0` for help requests
|
|
133
|
-
- Exits with code `1` (or custom) for parse errors
|
|
134
|
-
- Never returns on errors (always calls `process.exit()`)
|
|
75
|
+
[docs]: https://optique.dev/
|