@maizzle/framework 6.0.0-rc.1 → 6.0.0-rc.2

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.
Files changed (207) hide show
  1. package/bin/maizzle.mjs +1 -1
  2. package/dist/build.mjs +2 -1
  3. package/dist/build.mjs.map +1 -1
  4. package/dist/config/index.mjs +7 -0
  5. package/dist/config/index.mjs.map +1 -1
  6. package/dist/render/createRenderer.d.mts +2 -0
  7. package/dist/render/createRenderer.d.mts.map +1 -1
  8. package/dist/render/createRenderer.mjs +7 -2
  9. package/dist/render/createRenderer.mjs.map +1 -1
  10. package/dist/render/index.mjs +2 -1
  11. package/dist/render/index.mjs.map +1 -1
  12. package/dist/serve.mjs +2 -1
  13. package/dist/serve.mjs.map +1 -1
  14. package/dist/types/config.d.mts +3 -0
  15. package/dist/types/config.d.mts.map +1 -1
  16. package/node_modules/@clack/core/CHANGELOG.md +87 -4
  17. package/node_modules/@clack/core/README.md +1 -1
  18. package/node_modules/@clack/core/dist/index.d.mts +186 -48
  19. package/node_modules/@clack/core/dist/index.mjs +10 -14
  20. package/node_modules/@clack/core/dist/index.mjs.map +1 -1
  21. package/node_modules/@clack/core/package.json +7 -9
  22. package/node_modules/@clack/prompts/CHANGELOG.md +171 -7
  23. package/node_modules/@clack/prompts/README.md +66 -3
  24. package/node_modules/@clack/prompts/dist/index.d.mts +302 -76
  25. package/node_modules/@clack/prompts/dist/index.mjs +134 -84
  26. package/node_modules/@clack/prompts/dist/index.mjs.map +1 -1
  27. package/node_modules/@clack/prompts/package.json +14 -10
  28. package/node_modules/citty/LICENSE +0 -15
  29. package/node_modules/citty/README.md +166 -69
  30. package/node_modules/citty/dist/index.d.mts +88 -56
  31. package/node_modules/citty/dist/index.mjs +399 -437
  32. package/node_modules/citty/package.json +28 -35
  33. package/node_modules/giget/README.md +59 -11
  34. package/node_modules/giget/dist/THIRD-PARTY-LICENSES.md +205 -0
  35. package/node_modules/giget/dist/_chunks/giget.mjs +508 -0
  36. package/node_modules/giget/dist/_chunks/libs/citty.mjs +269 -0
  37. package/node_modules/giget/dist/_chunks/libs/nypm.d.mts +1 -0
  38. package/node_modules/giget/dist/_chunks/libs/nypm.mjs +669 -0
  39. package/node_modules/giget/dist/_chunks/libs/tar.mjs +2931 -0
  40. package/node_modules/giget/dist/_chunks/rolldown-runtime.mjs +14 -0
  41. package/node_modules/giget/dist/cli.d.mts +1 -0
  42. package/node_modules/giget/dist/cli.mjs +89 -111
  43. package/node_modules/giget/dist/index.d.mts +46 -35
  44. package/node_modules/giget/dist/index.mjs +2 -22
  45. package/node_modules/giget/package.json +32 -45
  46. package/node_modules/maizzle/README.md +140 -0
  47. package/node_modules/maizzle/bin/maizzle.mjs +5 -0
  48. package/node_modules/maizzle/dist/commands/new.d.mts +7 -0
  49. package/node_modules/maizzle/dist/commands/new.mjs +278 -0
  50. package/node_modules/{@maizzle/cli → maizzle}/dist/index.d.mts +1 -1
  51. package/node_modules/maizzle/dist/index.mjs +44 -0
  52. package/node_modules/{commander → maizzle/node_modules/commander}/Readme.md +94 -67
  53. package/node_modules/{commander → maizzle/node_modules/commander}/lib/argument.js +5 -4
  54. package/node_modules/{commander → maizzle/node_modules/commander}/lib/command.js +154 -39
  55. package/node_modules/{commander → maizzle/node_modules/commander}/lib/help.js +77 -39
  56. package/node_modules/{commander → maizzle/node_modules/commander}/lib/option.js +16 -3
  57. package/node_modules/{commander → maizzle/node_modules/commander}/package-support.json +4 -1
  58. package/node_modules/{commander → maizzle/node_modules/commander}/package.json +8 -8
  59. package/node_modules/{commander → maizzle/node_modules/commander}/typings/index.d.ts +71 -3
  60. package/node_modules/{@maizzle/cli → maizzle}/package.json +13 -11
  61. package/node_modules/tinyexec/README.md +49 -3
  62. package/node_modules/tinyexec/dist/main.d.mts +25 -14
  63. package/node_modules/tinyexec/dist/main.mjs +148 -100
  64. package/node_modules/tinyexec/package.json +9 -8
  65. package/package.json +3 -3
  66. package/node_modules/@clack/core/dist/index.cjs +0 -15
  67. package/node_modules/@clack/core/dist/index.cjs.map +0 -1
  68. package/node_modules/@clack/core/dist/index.d.cts +0 -211
  69. package/node_modules/@clack/core/dist/index.d.ts +0 -211
  70. package/node_modules/@clack/prompts/dist/index.cjs +0 -87
  71. package/node_modules/@clack/prompts/dist/index.cjs.map +0 -1
  72. package/node_modules/@clack/prompts/dist/index.d.cts +0 -165
  73. package/node_modules/@clack/prompts/dist/index.d.ts +0 -165
  74. package/node_modules/@maizzle/cli/README.md +0 -58
  75. package/node_modules/@maizzle/cli/dist/index.mjs +0 -42
  76. package/node_modules/citty/dist/index.cjs +0 -475
  77. package/node_modules/citty/dist/index.d.cts +0 -80
  78. package/node_modules/citty/dist/index.d.ts +0 -80
  79. package/node_modules/consola/LICENSE +0 -47
  80. package/node_modules/consola/README.md +0 -352
  81. package/node_modules/consola/basic.d.ts +0 -1
  82. package/node_modules/consola/browser.d.ts +0 -1
  83. package/node_modules/consola/core.d.ts +0 -1
  84. package/node_modules/consola/dist/basic.cjs +0 -32
  85. package/node_modules/consola/dist/basic.d.cts +0 -23
  86. package/node_modules/consola/dist/basic.d.mts +0 -21
  87. package/node_modules/consola/dist/basic.d.ts +0 -23
  88. package/node_modules/consola/dist/basic.mjs +0 -24
  89. package/node_modules/consola/dist/browser.cjs +0 -84
  90. package/node_modules/consola/dist/browser.d.cts +0 -23
  91. package/node_modules/consola/dist/browser.d.mts +0 -21
  92. package/node_modules/consola/dist/browser.d.ts +0 -23
  93. package/node_modules/consola/dist/browser.mjs +0 -76
  94. package/node_modules/consola/dist/chunks/prompt.cjs +0 -288
  95. package/node_modules/consola/dist/chunks/prompt.mjs +0 -280
  96. package/node_modules/consola/dist/core.cjs +0 -517
  97. package/node_modules/consola/dist/core.d.cts +0 -459
  98. package/node_modules/consola/dist/core.d.mts +0 -459
  99. package/node_modules/consola/dist/core.d.ts +0 -459
  100. package/node_modules/consola/dist/core.mjs +0 -512
  101. package/node_modules/consola/dist/index.cjs +0 -663
  102. package/node_modules/consola/dist/index.d.cts +0 -24
  103. package/node_modules/consola/dist/index.d.mts +0 -22
  104. package/node_modules/consola/dist/index.d.ts +0 -24
  105. package/node_modules/consola/dist/index.mjs +0 -651
  106. package/node_modules/consola/dist/shared/consola.DCGIlDNP.cjs +0 -75
  107. package/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +0 -72
  108. package/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +0 -288
  109. package/node_modules/consola/dist/shared/consola.DwRq1yyg.cjs +0 -312
  110. package/node_modules/consola/dist/utils.cjs +0 -64
  111. package/node_modules/consola/dist/utils.d.cts +0 -286
  112. package/node_modules/consola/dist/utils.d.mts +0 -286
  113. package/node_modules/consola/dist/utils.d.ts +0 -286
  114. package/node_modules/consola/dist/utils.mjs +0 -54
  115. package/node_modules/consola/lib/index.cjs +0 -10
  116. package/node_modules/consola/package.json +0 -136
  117. package/node_modules/consola/utils.d.ts +0 -1
  118. package/node_modules/create-maizzle/README.md +0 -86
  119. package/node_modules/create-maizzle/bin/create-maizzle.mjs +0 -4
  120. package/node_modules/create-maizzle/node_modules/@clack/core/CHANGELOG.md +0 -340
  121. package/node_modules/create-maizzle/node_modules/@clack/core/LICENSE +0 -9
  122. package/node_modules/create-maizzle/node_modules/@clack/core/README.md +0 -22
  123. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.d.mts +0 -349
  124. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs +0 -11
  125. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs.map +0 -1
  126. package/node_modules/create-maizzle/node_modules/@clack/core/package.json +0 -60
  127. package/node_modules/create-maizzle/node_modules/@clack/prompts/CHANGELOG.md +0 -576
  128. package/node_modules/create-maizzle/node_modules/@clack/prompts/LICENSE +0 -9
  129. package/node_modules/create-maizzle/node_modules/@clack/prompts/README.md +0 -270
  130. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.d.mts +0 -391
  131. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs +0 -137
  132. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs.map +0 -1
  133. package/node_modules/create-maizzle/node_modules/@clack/prompts/package.json +0 -65
  134. package/node_modules/create-maizzle/package.json +0 -47
  135. package/node_modules/create-maizzle/src/index.js +0 -242
  136. package/node_modules/defu/LICENSE +0 -21
  137. package/node_modules/defu/README.md +0 -171
  138. package/node_modules/defu/dist/defu.cjs +0 -77
  139. package/node_modules/defu/dist/defu.d.cts +0 -31
  140. package/node_modules/defu/dist/defu.d.mts +0 -29
  141. package/node_modules/defu/dist/defu.d.ts +0 -31
  142. package/node_modules/defu/dist/defu.mjs +0 -69
  143. package/node_modules/defu/lib/defu.cjs +0 -10
  144. package/node_modules/defu/lib/defu.d.cts +0 -12
  145. package/node_modules/defu/package.json +0 -48
  146. package/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs +0 -468
  147. package/node_modules/node-fetch-native/LICENSE +0 -114
  148. package/node_modules/node-fetch-native/README.md +0 -225
  149. package/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +0 -2
  150. package/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +0 -2
  151. package/node_modules/node-fetch-native/dist/index.cjs +0 -1
  152. package/node_modules/node-fetch-native/dist/index.mjs +0 -1
  153. package/node_modules/node-fetch-native/dist/native.cjs +0 -1
  154. package/node_modules/node-fetch-native/dist/native.mjs +0 -1
  155. package/node_modules/node-fetch-native/dist/node.cjs +0 -19
  156. package/node_modules/node-fetch-native/dist/node.mjs +0 -19
  157. package/node_modules/node-fetch-native/dist/polyfill.cjs +0 -1
  158. package/node_modules/node-fetch-native/dist/polyfill.mjs +0 -1
  159. package/node_modules/node-fetch-native/dist/proxy-stub.cjs +0 -1
  160. package/node_modules/node-fetch-native/dist/proxy-stub.mjs +0 -1
  161. package/node_modules/node-fetch-native/dist/proxy.cjs +0 -58
  162. package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +0 -1
  163. package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DhEqb06g.cjs +0 -1
  164. package/node_modules/node-fetch-native/index.d.ts +0 -1
  165. package/node_modules/node-fetch-native/lib/empty.cjs +0 -0
  166. package/node_modules/node-fetch-native/lib/empty.mjs +0 -0
  167. package/node_modules/node-fetch-native/lib/index.cjs +0 -11
  168. package/node_modules/node-fetch-native/lib/index.d.cts +0 -10
  169. package/node_modules/node-fetch-native/lib/index.d.mts +0 -10
  170. package/node_modules/node-fetch-native/lib/index.d.ts +0 -10
  171. package/node_modules/node-fetch-native/lib/native.cjs +0 -11
  172. package/node_modules/node-fetch-native/lib/polyfill.d.cts +0 -1
  173. package/node_modules/node-fetch-native/lib/polyfill.d.mts +0 -1
  174. package/node_modules/node-fetch-native/lib/polyfill.d.ts +0 -1
  175. package/node_modules/node-fetch-native/lib/proxy.d.ts +0 -32
  176. package/node_modules/node-fetch-native/node.d.ts +0 -1
  177. package/node_modules/node-fetch-native/package.json +0 -138
  178. package/node_modules/node-fetch-native/polyfill.d.ts +0 -1
  179. package/node_modules/node-fetch-native/proxy.d.ts +0 -1
  180. package/node_modules/nypm/node_modules/citty/LICENSE +0 -21
  181. package/node_modules/nypm/node_modules/citty/README.md +0 -231
  182. package/node_modules/nypm/node_modules/citty/dist/index.d.mts +0 -112
  183. package/node_modules/nypm/node_modules/citty/dist/index.mjs +0 -425
  184. package/node_modules/nypm/node_modules/citty/package.json +0 -42
  185. /package/node_modules/{nypm/node_modules/citty → citty}/dist/THIRD-PARTY-LICENSES.md +0 -0
  186. /package/node_modules/{nypm/node_modules/citty → citty}/dist/_chunks/libs/scule.mjs +0 -0
  187. /package/node_modules/{@maizzle/cli → maizzle}/LICENSE +0 -0
  188. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.d.mts +0 -0
  189. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.mjs +0 -0
  190. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.d.mts +0 -0
  191. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.mjs +0 -0
  192. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.d.mts +0 -0
  193. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.mjs +0 -0
  194. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.d.mts +0 -0
  195. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.mjs +0 -0
  196. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/component.vue +0 -0
  197. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/config.ts +0 -0
  198. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/layout.vue +0 -0
  199. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/template.vue +0 -0
  200. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.d.mts +0 -0
  201. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.mjs +0 -0
  202. /package/node_modules/{commander → maizzle/node_modules/commander}/LICENSE +0 -0
  203. /package/node_modules/{commander → maizzle/node_modules/commander}/esm.mjs +0 -0
  204. /package/node_modules/{commander → maizzle/node_modules/commander}/index.js +0 -0
  205. /package/node_modules/{commander → maizzle/node_modules/commander}/lib/error.js +0 -0
  206. /package/node_modules/{commander → maizzle/node_modules/commander}/lib/suggestSimilar.js +0 -0
  207. /package/node_modules/{commander → maizzle/node_modules/commander}/typings/esm.d.mts +0 -0
