@ohos-ports/curlconverter 4.12.0-beta.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.
Files changed (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -0
  3. package/dist/src/Headers.d.ts +23 -0
  4. package/dist/src/Headers.js +287 -0
  5. package/dist/src/Headers.js.map +1 -0
  6. package/dist/src/Query.d.ts +8 -0
  7. package/dist/src/Query.js +136 -0
  8. package/dist/src/Query.js.map +1 -0
  9. package/dist/src/Request.d.ts +200 -0
  10. package/dist/src/Request.js +1191 -0
  11. package/dist/src/Request.js.map +1 -0
  12. package/dist/src/Warnings.d.ts +15 -0
  13. package/dist/src/Warnings.js +111 -0
  14. package/dist/src/Warnings.js.map +1 -0
  15. package/dist/src/cli.d.ts +2 -0
  16. package/dist/src/cli.js +333 -0
  17. package/dist/src/cli.js.map +1 -0
  18. package/dist/src/curl/auth.d.ts +12 -0
  19. package/dist/src/curl/auth.js +40 -0
  20. package/dist/src/curl/auth.js.map +1 -0
  21. package/dist/src/curl/form.d.ts +28 -0
  22. package/dist/src/curl/form.js +218 -0
  23. package/dist/src/curl/form.js.map +1 -0
  24. package/dist/src/curl/opts.d.ts +2052 -0
  25. package/dist/src/curl/opts.js +1000 -0
  26. package/dist/src/curl/opts.js.map +1 -0
  27. package/dist/src/curl/url.d.ts +14 -0
  28. package/dist/src/curl/url.js +218 -0
  29. package/dist/src/curl/url.js.map +1 -0
  30. package/dist/src/generators/ansible.d.ts +5 -0
  31. package/dist/src/generators/ansible.js +282 -0
  32. package/dist/src/generators/ansible.js.map +1 -0
  33. package/dist/src/generators/c.d.ts +12 -0
  34. package/dist/src/generators/c.js +1230 -0
  35. package/dist/src/generators/c.js.map +1 -0
  36. package/dist/src/generators/cfml.d.ts +5 -0
  37. package/dist/src/generators/cfml.js +134 -0
  38. package/dist/src/generators/cfml.js.map +1 -0
  39. package/dist/src/generators/clojure.d.ts +7 -0
  40. package/dist/src/generators/clojure.js +436 -0
  41. package/dist/src/generators/clojure.js.map +1 -0
  42. package/dist/src/generators/csharp.d.ts +8 -0
  43. package/dist/src/generators/csharp.js +356 -0
  44. package/dist/src/generators/csharp.js.map +1 -0
  45. package/dist/src/generators/dart.d.ts +5 -0
  46. package/dist/src/generators/dart.js +273 -0
  47. package/dist/src/generators/dart.js.map +1 -0
  48. package/dist/src/generators/elixir.d.ts +8 -0
  49. package/dist/src/generators/elixir.js +296 -0
  50. package/dist/src/generators/elixir.js.map +1 -0
  51. package/dist/src/generators/go.d.ts +5 -0
  52. package/dist/src/generators/go.js +228 -0
  53. package/dist/src/generators/go.js.map +1 -0
  54. package/dist/src/generators/har.d.ts +7 -0
  55. package/dist/src/generators/har.js +115 -0
  56. package/dist/src/generators/har.js.map +1 -0
  57. package/dist/src/generators/http.d.ts +7 -0
  58. package/dist/src/generators/http.js +165 -0
  59. package/dist/src/generators/http.js.map +1 -0
  60. package/dist/src/generators/httpie.d.ts +5 -0
  61. package/dist/src/generators/httpie.js +446 -0
  62. package/dist/src/generators/httpie.js.map +1 -0
  63. package/dist/src/generators/java/httpurlconnection.d.ts +5 -0
  64. package/dist/src/generators/java/httpurlconnection.js +123 -0
  65. package/dist/src/generators/java/httpurlconnection.js.map +1 -0
  66. package/dist/src/generators/java/java.d.ts +8 -0
  67. package/dist/src/generators/java/java.js +247 -0
  68. package/dist/src/generators/java/java.js.map +1 -0
  69. package/dist/src/generators/java/jsoup.d.ts +5 -0
  70. package/dist/src/generators/java/jsoup.js +152 -0
  71. package/dist/src/generators/java/jsoup.js.map +1 -0
  72. package/dist/src/generators/java/okhttp.d.ts +5 -0
  73. package/dist/src/generators/java/okhttp.js +232 -0
  74. package/dist/src/generators/java/okhttp.js.map +1 -0
  75. package/dist/src/generators/javascript/axios.d.ts +5 -0
  76. package/dist/src/generators/javascript/axios.js +332 -0
  77. package/dist/src/generators/javascript/axios.js.map +1 -0
  78. package/dist/src/generators/javascript/got.d.ts +5 -0
  79. package/dist/src/generators/javascript/got.js +277 -0
  80. package/dist/src/generators/javascript/got.js.map +1 -0
  81. package/dist/src/generators/javascript/http.d.ts +8 -0
  82. package/dist/src/generators/javascript/http.js +183 -0
  83. package/dist/src/generators/javascript/http.js.map +1 -0
  84. package/dist/src/generators/javascript/javascript.d.ts +37 -0
  85. package/dist/src/generators/javascript/javascript.js +676 -0
  86. package/dist/src/generators/javascript/javascript.js.map +1 -0
  87. package/dist/src/generators/javascript/jquery.d.ts +15 -0
  88. package/dist/src/generators/javascript/jquery.js +297 -0
  89. package/dist/src/generators/javascript/jquery.js.map +1 -0
  90. package/dist/src/generators/javascript/ky.d.ts +7 -0
  91. package/dist/src/generators/javascript/ky.js +245 -0
  92. package/dist/src/generators/javascript/ky.js.map +1 -0
  93. package/dist/src/generators/javascript/request.d.ts +5 -0
  94. package/dist/src/generators/javascript/request.js +113 -0
  95. package/dist/src/generators/javascript/request.js.map +1 -0
  96. package/dist/src/generators/javascript/superagent.d.ts +10 -0
  97. package/dist/src/generators/javascript/superagent.js +301 -0
  98. package/dist/src/generators/javascript/superagent.js.map +1 -0
  99. package/dist/src/generators/javascript/xhr.d.ts +8 -0
  100. package/dist/src/generators/javascript/xhr.js +147 -0
  101. package/dist/src/generators/javascript/xhr.js.map +1 -0
  102. package/dist/src/generators/json.d.ts +45 -0
  103. package/dist/src/generators/json.js +197 -0
  104. package/dist/src/generators/json.js.map +1 -0
  105. package/dist/src/generators/julia.d.ts +8 -0
  106. package/dist/src/generators/julia.js +365 -0
  107. package/dist/src/generators/julia.js.map +1 -0
  108. package/dist/src/generators/kotlin.d.ts +8 -0
  109. package/dist/src/generators/kotlin.js +325 -0
  110. package/dist/src/generators/kotlin.js.map +1 -0
  111. package/dist/src/generators/lua.d.ts +5 -0
  112. package/dist/src/generators/lua.js +192 -0
  113. package/dist/src/generators/lua.js.map +1 -0
  114. package/dist/src/generators/matlab/common.d.ts +16 -0
  115. package/dist/src/generators/matlab/common.js +238 -0
  116. package/dist/src/generators/matlab/common.js.map +1 -0
  117. package/dist/src/generators/matlab/httpinterface.d.ts +2 -0
  118. package/dist/src/generators/matlab/httpinterface.js +211 -0
  119. package/dist/src/generators/matlab/httpinterface.js.map +1 -0
  120. package/dist/src/generators/matlab/matlab.d.ts +5 -0
  121. package/dist/src/generators/matlab/matlab.js +29 -0
  122. package/dist/src/generators/matlab/matlab.js.map +1 -0
  123. package/dist/src/generators/matlab/webservices.d.ts +2 -0
  124. package/dist/src/generators/matlab/webservices.js +191 -0
  125. package/dist/src/generators/matlab/webservices.js.map +1 -0
  126. package/dist/src/generators/objectivec.d.ts +8 -0
  127. package/dist/src/generators/objectivec.js +269 -0
  128. package/dist/src/generators/objectivec.js.map +1 -0
  129. package/dist/src/generators/ocaml.d.ts +8 -0
  130. package/dist/src/generators/ocaml.js +150 -0
  131. package/dist/src/generators/ocaml.js.map +1 -0
  132. package/dist/src/generators/perl.d.ts +9 -0
  133. package/dist/src/generators/perl.js +209 -0
  134. package/dist/src/generators/perl.js.map +1 -0
  135. package/dist/src/generators/php/guzzle.d.ts +5 -0
  136. package/dist/src/generators/php/guzzle.js +328 -0
  137. package/dist/src/generators/php/guzzle.js.map +1 -0
  138. package/dist/src/generators/php/php.d.ts +8 -0
  139. package/dist/src/generators/php/php.js +217 -0
  140. package/dist/src/generators/php/php.js.map +1 -0
  141. package/dist/src/generators/php/requests.d.ts +5 -0
  142. package/dist/src/generators/php/requests.js +89 -0
  143. package/dist/src/generators/php/requests.js.map +1 -0
  144. package/dist/src/generators/powershell.d.ts +11 -0
  145. package/dist/src/generators/powershell.js +377 -0
  146. package/dist/src/generators/powershell.js.map +1 -0
  147. package/dist/src/generators/python/http.d.ts +5 -0
  148. package/dist/src/generators/python/http.js +128 -0
  149. package/dist/src/generators/python/http.js.map +1 -0
  150. package/dist/src/generators/python/python.d.ts +22 -0
  151. package/dist/src/generators/python/python.js +1693 -0
  152. package/dist/src/generators/python/python.js.map +1 -0
  153. package/dist/src/generators/r/httr.d.ts +10 -0
  154. package/dist/src/generators/r/httr.js +298 -0
  155. package/dist/src/generators/r/httr.js.map +1 -0
  156. package/dist/src/generators/r/httr2.d.ts +5 -0
  157. package/dist/src/generators/r/httr2.js +214 -0
  158. package/dist/src/generators/r/httr2.js.map +1 -0
  159. package/dist/src/generators/ruby/httparty.d.ts +6 -0
  160. package/dist/src/generators/ruby/httparty.js +308 -0
  161. package/dist/src/generators/ruby/httparty.js.map +1 -0
  162. package/dist/src/generators/ruby/ruby.d.ts +14 -0
  163. package/dist/src/generators/ruby/ruby.js +515 -0
  164. package/dist/src/generators/ruby/ruby.js.map +1 -0
  165. package/dist/src/generators/rust.d.ts +8 -0
  166. package/dist/src/generators/rust.js +177 -0
  167. package/dist/src/generators/rust.js.map +1 -0
  168. package/dist/src/generators/swift.d.ts +8 -0
  169. package/dist/src/generators/swift.js +219 -0
  170. package/dist/src/generators/swift.js.map +1 -0
  171. package/dist/src/generators/wget.d.ts +8 -0
  172. package/dist/src/generators/wget.js +472 -0
  173. package/dist/src/generators/wget.js.map +1 -0
  174. package/dist/src/index.d.ts +53 -0
  175. package/dist/src/index.js +54 -0
  176. package/dist/src/index.js.map +1 -0
  177. package/dist/src/parse.d.ts +13 -0
  178. package/dist/src/parse.js +43 -0
  179. package/dist/src/parse.js.map +1 -0
  180. package/dist/src/shell/Parser.d.ts +4 -0
  181. package/dist/src/shell/Parser.js +6 -0
  182. package/dist/src/shell/Parser.js.map +1 -0
  183. package/dist/src/shell/Word.d.ts +48 -0
  184. package/dist/src/shell/Word.js +486 -0
  185. package/dist/src/shell/Word.js.map +1 -0
  186. package/dist/src/shell/tokenizer.d.ts +3 -0
  187. package/dist/src/shell/tokenizer.js +610 -0
  188. package/dist/src/shell/tokenizer.js.map +1 -0
  189. package/dist/src/shell/webParser.d.ts +4 -0
  190. package/dist/src/shell/webParser.js +15 -0
  191. package/dist/src/shell/webParser.js.map +1 -0
  192. package/dist/src/utils.d.ts +6 -0
  193. package/dist/src/utils.js +21 -0
  194. package/dist/src/utils.js.map +1 -0
  195. package/dist/tools/compare-requests.d.ts +2 -0
  196. package/dist/tools/compare-requests.js +448 -0
  197. package/dist/tools/compare-requests.js.map +1 -0
  198. package/dist/tools/gen-test.d.ts +2 -0
  199. package/dist/tools/gen-test.js +114 -0
  200. package/dist/tools/gen-test.js.map +1 -0
  201. package/dist/tree-sitter-bash.wasm +0 -0
  202. package/index.d.ts +3 -0
  203. package/package.json +97 -0
  204. package/src/Headers.ts +334 -0
  205. package/src/Query.ts +147 -0
  206. package/src/Request.ts +1649 -0
  207. package/src/Warnings.ts +154 -0
  208. package/src/cli.ts +561 -0
  209. package/src/curl/auth.ts +45 -0
  210. package/src/curl/form.ts +297 -0
  211. package/src/curl/opts.ts +1417 -0
  212. package/src/curl/url.ts +241 -0
  213. package/src/generators/ansible.ts +364 -0
  214. package/src/generators/c.ts +1371 -0
  215. package/src/generators/cfml.ts +155 -0
  216. package/src/generators/clojure.ts +521 -0
  217. package/src/generators/csharp.ts +383 -0
  218. package/src/generators/dart.ts +293 -0
  219. package/src/generators/elixir.ts +349 -0
  220. package/src/generators/go.ts +269 -0
  221. package/src/generators/har.ts +147 -0
  222. package/src/generators/http.ts +194 -0
  223. package/src/generators/httpie.ts +506 -0
  224. package/src/generators/java/httpurlconnection.ts +151 -0
  225. package/src/generators/java/java.ts +280 -0
  226. package/src/generators/java/jsoup.ts +172 -0
  227. package/src/generators/java/okhttp.ts +257 -0
  228. package/src/generators/javascript/axios.ts +395 -0
  229. package/src/generators/javascript/got.ts +362 -0
  230. package/src/generators/javascript/http.ts +232 -0
  231. package/src/generators/javascript/javascript.ts +825 -0
  232. package/src/generators/javascript/jquery.ts +360 -0
  233. package/src/generators/javascript/ky.ts +315 -0
  234. package/src/generators/javascript/request.ts +152 -0
  235. package/src/generators/javascript/superagent.ts +373 -0
  236. package/src/generators/javascript/xhr.ts +192 -0
  237. package/src/generators/json.ts +293 -0
  238. package/src/generators/julia.ts +398 -0
  239. package/src/generators/kotlin.ts +355 -0
  240. package/src/generators/lua.ts +209 -0
  241. package/src/generators/matlab/common.ts +281 -0
  242. package/src/generators/matlab/httpinterface.ts +284 -0
  243. package/src/generators/matlab/matlab.ts +39 -0
  244. package/src/generators/matlab/webservices.ts +263 -0
  245. package/src/generators/objectivec.ts +297 -0
  246. package/src/generators/ocaml.ts +168 -0
  247. package/src/generators/perl.ts +237 -0
  248. package/src/generators/php/guzzle.ts +368 -0
  249. package/src/generators/php/php.ts +239 -0
  250. package/src/generators/php/requests.ts +103 -0
  251. package/src/generators/powershell.ts +430 -0
  252. package/src/generators/python/http.ts +167 -0
  253. package/src/generators/python/python.ts +1934 -0
  254. package/src/generators/r/httr.ts +328 -0
  255. package/src/generators/r/httr2.ts +268 -0
  256. package/src/generators/ruby/httparty.ts +351 -0
  257. package/src/generators/ruby/ruby.ts +564 -0
  258. package/src/generators/rust.ts +243 -0
  259. package/src/generators/swift.ts +235 -0
  260. package/src/generators/wget.ts +533 -0
  261. package/src/index.ts +89 -0
  262. package/src/parse.ts +72 -0
  263. package/src/shell/Parser.ts +8 -0
  264. package/src/shell/Word.ts +531 -0
  265. package/src/shell/tokenizer.ts +736 -0
  266. package/src/shell/webParser.ts +18 -0
  267. package/src/utils.ts +25 -0
  268. package/tools/compare-requests.ts +571 -0
  269. package/tools/extract_curl_args.py +511 -0
  270. package/tools/gen-test.ts +129 -0
@@ -0,0 +1,1417 @@
1
+ import { CCError, has } from "../utils.js";
2
+ import { Word, eq, firstShellToken } from "../shell/Word.js";
3
+ import { warnf, underlineNode, type Warnings } from "../Warnings.js";
4
+ import {
5
+ CURLAUTH_BASIC,
6
+ CURLAUTH_DIGEST,
7
+ CURLAUTH_NEGOTIATE,
8
+ CURLAUTH_NTLM,
9
+ CURLAUTH_NTLM_WB,
10
+ CURLAUTH_BEARER,
11
+ CURLAUTH_AWS_SIGV4,
12
+ CURLAUTH_ANY,
13
+ } from "./auth.js";
14
+ import type { DataType } from "../Request.js";
15
+
16
+ export type FormType = "string" | "form";
17
+
18
+ export interface LongShort {
19
+ type: "string" | "bool";
20
+ name: string;
21
+ removed?: string;
22
+ expand?: boolean;
23
+ }
24
+
25
+ export interface LongOpts {
26
+ [key: string]: LongShort | null;
27
+ }
28
+
29
+ export interface ShortOpts {
30
+ [key: string]: string;
31
+ }
32
+
33
+ // prettier-ignore
34
+ export const curlLongOpts = {
35
+ // BEGIN EXTRACTED OPTIONS
36
+ "url": { type: "string", name: "url" },
37
+ "dns-ipv4-addr": { type: "string", name: "dns-ipv4-addr" },
38
+ "dns-ipv6-addr": { type: "string", name: "dns-ipv6-addr" },
39
+ "random-file": { type: "string", name: "random-file" },
40
+ "egd-file": { type: "string", name: "egd-file" },
41
+ "oauth2-bearer": { type: "string", name: "oauth2-bearer" },
42
+ "connect-timeout": { type: "string", name: "connect-timeout" },
43
+ "doh-url": { type: "string", name: "doh-url" },
44
+ "ciphers": { type: "string", name: "ciphers" },
45
+ "dns-interface": { type: "string", name: "dns-interface" },
46
+ "disable-epsv": { type: "bool", name: "disable-epsv" },
47
+ "no-disable-epsv": { type: "bool", name: "disable-epsv", expand: false },
48
+ "disallow-username-in-url": { type: "bool", name: "disallow-username-in-url" },
49
+ "no-disallow-username-in-url": { type: "bool", name: "disallow-username-in-url", expand: false },
50
+ "epsv": { type: "bool", name: "epsv" },
51
+ "no-epsv": { type: "bool", name: "epsv", expand: false },
52
+ "dns-servers": { type: "string", name: "dns-servers" },
53
+ "trace": { type: "string", name: "trace" },
54
+ "npn": { type: "bool", name: "npn" },
55
+ "no-npn": { type: "bool", name: "npn", expand: false },
56
+ "trace-ascii": { type: "string", name: "trace-ascii" },
57
+ "alpn": { type: "bool", name: "alpn" },
58
+ "no-alpn": { type: "bool", name: "alpn", expand: false },
59
+ "limit-rate": { type: "string", name: "limit-rate" },
60
+ "rate": { type: "string", name: "rate" },
61
+ "compressed": { type: "bool", name: "compressed" },
62
+ "no-compressed": { type: "bool", name: "compressed", expand: false },
63
+ "tr-encoding": { type: "bool", name: "tr-encoding" },
64
+ "no-tr-encoding": { type: "bool", name: "tr-encoding", expand: false },
65
+ "digest": { type: "bool", name: "digest" },
66
+ "no-digest": { type: "bool", name: "digest", expand: false },
67
+ "negotiate": { type: "bool", name: "negotiate" },
68
+ "no-negotiate": { type: "bool", name: "negotiate", expand: false },
69
+ "ntlm": { type: "bool", name: "ntlm" },
70
+ "no-ntlm": { type: "bool", name: "ntlm", expand: false },
71
+ "ntlm-wb": { type: "bool", name: "ntlm-wb" },
72
+ "no-ntlm-wb": { type: "bool", name: "ntlm-wb", expand: false },
73
+ "basic": { type: "bool", name: "basic" },
74
+ "no-basic": { type: "bool", name: "basic", expand: false },
75
+ "anyauth": { type: "bool", name: "anyauth" },
76
+ "no-anyauth": { type: "bool", name: "anyauth", expand: false },
77
+ "wdebug": { type: "bool", name: "wdebug" },
78
+ "no-wdebug": { type: "bool", name: "wdebug", expand: false },
79
+ "ftp-create-dirs": { type: "bool", name: "ftp-create-dirs" },
80
+ "no-ftp-create-dirs": { type: "bool", name: "ftp-create-dirs", expand: false },
81
+ "create-dirs": { type: "bool", name: "create-dirs" },
82
+ "no-create-dirs": { type: "bool", name: "create-dirs", expand: false },
83
+ "create-file-mode": { type: "string", name: "create-file-mode" },
84
+ "max-redirs": { type: "string", name: "max-redirs" },
85
+ "proxy-ntlm": { type: "bool", name: "proxy-ntlm" },
86
+ "no-proxy-ntlm": { type: "bool", name: "proxy-ntlm", expand: false },
87
+ "crlf": { type: "bool", name: "crlf" },
88
+ "no-crlf": { type: "bool", name: "crlf", expand: false },
89
+ "stderr": { type: "string", name: "stderr" },
90
+ "aws-sigv4": { type: "string", name: "aws-sigv4" },
91
+ "interface": { type: "string", name: "interface" },
92
+ "krb": { type: "string", name: "krb" },
93
+ "krb4": { type: "string", name: "krb" },
94
+ "haproxy-protocol": { type: "bool", name: "haproxy-protocol" },
95
+ "no-haproxy-protocol": { type: "bool", name: "haproxy-protocol", expand: false },
96
+ "haproxy-clientip": { type: "string", name: "haproxy-clientip" },
97
+ "max-filesize": { type: "string", name: "max-filesize" },
98
+ "disable-eprt": { type: "bool", name: "disable-eprt" },
99
+ "no-disable-eprt": { type: "bool", name: "disable-eprt", expand: false },
100
+ "eprt": { type: "bool", name: "eprt" },
101
+ "no-eprt": { type: "bool", name: "eprt", expand: false },
102
+ "xattr": { type: "bool", name: "xattr" },
103
+ "no-xattr": { type: "bool", name: "xattr", expand: false },
104
+ "ftp-ssl": { type: "bool", name: "ssl" },
105
+ "no-ftp-ssl": { type: "bool", name: "ssl", expand: false },
106
+ "ssl": { type: "bool", name: "ssl" },
107
+ "no-ssl": { type: "bool", name: "ssl", expand: false },
108
+ "ftp-pasv": { type: "bool", name: "ftp-pasv" },
109
+ "no-ftp-pasv": { type: "bool", name: "ftp-pasv", expand: false },
110
+ "socks5": { type: "string", name: "socks5" },
111
+ "tcp-nodelay": { type: "bool", name: "tcp-nodelay" },
112
+ "no-tcp-nodelay": { type: "bool", name: "tcp-nodelay", expand: false },
113
+ "proxy-digest": { type: "bool", name: "proxy-digest" },
114
+ "no-proxy-digest": { type: "bool", name: "proxy-digest", expand: false },
115
+ "proxy-basic": { type: "bool", name: "proxy-basic" },
116
+ "no-proxy-basic": { type: "bool", name: "proxy-basic", expand: false },
117
+ "retry": { type: "string", name: "retry" },
118
+ "retry-connrefused": { type: "bool", name: "retry-connrefused" },
119
+ "no-retry-connrefused": { type: "bool", name: "retry-connrefused", expand: false },
120
+ "retry-delay": { type: "string", name: "retry-delay" },
121
+ "retry-max-time": { type: "string", name: "retry-max-time" },
122
+ "proxy-negotiate": { type: "bool", name: "proxy-negotiate" },
123
+ "no-proxy-negotiate": { type: "bool", name: "proxy-negotiate", expand: false },
124
+ "form-escape": { type: "bool", name: "form-escape" },
125
+ "no-form-escape": { type: "bool", name: "form-escape", expand: false },
126
+ "ftp-account": { type: "string", name: "ftp-account" },
127
+ "proxy-anyauth": { type: "bool", name: "proxy-anyauth" },
128
+ "no-proxy-anyauth": { type: "bool", name: "proxy-anyauth", expand: false },
129
+ "trace-time": { type: "bool", name: "trace-time" },
130
+ "no-trace-time": { type: "bool", name: "trace-time", expand: false },
131
+ "ignore-content-length": { type: "bool", name: "ignore-content-length" },
132
+ "no-ignore-content-length": { type: "bool", name: "ignore-content-length", expand: false },
133
+ "ftp-skip-pasv-ip": { type: "bool", name: "ftp-skip-pasv-ip" },
134
+ "no-ftp-skip-pasv-ip": { type: "bool", name: "ftp-skip-pasv-ip", expand: false },
135
+ "ftp-method": { type: "string", name: "ftp-method" },
136
+ "local-port": { type: "string", name: "local-port" },
137
+ "socks4": { type: "string", name: "socks4" },
138
+ "socks4a": { type: "string", name: "socks4a" },
139
+ "ftp-alternative-to-user": { type: "string", name: "ftp-alternative-to-user" },
140
+ "ftp-ssl-reqd": { type: "bool", name: "ssl-reqd" },
141
+ "no-ftp-ssl-reqd": { type: "bool", name: "ssl-reqd", expand: false },
142
+ "ssl-reqd": { type: "bool", name: "ssl-reqd" },
143
+ "no-ssl-reqd": { type: "bool", name: "ssl-reqd", expand: false },
144
+ "sessionid": { type: "bool", name: "sessionid" },
145
+ "no-sessionid": { type: "bool", name: "sessionid", expand: false },
146
+ "ftp-ssl-control": { type: "bool", name: "ftp-ssl-control" },
147
+ "no-ftp-ssl-control": { type: "bool", name: "ftp-ssl-control", expand: false },
148
+ "ftp-ssl-ccc": { type: "bool", name: "ftp-ssl-ccc" },
149
+ "no-ftp-ssl-ccc": { type: "bool", name: "ftp-ssl-ccc", expand: false },
150
+ "ftp-ssl-ccc-mode": { type: "string", name: "ftp-ssl-ccc-mode" },
151
+ "libcurl": { type: "string", name: "libcurl" },
152
+ "raw": { type: "bool", name: "raw" },
153
+ "no-raw": { type: "bool", name: "raw", expand: false },
154
+ "post301": { type: "bool", name: "post301" },
155
+ "no-post301": { type: "bool", name: "post301", expand: false },
156
+ "keepalive": { type: "bool", name: "keepalive" },
157
+ "no-keepalive": { type: "bool", name: "keepalive", expand: false },
158
+ "socks5-hostname": { type: "string", name: "socks5-hostname" },
159
+ "keepalive-time": { type: "string", name: "keepalive-time" },
160
+ "post302": { type: "bool", name: "post302" },
161
+ "no-post302": { type: "bool", name: "post302", expand: false },
162
+ "noproxy": { type: "string", name: "noproxy" },
163
+ "socks5-gssapi-nec": { type: "bool", name: "socks5-gssapi-nec" },
164
+ "no-socks5-gssapi-nec": { type: "bool", name: "socks5-gssapi-nec", expand: false },
165
+ "proxy1.0": { type: "string", name: "proxy1.0" },
166
+ "tftp-blksize": { type: "string", name: "tftp-blksize" },
167
+ "mail-from": { type: "string", name: "mail-from" },
168
+ "mail-rcpt": { type: "string", name: "mail-rcpt" },
169
+ "ftp-pret": { type: "bool", name: "ftp-pret" },
170
+ "no-ftp-pret": { type: "bool", name: "ftp-pret", expand: false },
171
+ "proto": { type: "string", name: "proto" },
172
+ "proto-redir": { type: "string", name: "proto-redir" },
173
+ "resolve": { type: "string", name: "resolve" },
174
+ "delegation": { type: "string", name: "delegation" },
175
+ "mail-auth": { type: "string", name: "mail-auth" },
176
+ "post303": { type: "bool", name: "post303" },
177
+ "no-post303": { type: "bool", name: "post303", expand: false },
178
+ "metalink": { type: "bool", name: "metalink" },
179
+ "no-metalink": { type: "bool", name: "metalink", expand: false },
180
+ "sasl-authzid": { type: "string", name: "sasl-authzid" },
181
+ "sasl-ir": { type: "bool", name: "sasl-ir" },
182
+ "no-sasl-ir": { type: "bool", name: "sasl-ir", expand: false },
183
+ "test-event": { type: "bool", name: "test-event" },
184
+ "no-test-event": { type: "bool", name: "test-event", expand: false },
185
+ "unix-socket": { type: "string", name: "unix-socket" },
186
+ "path-as-is": { type: "bool", name: "path-as-is" },
187
+ "no-path-as-is": { type: "bool", name: "path-as-is", expand: false },
188
+ "socks5-gssapi-service": { type: "string", name: "proxy-service-name" },
189
+ "proxy-service-name": { type: "string", name: "proxy-service-name" },
190
+ "service-name": { type: "string", name: "service-name" },
191
+ "proto-default": { type: "string", name: "proto-default" },
192
+ "expect100-timeout": { type: "string", name: "expect100-timeout" },
193
+ "tftp-no-options": { type: "bool", name: "tftp-no-options" },
194
+ "no-tftp-no-options": { type: "bool", name: "tftp-no-options", expand: false },
195
+ "connect-to": { type: "string", name: "connect-to" },
196
+ "abstract-unix-socket": { type: "string", name: "abstract-unix-socket" },
197
+ "tls-max": { type: "string", name: "tls-max" },
198
+ "suppress-connect-headers": { type: "bool", name: "suppress-connect-headers" },
199
+ "no-suppress-connect-headers": { type: "bool", name: "suppress-connect-headers", expand: false },
200
+ "compressed-ssh": { type: "bool", name: "compressed-ssh" },
201
+ "no-compressed-ssh": { type: "bool", name: "compressed-ssh", expand: false },
202
+ "happy-eyeballs-timeout-ms": { type: "string", name: "happy-eyeballs-timeout-ms" },
203
+ "retry-all-errors": { type: "bool", name: "retry-all-errors" },
204
+ "no-retry-all-errors": { type: "bool", name: "retry-all-errors", expand: false },
205
+ "trace-ids": { type: "bool", name: "trace-ids" },
206
+ "no-trace-ids": { type: "bool", name: "trace-ids", expand: false },
207
+ "http1.0": { type: "bool", name: "http1.0" },
208
+ "http1.1": { type: "bool", name: "http1.1" },
209
+ "http2": { type: "bool", name: "http2" },
210
+ "http2-prior-knowledge": { type: "bool", name: "http2-prior-knowledge" },
211
+ "http3": { type: "bool", name: "http3" },
212
+ "http3-only": { type: "bool", name: "http3-only" },
213
+ "http0.9": { type: "bool", name: "http0.9" },
214
+ "no-http0.9": { type: "bool", name: "http0.9", expand: false },
215
+ "proxy-http2": { type: "bool", name: "proxy-http2" },
216
+ "no-proxy-http2": { type: "bool", name: "proxy-http2", expand: false },
217
+ "tlsv1": { type: "bool", name: "tlsv1" },
218
+ "tlsv1.0": { type: "bool", name: "tlsv1.0" },
219
+ "tlsv1.1": { type: "bool", name: "tlsv1.1" },
220
+ "tlsv1.2": { type: "bool", name: "tlsv1.2" },
221
+ "tlsv1.3": { type: "bool", name: "tlsv1.3" },
222
+ "tls13-ciphers": { type: "string", name: "tls13-ciphers" },
223
+ "proxy-tls13-ciphers": { type: "string", name: "proxy-tls13-ciphers" },
224
+ "sslv2": { type: "bool", name: "sslv2" },
225
+ "sslv3": { type: "bool", name: "sslv3" },
226
+ "ipv4": { type: "bool", name: "ipv4" },
227
+ "ipv6": { type: "bool", name: "ipv6" },
228
+ "append": { type: "bool", name: "append" },
229
+ "no-append": { type: "bool", name: "append", expand: false },
230
+ "user-agent": { type: "string", name: "user-agent" },
231
+ "cookie": { type: "string", name: "cookie" },
232
+ "alt-svc": { type: "string", name: "alt-svc" },
233
+ "hsts": { type: "string", name: "hsts" },
234
+ "use-ascii": { type: "bool", name: "use-ascii" },
235
+ "no-use-ascii": { type: "bool", name: "use-ascii", expand: false },
236
+ "cookie-jar": { type: "string", name: "cookie-jar" },
237
+ "continue-at": { type: "string", name: "continue-at" },
238
+ "data": { type: "string", name: "data" },
239
+ "data-raw": { type: "string", name: "data-raw" },
240
+ "data-ascii": { type: "string", name: "data-ascii" },
241
+ "data-binary": { type: "string", name: "data-binary" },
242
+ "data-urlencode": { type: "string", name: "data-urlencode" },
243
+ "json": { type: "string", name: "json" },
244
+ "url-query": { type: "string", name: "url-query" },
245
+ "dump-header": { type: "string", name: "dump-header" },
246
+ "referer": { type: "string", name: "referer" },
247
+ "cert": { type: "string", name: "cert" },
248
+ "cacert": { type: "string", name: "cacert" },
249
+ "cert-type": { type: "string", name: "cert-type" },
250
+ "key": { type: "string", name: "key" },
251
+ "key-type": { type: "string", name: "key-type" },
252
+ "pass": { type: "string", name: "pass" },
253
+ "engine": { type: "string", name: "engine" },
254
+ "ca-native": { type: "bool", name: "ca-native" },
255
+ "no-ca-native": { type: "bool", name: "ca-native", expand: false },
256
+ "proxy-ca-native": { type: "bool", name: "proxy-ca-native" },
257
+ "no-proxy-ca-native": { type: "bool", name: "proxy-ca-native", expand: false },
258
+ "capath": { type: "string", name: "capath" },
259
+ "pubkey": { type: "string", name: "pubkey" },
260
+ "hostpubmd5": { type: "string", name: "hostpubmd5" },
261
+ "hostpubsha256": { type: "string", name: "hostpubsha256" },
262
+ "crlfile": { type: "string", name: "crlfile" },
263
+ "tlsuser": { type: "string", name: "tlsuser" },
264
+ "tlspassword": { type: "string", name: "tlspassword" },
265
+ "tlsauthtype": { type: "string", name: "tlsauthtype" },
266
+ "ssl-allow-beast": { type: "bool", name: "ssl-allow-beast" },
267
+ "no-ssl-allow-beast": { type: "bool", name: "ssl-allow-beast", expand: false },
268
+ "ssl-auto-client-cert": { type: "bool", name: "ssl-auto-client-cert" },
269
+ "no-ssl-auto-client-cert": { type: "bool", name: "ssl-auto-client-cert", expand: false },
270
+ "proxy-ssl-auto-client-cert": { type: "bool", name: "proxy-ssl-auto-client-cert" },
271
+ "no-proxy-ssl-auto-client-cert": { type: "bool", name: "proxy-ssl-auto-client-cert", expand: false },
272
+ "pinnedpubkey": { type: "string", name: "pinnedpubkey" },
273
+ "proxy-pinnedpubkey": { type: "string", name: "proxy-pinnedpubkey" },
274
+ "cert-status": { type: "bool", name: "cert-status" },
275
+ "no-cert-status": { type: "bool", name: "cert-status", expand: false },
276
+ "doh-cert-status": { type: "bool", name: "doh-cert-status" },
277
+ "no-doh-cert-status": { type: "bool", name: "doh-cert-status", expand: false },
278
+ "false-start": { type: "bool", name: "false-start" },
279
+ "no-false-start": { type: "bool", name: "false-start", expand: false },
280
+ "ssl-no-revoke": { type: "bool", name: "ssl-no-revoke" },
281
+ "no-ssl-no-revoke": { type: "bool", name: "ssl-no-revoke", expand: false },
282
+ "ssl-revoke-best-effort": { type: "bool", name: "ssl-revoke-best-effort" },
283
+ "no-ssl-revoke-best-effort": { type: "bool", name: "ssl-revoke-best-effort", expand: false },
284
+ "tcp-fastopen": { type: "bool", name: "tcp-fastopen" },
285
+ "no-tcp-fastopen": { type: "bool", name: "tcp-fastopen", expand: false },
286
+ "proxy-tlsuser": { type: "string", name: "proxy-tlsuser" },
287
+ "proxy-tlspassword": { type: "string", name: "proxy-tlspassword" },
288
+ "proxy-tlsauthtype": { type: "string", name: "proxy-tlsauthtype" },
289
+ "proxy-cert": { type: "string", name: "proxy-cert" },
290
+ "proxy-cert-type": { type: "string", name: "proxy-cert-type" },
291
+ "proxy-key": { type: "string", name: "proxy-key" },
292
+ "proxy-key-type": { type: "string", name: "proxy-key-type" },
293
+ "proxy-pass": { type: "string", name: "proxy-pass" },
294
+ "proxy-ciphers": { type: "string", name: "proxy-ciphers" },
295
+ "proxy-crlfile": { type: "string", name: "proxy-crlfile" },
296
+ "proxy-ssl-allow-beast": { type: "bool", name: "proxy-ssl-allow-beast" },
297
+ "no-proxy-ssl-allow-beast": { type: "bool", name: "proxy-ssl-allow-beast", expand: false },
298
+ "login-options": { type: "string", name: "login-options" },
299
+ "proxy-cacert": { type: "string", name: "proxy-cacert" },
300
+ "proxy-capath": { type: "string", name: "proxy-capath" },
301
+ "proxy-insecure": { type: "bool", name: "proxy-insecure" },
302
+ "no-proxy-insecure": { type: "bool", name: "proxy-insecure", expand: false },
303
+ "proxy-tlsv1": { type: "bool", name: "proxy-tlsv1" },
304
+ "socks5-basic": { type: "bool", name: "socks5-basic" },
305
+ "no-socks5-basic": { type: "bool", name: "socks5-basic", expand: false },
306
+ "socks5-gssapi": { type: "bool", name: "socks5-gssapi" },
307
+ "no-socks5-gssapi": { type: "bool", name: "socks5-gssapi", expand: false },
308
+ "etag-save": { type: "string", name: "etag-save" },
309
+ "etag-compare": { type: "string", name: "etag-compare" },
310
+ "curves": { type: "string", name: "curves" },
311
+ "fail": { type: "bool", name: "fail" },
312
+ "no-fail": { type: "bool", name: "fail", expand: false },
313
+ "fail-early": { type: "bool", name: "fail-early" },
314
+ "no-fail-early": { type: "bool", name: "fail-early", expand: false },
315
+ "styled-output": { type: "bool", name: "styled-output" },
316
+ "no-styled-output": { type: "bool", name: "styled-output", expand: false },
317
+ "mail-rcpt-allowfails": { type: "bool", name: "mail-rcpt-allowfails" },
318
+ "no-mail-rcpt-allowfails": { type: "bool", name: "mail-rcpt-allowfails", expand: false },
319
+ "fail-with-body": { type: "bool", name: "fail-with-body" },
320
+ "no-fail-with-body": { type: "bool", name: "fail-with-body", expand: false },
321
+ "remove-on-error": { type: "bool", name: "remove-on-error" },
322
+ "no-remove-on-error": { type: "bool", name: "remove-on-error", expand: false },
323
+ "form": { type: "string", name: "form" },
324
+ "form-string": { type: "string", name: "form-string" },
325
+ "globoff": { type: "bool", name: "globoff" },
326
+ "no-globoff": { type: "bool", name: "globoff", expand: false },
327
+ "get": { type: "bool", name: "get" },
328
+ "no-get": { type: "bool", name: "get", expand: false },
329
+ "request-target": { type: "string", name: "request-target" },
330
+ "help": { type: "bool", name: "help" },
331
+ "no-help": { type: "bool", name: "help", expand: false },
332
+ "header": { type: "string", name: "header" },
333
+ "proxy-header": { type: "string", name: "proxy-header" },
334
+ "include": { type: "bool", name: "include" },
335
+ "no-include": { type: "bool", name: "include", expand: false },
336
+ "head": { type: "bool", name: "head" },
337
+ "no-head": { type: "bool", name: "head", expand: false },
338
+ "junk-session-cookies": { type: "bool", name: "junk-session-cookies" },
339
+ "no-junk-session-cookies": { type: "bool", name: "junk-session-cookies", expand: false },
340
+ "remote-header-name": { type: "bool", name: "remote-header-name" },
341
+ "no-remote-header-name": { type: "bool", name: "remote-header-name", expand: false },
342
+ "insecure": { type: "bool", name: "insecure" },
343
+ "no-insecure": { type: "bool", name: "insecure", expand: false },
344
+ "doh-insecure": { type: "bool", name: "doh-insecure" },
345
+ "no-doh-insecure": { type: "bool", name: "doh-insecure", expand: false },
346
+ "config": { type: "string", name: "config" },
347
+ "list-only": { type: "bool", name: "list-only" },
348
+ "no-list-only": { type: "bool", name: "list-only", expand: false },
349
+ "location": { type: "bool", name: "location" },
350
+ "no-location": { type: "bool", name: "location", expand: false },
351
+ "location-trusted": { type: "bool", name: "location-trusted" },
352
+ "no-location-trusted": { type: "bool", name: "location-trusted", expand: false },
353
+ "max-time": { type: "string", name: "max-time" },
354
+ "manual": { type: "bool", name: "manual" },
355
+ "no-manual": { type: "bool", name: "manual", expand: false },
356
+ "netrc": { type: "bool", name: "netrc" },
357
+ "no-netrc": { type: "bool", name: "netrc", expand: false },
358
+ "netrc-optional": { type: "bool", name: "netrc-optional" },
359
+ "no-netrc-optional": { type: "bool", name: "netrc-optional", expand: false },
360
+ "netrc-file": { type: "string", name: "netrc-file" },
361
+ "buffer": { type: "bool", name: "buffer" },
362
+ "no-buffer": { type: "bool", name: "buffer", expand: false },
363
+ "output": { type: "string", name: "output" },
364
+ "remote-name": { type: "bool", name: "remote-name" },
365
+ "no-remote-name": { type: "bool", name: "remote-name", expand: false },
366
+ "remote-name-all": { type: "bool", name: "remote-name-all" },
367
+ "no-remote-name-all": { type: "bool", name: "remote-name-all", expand: false },
368
+ "output-dir": { type: "string", name: "output-dir" },
369
+ "clobber": { type: "bool", name: "clobber" },
370
+ "no-clobber": { type: "bool", name: "clobber", expand: false },
371
+ "proxytunnel": { type: "bool", name: "proxytunnel" },
372
+ "no-proxytunnel": { type: "bool", name: "proxytunnel", expand: false },
373
+ "ftp-port": { type: "string", name: "ftp-port" },
374
+ "disable": { type: "bool", name: "disable" },
375
+ "no-disable": { type: "bool", name: "disable", expand: false },
376
+ "quote": { type: "string", name: "quote" },
377
+ "range": { type: "string", name: "range" },
378
+ "remote-time": { type: "bool", name: "remote-time" },
379
+ "no-remote-time": { type: "bool", name: "remote-time", expand: false },
380
+ "silent": { type: "bool", name: "silent" },
381
+ "no-silent": { type: "bool", name: "silent", expand: false },
382
+ "show-error": { type: "bool", name: "show-error" },
383
+ "no-show-error": { type: "bool", name: "show-error", expand: false },
384
+ "telnet-option": { type: "string", name: "telnet-option" },
385
+ "upload-file": { type: "string", name: "upload-file" },
386
+ "user": { type: "string", name: "user" },
387
+ "proxy-user": { type: "string", name: "proxy-user" },
388
+ "verbose": { type: "bool", name: "verbose" },
389
+ "no-verbose": { type: "bool", name: "verbose", expand: false },
390
+ "version": { type: "bool", name: "version" },
391
+ "no-version": { type: "bool", name: "version", expand: false },
392
+ "write-out": { type: "string", name: "write-out" },
393
+ "proxy": { type: "string", name: "proxy" },
394
+ "preproxy": { type: "string", name: "preproxy" },
395
+ "request": { type: "string", name: "request" },
396
+ "speed-limit": { type: "string", name: "speed-limit" },
397
+ "speed-time": { type: "string", name: "speed-time" },
398
+ "time-cond": { type: "string", name: "time-cond" },
399
+ "parallel": { type: "bool", name: "parallel" },
400
+ "no-parallel": { type: "bool", name: "parallel", expand: false },
401
+ "parallel-max": { type: "string", name: "parallel-max" },
402
+ "parallel-immediate": { type: "bool", name: "parallel-immediate" },
403
+ "no-parallel-immediate": { type: "bool", name: "parallel-immediate", expand: false },
404
+ "progress-bar": { type: "bool", name: "progress-bar" },
405
+ "no-progress-bar": { type: "bool", name: "progress-bar", expand: false },
406
+ "progress-meter": { type: "bool", name: "progress-meter" },
407
+ "no-progress-meter": { type: "bool", name: "progress-meter", expand: false },
408
+ "next": { type: "bool", name: "next" },
409
+ // END EXTRACTED OPTIONS
410
+
411
+
412
+ // These are options that curl used to have.
413
+ // Those that don't conflict with the current options are supported by curlconverter.
414
+ // TODO: curl's --long-options can be shortened.
415
+ // For example if curl used to only have a single option, "--blah" then
416
+ // "--bla" "--bl" and "--b" all used to be valid options as well. If later
417
+ // "--blaz" was added, suddenly those 3 shortened options are removed (because
418
+ // they are now ambiguous).
419
+ // https://github.com/curlconverter/curlconverter/pull/280#issuecomment-931241328
420
+ port: { type: "string", name: "port", removed: "7.3" },
421
+
422
+ // These are now shoretened forms of --upload-file and --continue-at
423
+ //upload: { type: "bool", name: "upload", removed: "7.7" },
424
+ //continue: { type: "bool", name: "continue", removed: "7.9" },
425
+
426
+ "ftp-ascii": { type: "bool", name: "use-ascii", removed: "7.10.7" },
427
+
428
+ "3p-url": { type: "string", name: "3p-url", removed: "7.16.0" },
429
+ "3p-user": { type: "string", name: "3p-user", removed: "7.16.0" },
430
+ "3p-quote": { type: "string", name: "3p-quote", removed: "7.16.0" },
431
+
432
+ "http2.0": { type: "bool", name: "http2", removed: "7.36.0" },
433
+ "no-http2.0": { type: "bool", name: "http2", removed: "7.36.0" },
434
+
435
+ "telnet-options": { type: "string", name: "telnet-option", removed: "7.49.0" },
436
+ "http-request": { type: "string", name: "request", removed: "7.49.0" },
437
+ // --socks is now an ambiguous shortening of --socks4, --socks5 and a bunch more
438
+ //socks: { type: "string", name: "socks5", removed: "7.49.0" },
439
+ "capath ": { type: "string", name: "capath", removed: "7.49.0" }, // trailing space
440
+ ftpport: { type: "string", name: "ftp-port", removed: "7.49.0" },
441
+
442
+ environment: { type: "bool", name: "environment", removed: "7.54.1" },
443
+
444
+ // These never had any effect
445
+ "no-tlsv1": { type: "bool", name: "tlsv1", removed: "7.54.1" },
446
+ "no-tlsv1.2": { type: "bool", name: "tlsv1.2", removed: "7.54.1" },
447
+ "no-http2-prior-knowledge": { type: "bool", name: "http2-prior-knowledge", removed: "7.54.1" },
448
+ "no-ipv6": { type: "bool", name: "ipv6", removed: "7.54.1" },
449
+ "no-ipv4": { type: "bool", name: "ipv4", removed: "7.54.1" },
450
+ "no-sslv2": { type: "bool", name: "sslv2", removed: "7.54.1" },
451
+ "no-tlsv1.0": { type: "bool", name: "tlsv1.0", removed: "7.54.1" },
452
+ "no-tlsv1.1": { type: "bool", name: "tlsv1.1", removed: "7.54.1" },
453
+ "no-sslv3": { type: "bool", name: "sslv3", removed: "7.54.1" },
454
+ "no-http1.0": { type: "bool", name: "http1.0", removed: "7.54.1" },
455
+ "no-next": { type: "bool", name: "next", removed: "7.54.1" },
456
+ "no-tlsv1.3": { type: "bool", name: "tlsv1.3", removed: "7.54.1" },
457
+ "no-environment": { type: "bool", name: "environment", removed: "7.54.1" },
458
+ "no-http1.1": { type: "bool", name: "http1.1", removed: "7.54.1" },
459
+ "no-proxy-tlsv1": { type: "bool", name: "proxy-tlsv1", removed: "7.54.1" },
460
+ "no-http2": { type: "bool", name: "http2", removed: "7.54.1" },
461
+ } as const;
462
+
463
+ // curl lets you not type the full argument as long as it's unambiguous.
464
+ // So --sil instead of --silent is okay, --s is not.
465
+ export const curlLongOptsShortened: { [key: string]: LongShort | null } = {};
466
+ for (const [opt, val] of Object.entries(curlLongOpts)) {
467
+ const expand = "expand" in val ? val.expand : true;
468
+ const removed = "removed" in val ? val.removed : false;
469
+ if (expand && !removed) {
470
+ for (let i = 1; i < opt.length; i++) {
471
+ const shortenedOpt = opt.slice(0, i);
472
+ if (
473
+ !Object.prototype.hasOwnProperty.call(
474
+ curlLongOptsShortened,
475
+ shortenedOpt,
476
+ )
477
+ ) {
478
+ if (!Object.prototype.hasOwnProperty.call(curlLongOpts, shortenedOpt)) {
479
+ curlLongOptsShortened[shortenedOpt] = val;
480
+ }
481
+ } else {
482
+ // If more than one option shortens to this, it's ambiguous
483
+ curlLongOptsShortened[shortenedOpt] = null;
484
+ }
485
+ }
486
+ }
487
+ }
488
+
489
+ // Arguments which are supported by all generators, because they're
490
+ // easy to implement or because they're handled by upstream code and
491
+ // affect something that's easy to implement.
492
+ export const COMMON_SUPPORTED_ARGS: string[] = [
493
+ "url",
494
+ "proto-default",
495
+ // Controls whether or not backslash-escaped [] {} will have the backslash removed.
496
+ "globoff",
497
+ // curl will exit if it finds auth credentials in the URL with this option,
498
+ // we remove it from the URL and emit a warning instead.
499
+ "disallow-username-in-url",
500
+
501
+ // Method
502
+ "request",
503
+ "get",
504
+ "head",
505
+ "no-head",
506
+
507
+ // Headers
508
+ "header", // TODO: can be a file
509
+ "user-agent",
510
+ "referer",
511
+ "range",
512
+ "time-cond",
513
+ "cookie", // TODO: can be a file
514
+ "oauth2-bearer",
515
+
516
+ // Basic Auth
517
+ "user",
518
+ "basic",
519
+ "no-basic",
520
+ // Data
521
+ "data",
522
+ "data-raw",
523
+ "data-ascii",
524
+ "data-binary",
525
+ "data-urlencode",
526
+ "json",
527
+ "url-query",
528
+
529
+ // TODO: --compressed is already the default for some runtimes, in
530
+ // which case we might have to only warn that --no-compressed isn't supported.
531
+ ];
532
+
533
+ export function toBoolean(opt: string): boolean {
534
+ if (opt.startsWith("no-disable-")) {
535
+ return true;
536
+ }
537
+ if (opt.startsWith("disable-") || opt.startsWith("no-")) {
538
+ return false;
539
+ }
540
+ return true;
541
+ }
542
+
543
+ // prettier-ignore
544
+ export const curlShortOpts: {
545
+ [key: string]: keyof typeof curlLongOpts
546
+ } = {
547
+ // BEGIN EXTRACTED SHORT OPTIONS
548
+ "0": "http1.0",
549
+ "1": "tlsv1",
550
+ "2": "sslv2",
551
+ "3": "sslv3",
552
+ "4": "ipv4",
553
+ "6": "ipv6",
554
+ "a": "append",
555
+ "A": "user-agent",
556
+ "b": "cookie",
557
+ "B": "use-ascii",
558
+ "c": "cookie-jar",
559
+ "C": "continue-at",
560
+ "d": "data",
561
+ "D": "dump-header",
562
+ "e": "referer",
563
+ "E": "cert",
564
+ "f": "fail",
565
+ "F": "form",
566
+ "g": "globoff",
567
+ "G": "get",
568
+ "h": "help",
569
+ "H": "header",
570
+ "i": "include",
571
+ "I": "head",
572
+ "j": "junk-session-cookies",
573
+ "J": "remote-header-name",
574
+ "k": "insecure",
575
+ "K": "config",
576
+ "l": "list-only",
577
+ "L": "location",
578
+ "m": "max-time",
579
+ "M": "manual",
580
+ "n": "netrc",
581
+ "N": "no-buffer",
582
+ "o": "output",
583
+ "O": "remote-name",
584
+ "p": "proxytunnel",
585
+ "P": "ftp-port",
586
+ "q": "disable",
587
+ "Q": "quote",
588
+ "r": "range",
589
+ "R": "remote-time",
590
+ "s": "silent",
591
+ "S": "show-error",
592
+ "t": "telnet-option",
593
+ "T": "upload-file",
594
+ "u": "user",
595
+ "U": "proxy-user",
596
+ "v": "verbose",
597
+ "V": "version",
598
+ "w": "write-out",
599
+ "x": "proxy",
600
+ "X": "request",
601
+ "Y": "speed-limit",
602
+ "y": "speed-time",
603
+ "z": "time-cond",
604
+ "Z": "parallel",
605
+ "#": "progress-bar",
606
+ ":": "next",
607
+ // END EXTRACTED SHORT OPTIONS
608
+ } as const;
609
+
610
+ export const changedShortOpts: ShortOpts = {
611
+ p: "used to be short for --port <port> (a since-deleted flag) until curl 7.3",
612
+ // TODO: some of these might be renamed options
613
+ t: "used to be short for --upload (a since-deleted boolean flag) until curl 7.7",
614
+ c: "used to be short for --continue (a since-deleted boolean flag) until curl 7.9",
615
+ // TODO: did -@ actually work?
616
+ "@": "used to be short for --create-dirs until curl 7.10.7",
617
+ Z: "used to be short for --max-redirs <num> until curl 7.10.7",
618
+ 9: "used to be short for --crlf until curl 7.10.8",
619
+ 8: "used to be short for --stderr <file> until curl 7.10.8",
620
+ 7: "used to be short for --interface <name> until curl 7.10.8",
621
+ 6: "used to be short for --krb <level> (which itself used to be --krb4 <level>) until curl 7.10.8",
622
+ // TODO: did these short options ever actually work?
623
+ 5: "used to be another way to specify the url until curl 7.10.8",
624
+ "*": "used to be another way to specify the url until curl 7.49.0",
625
+ "~": "used to be short for --xattr until curl 7.49.0",
626
+ } as const;
627
+
628
+ export type SrcFormParam = { value: Word; type: FormType };
629
+ export type SrcDataParam = [DataType, Word];
630
+
631
+ // The keys should be named the same as the curl options that
632
+ // set them because they appear in error messages.
633
+ export interface OperationConfig {
634
+ request?: Word; // the HTTP method
635
+
636
+ // Not the same name as the curl options that set it
637
+ authtype: number;
638
+ proxyauthtype: number;
639
+
640
+ json?: boolean;
641
+
642
+ // canBeList
643
+ url?: Word[];
644
+ "upload-file"?: Word[];
645
+ output?: Word[];
646
+ header?: Word[];
647
+ "proxy-header"?: Word[];
648
+ form?: SrcFormParam[];
649
+ data?: SrcDataParam[];
650
+ "url-query"?: SrcDataParam[];
651
+ "mail-rcpt"?: Word[];
652
+ resolve?: Word[];
653
+ "connect-to"?: Word[];
654
+ cookie?: Word[];
655
+ quote?: Word[];
656
+ "telnet-option"?: Word[];
657
+
658
+ httpVersion?: "1.0" | "1.1" | "2" | "2-prior-knowledge" | "3" | "3-only";
659
+ tlsVersion?: "1" | "1.0" | "1.1" | "1.2" | "1.3";
660
+
661
+ netrc?: boolean;
662
+ "netrc-optional"?: boolean;
663
+ "netrc-file"?: Word;
664
+
665
+ compressed?: boolean;
666
+
667
+ head?: boolean;
668
+ get?: boolean;
669
+
670
+ ipv4?: boolean;
671
+ ipv6?: boolean;
672
+
673
+ ciphers?: Word;
674
+ insecure?: boolean;
675
+ cert?: Word;
676
+ "cert-type"?: Word;
677
+ key?: Word;
678
+ "key-type"?: Word;
679
+ cacert?: Word;
680
+ capath?: Word;
681
+ crlfile?: Word;
682
+ pinnedpubkey?: Word;
683
+ "random-file"?: Word;
684
+ "egd-file"?: Word;
685
+ hsts?: Word[];
686
+
687
+ "proto-default"?: Word;
688
+ globoff?: boolean;
689
+
690
+ "max-redirs"?: Word;
691
+ location?: boolean;
692
+ "location-trusted"?: boolean;
693
+
694
+ proxy?: Word;
695
+ "proxy-user"?: Word;
696
+ noproxy?: Word;
697
+
698
+ range?: Word;
699
+ referer?: Word;
700
+ "time-cond"?: Word;
701
+ "user-agent"?: Word;
702
+
703
+ user?: Word;
704
+ "aws-sigv4"?: Word;
705
+ delegation?: Word;
706
+ "oauth2-bearer"?: Word;
707
+
708
+ "max-time"?: Word;
709
+ "connect-timeout"?: Word;
710
+
711
+ "cookie-jar"?: Word;
712
+
713
+ "unix-socket"?: Word;
714
+ // "abstract-unix-socket"?: Word;
715
+
716
+ // This needs to be updated any time a new argument is added
717
+ "3p-quote"?: Word;
718
+ "3p-url"?: Word;
719
+ "3p-user"?: Word;
720
+ "abstract-unix-socket"?: Word;
721
+ alpn?: boolean;
722
+ "alt-svc"?: Word;
723
+ anyauth?: boolean;
724
+ append?: boolean;
725
+ basic?: boolean;
726
+ buffer?: boolean;
727
+ "ca-native"?: boolean;
728
+ "cert-status"?: boolean;
729
+ clobber?: boolean;
730
+ "compressed-ssh"?: boolean;
731
+ "continue-at"?: Word;
732
+ "create-dirs"?: boolean;
733
+ "create-file-mode"?: Word;
734
+ crlf?: boolean;
735
+ curves?: Word;
736
+ "data-ascii"?: Word;
737
+ "data-binary"?: Word;
738
+ "data-raw"?: Word;
739
+ "data-urlencode"?: Word;
740
+ digest?: boolean;
741
+ disable?: boolean;
742
+ "disable-eprt"?: boolean;
743
+ "disable-epsv"?: boolean;
744
+ "disallow-username-in-url"?: boolean;
745
+ "dns-interface"?: Word;
746
+ "dns-ipv4-addr"?: Word;
747
+ "dns-ipv6-addr"?: Word;
748
+ "dns-servers"?: Word;
749
+ "doh-cert-status"?: boolean;
750
+ "doh-insecure"?: boolean;
751
+ "doh-url"?: Word;
752
+ "dump-header"?: Word;
753
+ engine?: Word;
754
+ environment?: boolean;
755
+ eprt?: boolean;
756
+ epsv?: boolean;
757
+ "etag-compare"?: Word;
758
+ "etag-save"?: Word;
759
+ "expect100-timeout"?: Word;
760
+ fail?: boolean;
761
+ "fail-with-body"?: boolean;
762
+ "false-start"?: boolean;
763
+ "form-escape"?: boolean;
764
+ "form-string"?: Word;
765
+ "ftp-account"?: Word;
766
+ "ftp-alternative-to-user"?: Word;
767
+ "ftp-create-dirs"?: boolean;
768
+ "ftp-method"?: Word;
769
+ "ftp-pasv"?: boolean;
770
+ "ftp-port"?: Word;
771
+ "ftp-pret"?: boolean;
772
+ "ftp-skip-pasv-ip"?: boolean;
773
+ "ftp-ssl-ccc"?: boolean;
774
+ "ftp-ssl-ccc-mode"?: Word;
775
+ "ftp-ssl-control"?: boolean;
776
+ "happy-eyeballs-timeout-ms"?: Word;
777
+ "haproxy-clientip"?: Word;
778
+ "haproxy-protocol"?: boolean;
779
+ hostpubmd5?: Word;
780
+ hostpubsha256?: Word;
781
+ "http0.9"?: boolean;
782
+ "http1.0"?: boolean;
783
+ "http1.1"?: boolean;
784
+ "http2-prior-knowledge"?: boolean;
785
+ "ignore-content-length"?: boolean;
786
+ include?: boolean;
787
+ interface?: Word;
788
+ "junk-session-cookies"?: boolean;
789
+ keepalive?: boolean;
790
+ "keepalive-time"?: Word;
791
+ krb?: Word;
792
+ "limit-rate"?: Word;
793
+ "list-only"?: boolean;
794
+ "local-port"?: Word;
795
+ "login-options"?: Word;
796
+ "mail-auth"?: Word;
797
+ "mail-from"?: Word;
798
+ "mail-rcpt-allowfails"?: boolean;
799
+ manual?: boolean;
800
+ "max-filesize"?: Word;
801
+ metalink?: boolean;
802
+ negotiate?: boolean;
803
+ next?: boolean;
804
+ npn?: boolean;
805
+ ntlm?: boolean;
806
+ "ntlm-wb"?: boolean;
807
+ "output-dir"?: Word;
808
+ pass?: Word;
809
+ "path-as-is"?: boolean;
810
+ port?: Word;
811
+ post301?: boolean;
812
+ post302?: boolean;
813
+ post303?: boolean;
814
+ preproxy?: Word;
815
+ proto?: Word;
816
+ "proto-redir"?: Word;
817
+ "proxy-anyauth"?: boolean;
818
+ "proxy-basic"?: boolean;
819
+ "proxy-cacert"?: Word;
820
+ "proxy-capath"?: Word;
821
+ "proxy-cert"?: Word;
822
+ "proxy-cert-type"?: Word;
823
+ "proxy-ciphers"?: Word;
824
+ "proxy-crlfile"?: Word;
825
+ "proxy-digest"?: boolean;
826
+ "proxy-insecure"?: boolean;
827
+ "proxy-key"?: Word;
828
+ "proxy-key-type"?: Word;
829
+ "proxy-negotiate"?: boolean;
830
+ "proxy-ntlm"?: boolean;
831
+ "proxy-pass"?: Word;
832
+ "proxy-pinnedpubkey"?: Word;
833
+ "proxy-service-name"?: Word;
834
+ "proxy-ssl-allow-beast"?: boolean;
835
+ "proxy-ssl-auto-client-cert"?: boolean;
836
+ "proxy-tls13-ciphers"?: Word;
837
+ "proxy-tlsauthtype"?: Word;
838
+ "proxy-tlspassword"?: Word;
839
+ "proxy-tlsuser"?: Word;
840
+ "proxy-tlsv1"?: boolean;
841
+ "proxy1.0"?: Word;
842
+ proxytunnel?: boolean;
843
+ pubkey?: Word;
844
+ rate?: Word;
845
+ raw?: boolean;
846
+ "remote-header-name"?: boolean;
847
+ "remote-name"?: boolean;
848
+ "remote-name-all"?: boolean;
849
+ "remote-time"?: boolean;
850
+ "remove-on-error"?: boolean;
851
+ "request-target"?: Word;
852
+ retry?: Word;
853
+ "retry-all-errors"?: boolean;
854
+ "retry-connrefused"?: boolean;
855
+ "retry-delay"?: Word;
856
+ "retry-max-time"?: Word;
857
+ "sasl-authzid"?: Word;
858
+ "sasl-ir"?: boolean;
859
+ "service-name"?: Word;
860
+ sessionid?: boolean;
861
+ socks4?: Word;
862
+ socks4a?: Word;
863
+ socks5?: Word;
864
+ "socks5-basic"?: boolean;
865
+ "socks5-gssapi"?: boolean;
866
+ "socks5-gssapi-nec"?: boolean;
867
+ "socks5-hostname"?: Word;
868
+ "speed-limit"?: Word;
869
+ "speed-time"?: Word;
870
+ ssl?: boolean;
871
+ "ssl-allow-beast"?: boolean;
872
+ "ssl-auto-client-cert"?: boolean;
873
+ "ssl-no-revoke"?: boolean;
874
+ "ssl-reqd"?: boolean;
875
+ "ssl-revoke-best-effort"?: boolean;
876
+ sslv2?: boolean;
877
+ sslv3?: boolean;
878
+ "suppress-connect-headers"?: boolean;
879
+ "tcp-fastopen"?: boolean;
880
+ "tcp-nodelay"?: boolean;
881
+ "tftp-blksize"?: Word;
882
+ "tftp-no-options"?: boolean;
883
+ "tls-max"?: Word;
884
+ "tls13-ciphers"?: Word;
885
+ tlsauthtype?: Word;
886
+ tlspassword?: Word;
887
+ tlsuser?: Word;
888
+ tlsv1?: boolean;
889
+ "tlsv1.0"?: boolean;
890
+ "tlsv1.1"?: boolean;
891
+ "tlsv1.2"?: boolean;
892
+ "tlsv1.3"?: boolean;
893
+ "tr-encoding"?: boolean;
894
+ "use-ascii"?: boolean;
895
+ version?: boolean;
896
+ wdebug?: boolean;
897
+ "write-out"?: Word;
898
+ xattr?: boolean;
899
+
900
+ // TODO: --npn not supported warning
901
+ // TODO: --metalink disabled warning
902
+
903
+ // TODO: remove any.
904
+ // This is difficult because we have curl's arguments but also a couple
905
+ // curlconverter-specific arguments that are handled by the same code.
906
+ [key: string]: any;
907
+ }
908
+ // type Satisfies<T, U extends T> = void;
909
+ // type AssertSubsetKeys = Satisfies<
910
+ // keyof typeof curlLongOpts | "authtype" | "proxyauthtype",
911
+ // keyof OperationConfig
912
+ // >;
913
+
914
+ // These options can be specified more than once, they
915
+ // are always returned as a list.
916
+ // For all other options, if you specify it more than once
917
+ // curl will use the last one.
918
+ const canBeList = new Set<keyof OperationConfig>([
919
+ "connect-to",
920
+ "cookie",
921
+ "data",
922
+ "form",
923
+ "header",
924
+ "hsts",
925
+ "mail-rcpt",
926
+ "output",
927
+ "proxy-header",
928
+ "quote",
929
+ "resolve",
930
+ "telnet-option",
931
+ "upload-file",
932
+ "url-query",
933
+ "url",
934
+ ]);
935
+
936
+ export interface GlobalConfig {
937
+ version?: boolean;
938
+ trace?: Word;
939
+ "trace-ascii"?: Word;
940
+ "trace-time"?: boolean;
941
+ stderr?: Word;
942
+ libcurl?: Word;
943
+ "test-event"?: boolean;
944
+ "progress-bar"?: boolean;
945
+ "progress-meter"?: boolean;
946
+ "fail-early"?: boolean;
947
+ "styled-output"?: boolean;
948
+ help?: boolean; // TODO: might use the next word, then curl exits immediately
949
+ config?: Word; // TODO: is it really global?
950
+ silent?: boolean;
951
+ "show-error"?: boolean;
952
+ verbose?: boolean;
953
+ parallel?: boolean;
954
+ "parallel-immediate"?: boolean;
955
+ "parallel-max"?: Word;
956
+
957
+ configs: OperationConfig[];
958
+ warnings: Warnings;
959
+
960
+ // These are specific to the curlconverter cli
961
+ language?: string;
962
+ stdin?: boolean;
963
+ }
964
+
965
+ function checkSupported(
966
+ global_: GlobalConfig,
967
+ lookup: string,
968
+ longArg: LongShort,
969
+ supportedOpts?: Set<string>,
970
+ ) {
971
+ if (supportedOpts && !supportedOpts.has(longArg.name)) {
972
+ // TODO: better message. include generator name?
973
+ warnf(global_, [
974
+ longArg.name,
975
+ lookup +
976
+ " is not a supported option" +
977
+ (longArg.removed ? ", it was removed in curl " + longArg.removed : ""),
978
+ ]);
979
+ }
980
+ }
981
+
982
+ export function pushProp<Type>(
983
+ obj: { [key: string]: Type[] },
984
+ prop: string,
985
+ value: Type,
986
+ ) {
987
+ if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
988
+ obj[prop] = [];
989
+ }
990
+ obj[prop].push(value);
991
+ return obj;
992
+ }
993
+
994
+ function pushArgValue(
995
+ global_: GlobalConfig,
996
+ config: OperationConfig,
997
+ argName: string,
998
+ value: Word,
999
+ ) {
1000
+ // Note: cli.ts assumes that the property names on OperationConfig
1001
+ // are the same as the passed in argument in an error message, so
1002
+ // if you do something like
1003
+ // echo curl example.com | curlconverter - --data-raw foo
1004
+ // The error message will say
1005
+ // "if you pass --stdin or -, you can't also pass --data"
1006
+ // instead of "--data-raw".
1007
+ switch (argName) {
1008
+ case "data":
1009
+ case "data-ascii":
1010
+ return pushProp(config, "data", ["data", value]);
1011
+ case "data-binary":
1012
+ return pushProp(config, "data", [
1013
+ // Unless it's a file, --data-binary works the same as --data
1014
+ value.startsWith("@") ? "binary" : "data",
1015
+ value,
1016
+ ]);
1017
+ case "data-raw":
1018
+ return pushProp(config, "data", [
1019
+ // Unless it's a file, --data-raw works the same as --data
1020
+ value.startsWith("@") ? "raw" : "data",
1021
+ value,
1022
+ ]);
1023
+ case "data-urlencode":
1024
+ return pushProp(config, "data", ["urlencode", value]);
1025
+ case "json":
1026
+ config.json = true;
1027
+ return pushProp(config, "data", ["json", value]);
1028
+ case "url-query":
1029
+ if (value.startsWith("+")) {
1030
+ return pushProp(config, "url-query", ["raw", value.slice(1)]);
1031
+ }
1032
+ return pushProp(config, "url-query", ["urlencode", value]);
1033
+
1034
+ case "form":
1035
+ return pushProp(config, "form", { value, type: "form" });
1036
+ case "form-string":
1037
+ return pushProp(config, "form", { value, type: "string" });
1038
+
1039
+ case "aws-sigv4":
1040
+ config.authtype |= CURLAUTH_AWS_SIGV4;
1041
+ break;
1042
+ case "oauth2-bearer":
1043
+ config.authtype |= CURLAUTH_BEARER;
1044
+ break;
1045
+
1046
+ case "unix-socket":
1047
+ case "abstract-unix-socket":
1048
+ // Ignore distinction
1049
+ // TODO: this makes the error message wrong
1050
+ // TODO: what's the difference?
1051
+ pushProp(config, "unix-socket", value);
1052
+ break;
1053
+
1054
+ case "trace":
1055
+ case "trace-ascii":
1056
+ case "stderr":
1057
+ case "libcurl":
1058
+ case "config":
1059
+ case "parallel-max":
1060
+ global_[argName] = value;
1061
+ break;
1062
+
1063
+ case "language": // --language is a curlconverter specific option
1064
+ global_[argName] = value.toString();
1065
+ return;
1066
+ }
1067
+
1068
+ return pushProp(config, argName, value);
1069
+ }
1070
+
1071
+ // Might create a new config
1072
+ function setArgValue(
1073
+ global_: GlobalConfig,
1074
+ config: OperationConfig,
1075
+ argName: string,
1076
+ toggle: boolean,
1077
+ ): OperationConfig {
1078
+ switch (argName) {
1079
+ case "digest":
1080
+ if (toggle) {
1081
+ config.authtype |= CURLAUTH_DIGEST;
1082
+ } else {
1083
+ config.authtype &= ~CURLAUTH_DIGEST;
1084
+ }
1085
+ break;
1086
+ case "proxy-digest":
1087
+ if (toggle) {
1088
+ config.proxyauthtype |= CURLAUTH_DIGEST;
1089
+ } else {
1090
+ config.proxyauthtype &= ~CURLAUTH_DIGEST;
1091
+ }
1092
+ break;
1093
+ case "negotiate":
1094
+ if (toggle) {
1095
+ config.authtype |= CURLAUTH_NEGOTIATE;
1096
+ } else {
1097
+ config.authtype &= ~CURLAUTH_NEGOTIATE;
1098
+ }
1099
+ break;
1100
+ case "proxy-negotiate":
1101
+ if (toggle) {
1102
+ config.proxyauthtype |= CURLAUTH_NEGOTIATE;
1103
+ } else {
1104
+ config.proxyauthtype &= ~CURLAUTH_NEGOTIATE;
1105
+ }
1106
+ break;
1107
+ case "ntlm":
1108
+ if (toggle) {
1109
+ config.authtype |= CURLAUTH_NTLM;
1110
+ } else {
1111
+ config.authtype &= ~CURLAUTH_NTLM;
1112
+ }
1113
+ break;
1114
+ case "proxy-ntlm":
1115
+ if (toggle) {
1116
+ config.proxyauthtype |= CURLAUTH_NTLM;
1117
+ } else {
1118
+ config.proxyauthtype &= ~CURLAUTH_NTLM;
1119
+ }
1120
+ break;
1121
+ case "ntlm-wb":
1122
+ if (toggle) {
1123
+ config.authtype |= CURLAUTH_NTLM_WB;
1124
+ } else {
1125
+ config.authtype &= ~CURLAUTH_NTLM_WB;
1126
+ }
1127
+ break;
1128
+ case "basic":
1129
+ if (toggle) {
1130
+ config.authtype |= CURLAUTH_BASIC;
1131
+ } else {
1132
+ config.authtype &= ~CURLAUTH_BASIC;
1133
+ }
1134
+ break;
1135
+ case "proxy-basic":
1136
+ if (toggle) {
1137
+ config.proxyauthtype |= CURLAUTH_BASIC;
1138
+ } else {
1139
+ config.proxyauthtype &= ~CURLAUTH_BASIC;
1140
+ }
1141
+ break;
1142
+ case "anyauth":
1143
+ if (toggle) {
1144
+ config.authtype = CURLAUTH_ANY;
1145
+ }
1146
+ break;
1147
+ case "proxy-anyauth":
1148
+ if (toggle) {
1149
+ config.proxyauthtype = CURLAUTH_ANY;
1150
+ }
1151
+ break;
1152
+ case "location":
1153
+ config["location"] = toggle;
1154
+ break;
1155
+ case "location-trusted":
1156
+ config["location"] = toggle;
1157
+ config["location-trusted"] = toggle;
1158
+ break;
1159
+ case "http1.0":
1160
+ config.httpVersion = "1.0";
1161
+ break;
1162
+ case "http1.1":
1163
+ config.httpVersion = "1.1";
1164
+ break;
1165
+ case "http2":
1166
+ config.httpVersion = "2";
1167
+ break;
1168
+ case "http2-prior-knowledge":
1169
+ config.httpVersion = "2-prior-knowledge";
1170
+ break;
1171
+ case "http3":
1172
+ config.httpVersion = "3";
1173
+ break;
1174
+ case "http3-only":
1175
+ config.httpVersion = "3-only";
1176
+ break;
1177
+ case "tlsv1":
1178
+ config.tlsVersion = "1";
1179
+ break;
1180
+ case "tlsv1.0":
1181
+ config.tlsVersion = "1.0";
1182
+ break;
1183
+ case "tlsv1.1":
1184
+ config.tlsVersion = "1.1";
1185
+ break;
1186
+ case "tlsv1.2":
1187
+ config.tlsVersion = "1.2";
1188
+ break;
1189
+ case "tlsv1.3":
1190
+ config.tlsVersion = "1.3";
1191
+ break;
1192
+ case "verbose":
1193
+ case "version":
1194
+ case "trace-time":
1195
+ case "test-event":
1196
+ case "progress-bar":
1197
+ case "progress-meter":
1198
+ case "fail-early":
1199
+ case "styled-output":
1200
+ case "help":
1201
+ case "silent":
1202
+ case "show-error":
1203
+ case "parallel":
1204
+ case "parallel-immediate":
1205
+ case "stdin": // --stdin or - is a curlconverter specific option
1206
+ global_[argName] = toggle;
1207
+ break;
1208
+ case "next":
1209
+ // curl ignores --next if the last url node doesn't have a url
1210
+ if (
1211
+ toggle &&
1212
+ config.url &&
1213
+ config.url.length > 0 &&
1214
+ config.url.length >= (config["upload-file"] || []).length &&
1215
+ config.url.length >= (config.output || []).length
1216
+ ) {
1217
+ config = { authtype: CURLAUTH_BASIC, proxyauthtype: CURLAUTH_BASIC };
1218
+ global_.configs.push(config);
1219
+ }
1220
+ break;
1221
+ default:
1222
+ config[argName] = toggle;
1223
+ }
1224
+ return config;
1225
+ }
1226
+
1227
+ export function parseArgs(
1228
+ args: Word[],
1229
+ longOpts: LongOpts = curlLongOpts,
1230
+ shortenedLongOpts: LongOpts = curlLongOptsShortened,
1231
+ shortOpts: ShortOpts = curlShortOpts,
1232
+ supportedOpts?: Set<string>,
1233
+ warnings: Warnings = [],
1234
+ ): [GlobalConfig, [string, string][]] {
1235
+ let config: OperationConfig = {
1236
+ authtype: CURLAUTH_BASIC,
1237
+ proxyauthtype: CURLAUTH_BASIC,
1238
+ };
1239
+ const global_: GlobalConfig = { configs: [config], warnings };
1240
+ const seen: [string, string][] = [];
1241
+
1242
+ for (let i = 1, stillflags = true; i < args.length; i++) {
1243
+ const arg: Word = args[i];
1244
+ if (stillflags && arg.startsWith("-")) {
1245
+ if (eq(arg, "--")) {
1246
+ /* This indicates the end of the flags and thus enables the
1247
+ following (URL) argument to start with -. */
1248
+ stillflags = false;
1249
+ } else if (arg.startsWith("--")) {
1250
+ const shellToken = firstShellToken(arg);
1251
+ if (shellToken) {
1252
+ // TODO: if there's any text after the "--" or after the variable
1253
+ // we could narrow it down.
1254
+ throw new CCError(
1255
+ "this " +
1256
+ shellToken.type +
1257
+ " could " +
1258
+ (shellToken.type === "command" ? "return" : "be") +
1259
+ " anything\n" +
1260
+ underlineNode(shellToken.syntaxNode),
1261
+ );
1262
+ }
1263
+ const argStr = arg.toString();
1264
+
1265
+ const lookup = argStr.slice(2);
1266
+ let longArg = shortenedLongOpts[lookup];
1267
+ if (typeof longArg === "undefined") {
1268
+ longArg = longOpts[lookup];
1269
+ }
1270
+
1271
+ if (longArg === null) {
1272
+ throw new CCError("option " + argStr + ": is ambiguous");
1273
+ }
1274
+ if (typeof longArg === "undefined") {
1275
+ // TODO: extract a list of deleted arguments to check here
1276
+ throw new CCError("option " + argStr + ": is unknown");
1277
+ }
1278
+
1279
+ if (longArg.type === "string") {
1280
+ i++;
1281
+ if (i >= args.length) {
1282
+ throw new CCError("option " + argStr + ": requires parameter");
1283
+ }
1284
+ pushArgValue(global_, config, longArg.name, args[i]);
1285
+ } else {
1286
+ config = setArgValue(
1287
+ global_,
1288
+ config,
1289
+ longArg.name,
1290
+ toBoolean(argStr.slice(2)),
1291
+ ); // TODO: all shortened args work correctly?
1292
+ }
1293
+
1294
+ checkSupported(global_, argStr, longArg, supportedOpts);
1295
+ seen.push([longArg.name, argStr]);
1296
+ } else {
1297
+ // Short option. These can look like
1298
+ // -X POST -> {request: 'POST'}
1299
+ // or
1300
+ // -XPOST -> {request: 'POST'}
1301
+ // or multiple options
1302
+ // -ABCX POST -> {A: true, B: true, C: true, request: 'POST'}
1303
+ // or multiple options and a value for the last one
1304
+ // -ABCXPOST -> {A: true, B: true, C: true, request: 'POST'}
1305
+
1306
+ // "-" passed to curl as an argument raises an error,
1307
+ // curlconverter's command line uses it to read from stdin
1308
+ if (arg.length === 1) {
1309
+ if (Object.prototype.hasOwnProperty.call(shortOpts, "")) {
1310
+ const shortFor: string = shortOpts[""];
1311
+ const longArg = longOpts[shortFor];
1312
+ if (longArg === null) {
1313
+ throw new CCError("option -: is unknown");
1314
+ }
1315
+ config = setArgValue(
1316
+ global_,
1317
+ config,
1318
+ longArg.name,
1319
+ toBoolean(shortFor),
1320
+ );
1321
+ seen.push([longArg.name, "-"]);
1322
+ } else {
1323
+ throw new CCError("option -: is unknown");
1324
+ }
1325
+ }
1326
+
1327
+ for (let j = 1; j < arg.length; j++) {
1328
+ const jthChar = arg.get(j);
1329
+ if (typeof jthChar !== "string") {
1330
+ // A bash variable in the middle of a short option
1331
+ throw new CCError(
1332
+ "this " +
1333
+ jthChar.type +
1334
+ " could " +
1335
+ (jthChar.type === "command" ? "return" : "be") +
1336
+ " anything\n" +
1337
+ underlineNode(jthChar.syntaxNode),
1338
+ );
1339
+ }
1340
+ if (!has(shortOpts, jthChar)) {
1341
+ if (has(changedShortOpts, jthChar)) {
1342
+ throw new CCError(
1343
+ "option " + arg + ": " + changedShortOpts[jthChar],
1344
+ );
1345
+ }
1346
+ // TODO: there are a few deleted short options we could report
1347
+ throw new CCError("option " + arg + ": is unknown");
1348
+ }
1349
+ const lookup = jthChar;
1350
+ const shortFor = shortOpts[lookup];
1351
+ const longArg = longOpts[shortFor];
1352
+ if (longArg === null) {
1353
+ // This could happen if curlShortOpts points to a renamed option or has a typo
1354
+ throw new CCError("ambiguous short option -" + jthChar);
1355
+ }
1356
+ if (longArg.type === "string") {
1357
+ let val;
1358
+ if (j + 1 < arg.length) {
1359
+ // treat -XPOST as -X POST
1360
+ val = arg.slice(j + 1);
1361
+ j = arg.length;
1362
+ } else if (i + 1 < args.length) {
1363
+ i++;
1364
+ val = args[i];
1365
+ } else {
1366
+ throw new CCError(
1367
+ "option " + arg.toString() + ": requires parameter",
1368
+ );
1369
+ }
1370
+ pushArgValue(global_, config, longArg.name, val);
1371
+ } else {
1372
+ // Use shortFor because -N is short for --no-buffer
1373
+ // and we want to end up with {buffer: false}
1374
+ config = setArgValue(
1375
+ global_,
1376
+ config,
1377
+ longArg.name,
1378
+ toBoolean(shortFor),
1379
+ );
1380
+ }
1381
+ if (lookup) {
1382
+ checkSupported(global_, "-" + lookup, longArg, supportedOpts);
1383
+ seen.push([longArg.name, "-" + lookup]);
1384
+ }
1385
+ }
1386
+ }
1387
+ } else {
1388
+ if (
1389
+ typeof arg !== "string" &&
1390
+ arg.tokens.length &&
1391
+ typeof arg.tokens[0] !== "string"
1392
+ ) {
1393
+ const isOrBeginsWith = arg.tokens.length === 1 ? "is" : "begins with";
1394
+ warnings.push([
1395
+ "ambiguous argument",
1396
+ "argument " +
1397
+ isOrBeginsWith +
1398
+ " a " +
1399
+ arg.tokens[0].type +
1400
+ ", assuming it's a URL\n" +
1401
+ underlineNode(arg.tokens[0].syntaxNode),
1402
+ ]);
1403
+ }
1404
+ pushArgValue(global_, config, "url", arg);
1405
+ seen.push(["url", "--url"]);
1406
+ }
1407
+ }
1408
+
1409
+ for (const cfg of global_.configs) {
1410
+ for (const [arg, values] of Object.entries(cfg)) {
1411
+ if (Array.isArray(values) && !canBeList.has(arg)) {
1412
+ cfg[arg] = values[values.length - 1];
1413
+ }
1414
+ }
1415
+ }
1416
+ return [global_, seen];
1417
+ }