@@ -1,50 +1,27 @@
1
1
  # 🌆 citty
2
2
 
3
- [![npm version][npm-version-src]][npm-version-href]
4
- [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![bundle][bundle-src]][bundle-href]
6
- [![Codecov][codecov-src]][codecov-href]
7
- [![License][license-src]][license-href]
3
+ <!-- automd:badges color=yellow bundlephobia -->
8
4
 
9
- > Elegant CLI Builder
5
+ [![npm version](https://img.shields.io/npm/v/citty?color=yellow)](https://npmjs.com/package/citty)
6
+ [![npm downloads](https://img.shields.io/npm/dm/citty?color=yellow)](https://npmjs.com/package/citty)
7
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/citty?color=yellow)](https://bundlephobia.com/package/citty)
10
8
 
11
- - Fast and lightweight argument parser based on [mri](https://github.com/lukeed/mri)
12
- - Smart value parsing with typecast, boolean shortcuts and unknown flag handling
13
- - Nested sub-commands
14
- - Lazy and Async commands
15
- - Plugable and composable API
16
- - Auto generated usage and help
9
+ <!-- /automd -->
17
10
 
18
- 🚧 This project is under heavy development. More features are coming soon!
11
+ Elegant CLI Builder
19
12
 
20
- ## Usage
13
+ - Zero dependency, fast and lightweight (based on native [`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig))
14
+ - Smart value parsing with typecast and boolean shortcuts
15
+ - Nested sub-commands with lazy and async loading
16
+ - Pluggable and composable API with auto generated usage
21
17
 
22
- Install package:
18
+ ## Usage
23
19
 
24
20
  ```sh
25
- # npm
26
- npm install citty
27
-
28
- # yarn
29
- yarn add citty
30
-
31
- # pnpm
32
- pnpm install citty
21
+ npx nypm add -D citty
33
22
  ```
34
23
 
35
- Import:
36
-
37
24
  ```js
38
- // ESM
39
- import { defineCommand, runMain } from "citty";
40
-
41
- // CommonJS
42
- const { defineCommand, runMain } = require("citty");
43
- ```
44
-
45
- Define main command to run:
46
-
47
- ```ts
48
25
  import { defineCommand, runMain } from "citty";
49
26
 
50
27
  const main = defineCommand({
@@ -64,6 +41,12 @@ const main = defineCommand({
64
41
  description: "Use friendly greeting",
65
42
  },
66
43
  },
44
+ setup({ args }) {
45
+ console.log(`now setup ${args.command}`);
46
+ },
47
+ cleanup({ args }) {
48
+ console.log(`now cleanup ${args.command}`);
49
+ },
67
50
  run({ args }) {
68
51
  console.log(`${args.friendly ? "Hi" : "Greetings"} ${args.name}!`);
69
52
  },
@@ -72,35 +55,168 @@ const main = defineCommand({
72
55
  runMain(main);
73
56
  ```
74
57
 
75
- ## Utils
58
+ ```sh
59
+ node index.mjs john
60
+ # Greetings john!
61
+ ```
76
62
 
77
- ### `defineCommand`
63
+ ### Sub Commands
78
64
 
79
- `defineCommand` is a type helper for defining commands.
65
+ Sub commands can be nested recursively. Use lazy imports for large CLIs to avoid loading all commands at once.
80
66
 
81
- ### `runMain`
67
+ ```js
68
+ import { defineCommand, runMain } from "citty";
82
69
 
83
- Runs a command with usage support and graceful error handling.
70
+ const sub = defineCommand({
71
+ meta: { name: "sub", description: "Sub command" },
72
+ args: {
73
+ name: { type: "positional", description: "Your name", required: true },
74
+ },
75
+ run({ args }) {
76
+ console.log(`Hello ${args.name}!`);
77
+ },
78
+ });
84
79
 
85
- ### `createMain`
80
+ const main = defineCommand({
81
+ meta: { name: "hello", version: "1.0.0", description: "My Awesome CLI App" },
82
+ subCommands: { sub },
83
+ });
84
+
85
+ runMain(main);
86
+ ```
86
87
 
87
- Create a wrapper around command that calls `runMain` when called.
88
+ Subcommands support `meta.alias` (e.g., `["i", "add"]`) and `meta.hidden: true` to hide from help output.
88
89
 
89
- ### `runCommand`
90
+ ### Lazy Commands
91
+
92
+ For large CLIs, lazy load sub commands so only the executed command is imported:
93
+
94
+ ```js
95
+ const main = defineCommand({
96
+ meta: { name: "hello", version: "1.0.0", description: "My Awesome CLI App" },
97
+ subCommands: {
98
+ sub: () => import("./sub.mjs").then((m) => m.default),
99
+ },
100
+ });
101
+ ```
90
102
 
91
- Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returnd/awaited value to access command's result.
103
+ `meta`, `args`, and `subCommands` all accept `Resolvable<T>` values a value, Promise, function, or async function enabling lazy and dynamic resolution.
92
104
 
93
- ### `parseArgs`
105
+ ### Hooks
94
106
 
95
- Parses input arguments and applies defaults.
107
+ Commands support `setup` and `cleanup` functions called before and after `run()`. Only the executed command's hooks run. `cleanup` always runs, even if `run()` throws.
96
108
 
97
- ### `renderUsage`
109
+ ```js
110
+ const main = defineCommand({
111
+ meta: { name: "hello", version: "1.0.0", description: "My Awesome CLI App" },
112
+ setup() {
113
+ console.log("Setting up...");
114
+ },
115
+ cleanup() {
116
+ console.log("Cleaning up...");
117
+ },
118
+ run() {
119
+ console.log("Hello World!");
120
+ },
121
+ });
122
+ ```
98
123
 
99
- Renders command usage to a string value.
124
+ ### Plugins
100
125
 
101
- ### `showUsage`
126
+ Plugins extend commands with reusable `setup` and `cleanup` hooks:
102
127
 
103
- Renders usage and prints to the console
128
+ ```js
129
+ import { defineCommand, defineCittyPlugin, runMain } from "citty";
130
+
131
+ const logger = defineCittyPlugin({
132
+ name: "logger",
133
+ setup({ args }) {
134
+ console.log("Logger setup, args:", args);
135
+ },
136
+ cleanup() {
137
+ console.log("Logger cleanup");
138
+ },
139
+ });
140
+
141
+ const main = defineCommand({
142
+ meta: { name: "hello", description: "My CLI App" },
143
+ plugins: [logger],
144
+ run() {
145
+ console.log("Hello!");
146
+ },
147
+ });
148
+
149
+ runMain(main);
150
+ ```
151
+
152
+ Plugin `setup` hooks run before the command's `setup` (in order), `cleanup` hooks run after (in reverse). Plugins can be async or factory functions.
153
+
154
+ ## Arguments
155
+
156
+ ### Argument Types
157
+
158
+ | Type | Description | Example |
159
+ | ------------ | ---------------------------------------- | --------------------------- |
160
+ | `positional` | Unnamed positional args | `cli <name>` |
161
+ | `string` | Named string options | `--name value` |
162
+ | `boolean` | Boolean flags, supports `--no-` negation | `--verbose` |
163
+ | `enum` | Constrained to `options` array | `--level=info\|warn\|error` |
164
+
165
+ ### Common Options
166
+
167
+ | Option | Description |
168
+ | ------------- | ------------------------------------------------------------- |
169
+ | `description` | Help text shown in usage output |
170
+ | `required` | Whether the argument is required |
171
+ | `default` | Default value when not provided |
172
+ | `alias` | Short aliases (e.g., `["f"]`). Not for `positional` |
173
+ | `valueHint` | Display hint in help (e.g., `"host"` renders `--name=<host>`) |
174
+
175
+ ### Example
176
+
177
+ ```js
178
+ const main = defineCommand({
179
+ args: {
180
+ name: { type: "positional", description: "Your name", required: true },
181
+ friendly: { type: "boolean", description: "Use friendly greeting", alias: ["f"] },
182
+ greeting: { type: "string", description: "Custom greeting", default: "Hello" },
183
+ level: {
184
+ type: "enum",
185
+ description: "Log level",
186
+ options: ["debug", "info", "warn", "error"],
187
+ default: "info",
188
+ },
189
+ },
190
+ run({ args }) {
191
+ console.log(`${args.greeting} ${args.name}! (level: ${args.level})`);
192
+ },
193
+ });
194
+ ```
195
+
196
+ ### Boolean Negation
197
+
198
+ Boolean args support `--no-` prefix. The negative variant appears in help when `default: true` or `negativeDescription` is set.
199
+
200
+ ### Case-Agnostic Access
201
+
202
+ Kebab-case args can be accessed as camelCase: `args["output-dir"]` and `args.outputDir` both work.
203
+
204
+ ## Built-in Flags
205
+
206
+ `--help` / `-h` and `--version` / `-v` are handled automatically. Disabled if your command defines args with the same names or aliases.
207
+
208
+ ## API
209
+
210
+ | Function | Description |
211
+ | ----------------------------- | -------------------------------------------------------------------------- |
212
+ | `defineCommand(def)` | Type helper for defining commands |
213
+ | `runMain(cmd, opts?)` | Run a command with usage support and graceful error handling |
214
+ | `createMain(cmd)` | Create a wrapper that calls `runMain` when invoked |
215
+ | `runCommand(cmd, opts)` | Parse args and run command/sub-commands; access `result` from return value |
216
+ | `parseArgs(rawArgs, argsDef)` | Parse input arguments and apply defaults |
217
+ | `renderUsage(cmd, parent?)` | Render command usage to a string |
218
+ | `showUsage(cmd, parent?)` | Render usage and print to console |
219
+ | `defineCittyPlugin(def)` | Type helper for defining plugins |
104
220
 
105
221
  ## Development
106
222
 
@@ -113,22 +229,3 @@ Renders usage and prints to the console
113
229
  ## License
114
230
 
115
231
  Made with 💛 Published under [MIT License](./LICENSE).
116
-
117
- Argument parser is based on [lukeed/mri](https://github.com/lukeed/mri) by Luke Edwards ([@lukeed](https://github.com/lukeed)).
118
-
119
- <!-- Badges -->
120
-
121
- <!-- Badges -->
122
-
123
- [npm-version-src]: https://img.shields.io/npm/v/citty?style=flat&colorA=18181B&colorB=F0DB4F
124
- [npm-version-href]: https://npmjs.com/package/citty
125
- [npm-downloads-src]: https://img.shields.io/npm/dm/citty?style=flat&colorA=18181B&colorB=F0DB4F
126
- [npm-downloads-href]: https://npmjs.com/package/citty
127
- [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/citty/main?style=flat&colorA=18181B&colorB=F0DB4F
128
- [codecov-href]: https://codecov.io/gh/unjs/citty
129
- [bundle-src]: https://img.shields.io/bundlephobia/minzip/citty?style=flat&colorA=18181B&colorB=F0DB4F
130
- [bundle-href]: https://bundlephobia.com/result?p=citty
131
- [license-src]: https://img.shields.io/github/license/unjs/citty.svg?style=flat&colorA=18181B&colorB=F0DB4F
132
- [license-href]: https://github.com/unjs/citty/blob/main/LICENSE
133
- [jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
134
- [jsdocs-href]: https://www.jsdocs.io/package/citty
@@ -1,80 +1,112 @@
1
- type ArgType = "boolean" | "string" | "positional" | undefined;
2
- type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
- type?: T;
4
- description?: string;
5
- valueHint?: string;
6
- alias?: string | string[];
7
- default?: VT;
8
- required?: boolean;
1
+ //#region src/types.d.ts
2
+ type ArgType = "boolean" | "string" | "enum" | "positional" | undefined;
3
+ type _ArgDef<T extends ArgType, VT extends boolean | number | string> = {
4
+ type?: T;
5
+ description?: string;
6
+ valueHint?: string;
7
+ alias?: string | string[];
8
+ default?: VT;
9
+ required?: boolean;
10
+ options?: string[];
9
11
  };
10
- type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
- type StringArgDef = _ArgDef<"string", string>;
12
- type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
- type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
12
+ type BooleanArgDef = Omit<_ArgDef<"boolean", boolean>, "options"> & {
13
+ negativeDescription?: string;
14
+ };
15
+ type StringArgDef = Omit<_ArgDef<"string", string>, "options">;
16
+ type EnumArgDef = _ArgDef<"enum", string>;
17
+ type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias" | "options">;
18
+ type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef | EnumArgDef;
14
19
  type ArgsDef = Record<string, ArgDef>;
15
20
  type Arg = ArgDef & {
16
- name: string;
17
- alias: string[];
21
+ name: string;
22
+ alias: string[];
23
+ };
24
+ type ResolveParsedArgType<T extends ArgDef, VT> = T extends {
25
+ default?: any;
26
+ required?: boolean;
27
+ } ? T["default"] extends NonNullable<VT> ? VT : T["required"] extends true ? VT : VT | undefined : VT | undefined;
28
+ type ParsedPositionalArg<T extends ArgDef> = T extends {
29
+ type: "positional";
30
+ } ? ResolveParsedArgType<T, string> : never;
31
+ type ParsedStringArg<T extends ArgDef> = T extends {
32
+ type: "string";
33
+ } ? ResolveParsedArgType<T, string> : never;
34
+ type ParsedBooleanArg<T extends ArgDef> = T extends {
35
+ type: "boolean";
36
+ } ? ResolveParsedArgType<T, boolean> : never;
37
+ type ParsedEnumArg<T extends ArgDef> = T extends {
38
+ type: "enum";
39
+ options: infer U;
40
+ } ? U extends Array<any> ? ResolveParsedArgType<T, U[number]> : never : never;
41
+ type RawArgs = {
42
+ _: string[];
18
43
  };
19
- type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
- _: string[];
21
- } & Record<{
22
- [K in keyof T]: T[K] extends {
23
- type: "positional";
24
- } ? K : never;
25
- }[keyof T], string> & Record<{
26
- [K in keyof T]: T[K] extends {
27
- type: "string";
28
- } ? K : never;
29
- }[keyof T], string> & Record<{
30
- [K in keyof T]: T[K] extends {
31
- type: "boolean";
32
- } ? K : never;
33
- }[keyof T], boolean> & Record<string, string | boolean | string[]>;
44
+ type ParsedArg<T extends ArgDef> = T["type"] extends "positional" ? ParsedPositionalArg<T> : T["type"] extends "boolean" ? ParsedBooleanArg<T> : T["type"] extends "string" ? ParsedStringArg<T> : T["type"] extends "enum" ? ParsedEnumArg<T> : never;
45
+ type ParsedArgs<T extends ArgsDef = ArgsDef> = RawArgs & { [K in keyof T]: ParsedArg<T[K]> } & { [K in keyof T as T[K] extends {
46
+ alias: string;
47
+ } ? T[K]["alias"] : never]: ParsedArg<T[K]> } & { [K in keyof T as T[K] extends {
48
+ alias: string[];
49
+ } ? T[K]["alias"][number] : never]: ParsedArg<T[K]> } & Record<string, string | number | boolean | string[]>;
34
50
  interface CommandMeta {
35
- name?: string;
36
- version?: string;
37
- description?: string;
51
+ name?: string;
52
+ version?: string;
53
+ description?: string;
54
+ hidden?: boolean;
55
+ alias?: string | string[];
38
56
  }
39
57
  type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
58
  type CommandDef<T extends ArgsDef = ArgsDef> = {
41
- meta?: Resolvable<CommandMeta>;
42
- args?: Resolvable<T>;
43
- subCommands?: Resolvable<SubCommandsDef>;
44
- setup?: (context: CommandContext<T>) => any | Promise<any>;
45
- cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
- run?: (context: CommandContext<T>) => any | Promise<any>;
59
+ meta?: Resolvable<CommandMeta>;
60
+ args?: Resolvable<T>;
61
+ default?: Resolvable<string>;
62
+ subCommands?: Resolvable<SubCommandsDef>;
63
+ plugins?: Resolvable<CittyPlugin>[];
64
+ setup?: (context: CommandContext<T>) => any | Promise<any>;
65
+ cleanup?: (context: CommandContext<T>) => any | Promise<any>;
66
+ run?: (context: CommandContext<T>) => any | Promise<any>;
47
67
  };
48
68
  type CommandContext<T extends ArgsDef = ArgsDef> = {
49
- rawArgs: string[];
50
- args: ParsedArgs<T>;
51
- cmd: CommandDef<T>;
52
- subCommand?: CommandDef<T>;
53
- data?: any;
69
+ rawArgs: string[];
70
+ args: ParsedArgs<T>;
71
+ cmd: CommandDef<T>;
72
+ subCommand?: CommandDef<T>;
73
+ data?: any;
74
+ };
75
+ type CittyPlugin = {
76
+ name: string;
77
+ setup?(context: CommandContext<any>): void | Promise<void>;
78
+ cleanup?(context: CommandContext<any>): void | Promise<void>;
54
79
  };
55
80
  type Awaitable<T> = () => T | Promise<T>;
56
81
  type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
-
58
- declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
82
+ //#endregion
83
+ //#region src/command.d.ts
84
+ declare function defineCommand<const T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
85
  interface RunCommandOptions {
60
- rawArgs: string[];
61
- data?: any;
62
- showUsage?: boolean;
86
+ rawArgs: string[];
87
+ data?: any;
88
+ showUsage?: boolean;
63
89
  }
64
90
  declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
- result: unknown;
91
+ result: unknown;
66
92
  }>;
67
-
93
+ //#endregion
94
+ //#region src/usage.d.ts
68
95
  declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
96
  declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
-
97
+ //#endregion
98
+ //#region src/main.d.ts
71
99
  interface RunMainOptions {
72
- rawArgs?: string[];
73
- showUsage?: typeof showUsage;
100
+ rawArgs?: string[];
101
+ showUsage?: typeof showUsage;
74
102
  }
75
103
  declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
104
  declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
-
105
+ //#endregion
106
+ //#region src/args.d.ts
78
107
  declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
-
80
- export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
108
+ //#endregion
109
+ //#region src/plugin.d.ts
110
+ declare function defineCittyPlugin(plugin: Resolvable<CittyPlugin>): Resolvable<CittyPlugin>;
111
+ //#endregion
112
+ export { Arg, ArgDef, ArgType, ArgsDef, Awaitable, BooleanArgDef, CittyPlugin, CommandContext, CommandDef, CommandMeta, EnumArgDef, ParsedArgs, PositionalArgDef, Resolvable, type RunCommandOptions, type RunMainOptions, StringArgDef, SubCommandsDef, _ArgDef, createMain, defineCittyPlugin, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };