@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.
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/src/Headers.d.ts +23 -0
- package/dist/src/Headers.js +287 -0
- package/dist/src/Headers.js.map +1 -0
- package/dist/src/Query.d.ts +8 -0
- package/dist/src/Query.js +136 -0
- package/dist/src/Query.js.map +1 -0
- package/dist/src/Request.d.ts +200 -0
- package/dist/src/Request.js +1191 -0
- package/dist/src/Request.js.map +1 -0
- package/dist/src/Warnings.d.ts +15 -0
- package/dist/src/Warnings.js +111 -0
- package/dist/src/Warnings.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +333 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/curl/auth.d.ts +12 -0
- package/dist/src/curl/auth.js +40 -0
- package/dist/src/curl/auth.js.map +1 -0
- package/dist/src/curl/form.d.ts +28 -0
- package/dist/src/curl/form.js +218 -0
- package/dist/src/curl/form.js.map +1 -0
- package/dist/src/curl/opts.d.ts +2052 -0
- package/dist/src/curl/opts.js +1000 -0
- package/dist/src/curl/opts.js.map +1 -0
- package/dist/src/curl/url.d.ts +14 -0
- package/dist/src/curl/url.js +218 -0
- package/dist/src/curl/url.js.map +1 -0
- package/dist/src/generators/ansible.d.ts +5 -0
- package/dist/src/generators/ansible.js +282 -0
- package/dist/src/generators/ansible.js.map +1 -0
- package/dist/src/generators/c.d.ts +12 -0
- package/dist/src/generators/c.js +1230 -0
- package/dist/src/generators/c.js.map +1 -0
- package/dist/src/generators/cfml.d.ts +5 -0
- package/dist/src/generators/cfml.js +134 -0
- package/dist/src/generators/cfml.js.map +1 -0
- package/dist/src/generators/clojure.d.ts +7 -0
- package/dist/src/generators/clojure.js +436 -0
- package/dist/src/generators/clojure.js.map +1 -0
- package/dist/src/generators/csharp.d.ts +8 -0
- package/dist/src/generators/csharp.js +356 -0
- package/dist/src/generators/csharp.js.map +1 -0
- package/dist/src/generators/dart.d.ts +5 -0
- package/dist/src/generators/dart.js +273 -0
- package/dist/src/generators/dart.js.map +1 -0
- package/dist/src/generators/elixir.d.ts +8 -0
- package/dist/src/generators/elixir.js +296 -0
- package/dist/src/generators/elixir.js.map +1 -0
- package/dist/src/generators/go.d.ts +5 -0
- package/dist/src/generators/go.js +228 -0
- package/dist/src/generators/go.js.map +1 -0
- package/dist/src/generators/har.d.ts +7 -0
- package/dist/src/generators/har.js +115 -0
- package/dist/src/generators/har.js.map +1 -0
- package/dist/src/generators/http.d.ts +7 -0
- package/dist/src/generators/http.js +165 -0
- package/dist/src/generators/http.js.map +1 -0
- package/dist/src/generators/httpie.d.ts +5 -0
- package/dist/src/generators/httpie.js +446 -0
- package/dist/src/generators/httpie.js.map +1 -0
- package/dist/src/generators/java/httpurlconnection.d.ts +5 -0
- package/dist/src/generators/java/httpurlconnection.js +123 -0
- package/dist/src/generators/java/httpurlconnection.js.map +1 -0
- package/dist/src/generators/java/java.d.ts +8 -0
- package/dist/src/generators/java/java.js +247 -0
- package/dist/src/generators/java/java.js.map +1 -0
- package/dist/src/generators/java/jsoup.d.ts +5 -0
- package/dist/src/generators/java/jsoup.js +152 -0
- package/dist/src/generators/java/jsoup.js.map +1 -0
- package/dist/src/generators/java/okhttp.d.ts +5 -0
- package/dist/src/generators/java/okhttp.js +232 -0
- package/dist/src/generators/java/okhttp.js.map +1 -0
- package/dist/src/generators/javascript/axios.d.ts +5 -0
- package/dist/src/generators/javascript/axios.js +332 -0
- package/dist/src/generators/javascript/axios.js.map +1 -0
- package/dist/src/generators/javascript/got.d.ts +5 -0
- package/dist/src/generators/javascript/got.js +277 -0
- package/dist/src/generators/javascript/got.js.map +1 -0
- package/dist/src/generators/javascript/http.d.ts +8 -0
- package/dist/src/generators/javascript/http.js +183 -0
- package/dist/src/generators/javascript/http.js.map +1 -0
- package/dist/src/generators/javascript/javascript.d.ts +37 -0
- package/dist/src/generators/javascript/javascript.js +676 -0
- package/dist/src/generators/javascript/javascript.js.map +1 -0
- package/dist/src/generators/javascript/jquery.d.ts +15 -0
- package/dist/src/generators/javascript/jquery.js +297 -0
- package/dist/src/generators/javascript/jquery.js.map +1 -0
- package/dist/src/generators/javascript/ky.d.ts +7 -0
- package/dist/src/generators/javascript/ky.js +245 -0
- package/dist/src/generators/javascript/ky.js.map +1 -0
- package/dist/src/generators/javascript/request.d.ts +5 -0
- package/dist/src/generators/javascript/request.js +113 -0
- package/dist/src/generators/javascript/request.js.map +1 -0
- package/dist/src/generators/javascript/superagent.d.ts +10 -0
- package/dist/src/generators/javascript/superagent.js +301 -0
- package/dist/src/generators/javascript/superagent.js.map +1 -0
- package/dist/src/generators/javascript/xhr.d.ts +8 -0
- package/dist/src/generators/javascript/xhr.js +147 -0
- package/dist/src/generators/javascript/xhr.js.map +1 -0
- package/dist/src/generators/json.d.ts +45 -0
- package/dist/src/generators/json.js +197 -0
- package/dist/src/generators/json.js.map +1 -0
- package/dist/src/generators/julia.d.ts +8 -0
- package/dist/src/generators/julia.js +365 -0
- package/dist/src/generators/julia.js.map +1 -0
- package/dist/src/generators/kotlin.d.ts +8 -0
- package/dist/src/generators/kotlin.js +325 -0
- package/dist/src/generators/kotlin.js.map +1 -0
- package/dist/src/generators/lua.d.ts +5 -0
- package/dist/src/generators/lua.js +192 -0
- package/dist/src/generators/lua.js.map +1 -0
- package/dist/src/generators/matlab/common.d.ts +16 -0
- package/dist/src/generators/matlab/common.js +238 -0
- package/dist/src/generators/matlab/common.js.map +1 -0
- package/dist/src/generators/matlab/httpinterface.d.ts +2 -0
- package/dist/src/generators/matlab/httpinterface.js +211 -0
- package/dist/src/generators/matlab/httpinterface.js.map +1 -0
- package/dist/src/generators/matlab/matlab.d.ts +5 -0
- package/dist/src/generators/matlab/matlab.js +29 -0
- package/dist/src/generators/matlab/matlab.js.map +1 -0
- package/dist/src/generators/matlab/webservices.d.ts +2 -0
- package/dist/src/generators/matlab/webservices.js +191 -0
- package/dist/src/generators/matlab/webservices.js.map +1 -0
- package/dist/src/generators/objectivec.d.ts +8 -0
- package/dist/src/generators/objectivec.js +269 -0
- package/dist/src/generators/objectivec.js.map +1 -0
- package/dist/src/generators/ocaml.d.ts +8 -0
- package/dist/src/generators/ocaml.js +150 -0
- package/dist/src/generators/ocaml.js.map +1 -0
- package/dist/src/generators/perl.d.ts +9 -0
- package/dist/src/generators/perl.js +209 -0
- package/dist/src/generators/perl.js.map +1 -0
- package/dist/src/generators/php/guzzle.d.ts +5 -0
- package/dist/src/generators/php/guzzle.js +328 -0
- package/dist/src/generators/php/guzzle.js.map +1 -0
- package/dist/src/generators/php/php.d.ts +8 -0
- package/dist/src/generators/php/php.js +217 -0
- package/dist/src/generators/php/php.js.map +1 -0
- package/dist/src/generators/php/requests.d.ts +5 -0
- package/dist/src/generators/php/requests.js +89 -0
- package/dist/src/generators/php/requests.js.map +1 -0
- package/dist/src/generators/powershell.d.ts +11 -0
- package/dist/src/generators/powershell.js +377 -0
- package/dist/src/generators/powershell.js.map +1 -0
- package/dist/src/generators/python/http.d.ts +5 -0
- package/dist/src/generators/python/http.js +128 -0
- package/dist/src/generators/python/http.js.map +1 -0
- package/dist/src/generators/python/python.d.ts +22 -0
- package/dist/src/generators/python/python.js +1693 -0
- package/dist/src/generators/python/python.js.map +1 -0
- package/dist/src/generators/r/httr.d.ts +10 -0
- package/dist/src/generators/r/httr.js +298 -0
- package/dist/src/generators/r/httr.js.map +1 -0
- package/dist/src/generators/r/httr2.d.ts +5 -0
- package/dist/src/generators/r/httr2.js +214 -0
- package/dist/src/generators/r/httr2.js.map +1 -0
- package/dist/src/generators/ruby/httparty.d.ts +6 -0
- package/dist/src/generators/ruby/httparty.js +308 -0
- package/dist/src/generators/ruby/httparty.js.map +1 -0
- package/dist/src/generators/ruby/ruby.d.ts +14 -0
- package/dist/src/generators/ruby/ruby.js +515 -0
- package/dist/src/generators/ruby/ruby.js.map +1 -0
- package/dist/src/generators/rust.d.ts +8 -0
- package/dist/src/generators/rust.js +177 -0
- package/dist/src/generators/rust.js.map +1 -0
- package/dist/src/generators/swift.d.ts +8 -0
- package/dist/src/generators/swift.js +219 -0
- package/dist/src/generators/swift.js.map +1 -0
- package/dist/src/generators/wget.d.ts +8 -0
- package/dist/src/generators/wget.js +472 -0
- package/dist/src/generators/wget.js.map +1 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/index.js +54 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/parse.d.ts +13 -0
- package/dist/src/parse.js +43 -0
- package/dist/src/parse.js.map +1 -0
- package/dist/src/shell/Parser.d.ts +4 -0
- package/dist/src/shell/Parser.js +6 -0
- package/dist/src/shell/Parser.js.map +1 -0
- package/dist/src/shell/Word.d.ts +48 -0
- package/dist/src/shell/Word.js +486 -0
- package/dist/src/shell/Word.js.map +1 -0
- package/dist/src/shell/tokenizer.d.ts +3 -0
- package/dist/src/shell/tokenizer.js +610 -0
- package/dist/src/shell/tokenizer.js.map +1 -0
- package/dist/src/shell/webParser.d.ts +4 -0
- package/dist/src/shell/webParser.js +15 -0
- package/dist/src/shell/webParser.js.map +1 -0
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.js +21 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tools/compare-requests.d.ts +2 -0
- package/dist/tools/compare-requests.js +448 -0
- package/dist/tools/compare-requests.js.map +1 -0
- package/dist/tools/gen-test.d.ts +2 -0
- package/dist/tools/gen-test.js +114 -0
- package/dist/tools/gen-test.js.map +1 -0
- package/dist/tree-sitter-bash.wasm +0 -0
- package/index.d.ts +3 -0
- package/package.json +97 -0
- package/src/Headers.ts +334 -0
- package/src/Query.ts +147 -0
- package/src/Request.ts +1649 -0
- package/src/Warnings.ts +154 -0
- package/src/cli.ts +561 -0
- package/src/curl/auth.ts +45 -0
- package/src/curl/form.ts +297 -0
- package/src/curl/opts.ts +1417 -0
- package/src/curl/url.ts +241 -0
- package/src/generators/ansible.ts +364 -0
- package/src/generators/c.ts +1371 -0
- package/src/generators/cfml.ts +155 -0
- package/src/generators/clojure.ts +521 -0
- package/src/generators/csharp.ts +383 -0
- package/src/generators/dart.ts +293 -0
- package/src/generators/elixir.ts +349 -0
- package/src/generators/go.ts +269 -0
- package/src/generators/har.ts +147 -0
- package/src/generators/http.ts +194 -0
- package/src/generators/httpie.ts +506 -0
- package/src/generators/java/httpurlconnection.ts +151 -0
- package/src/generators/java/java.ts +280 -0
- package/src/generators/java/jsoup.ts +172 -0
- package/src/generators/java/okhttp.ts +257 -0
- package/src/generators/javascript/axios.ts +395 -0
- package/src/generators/javascript/got.ts +362 -0
- package/src/generators/javascript/http.ts +232 -0
- package/src/generators/javascript/javascript.ts +825 -0
- package/src/generators/javascript/jquery.ts +360 -0
- package/src/generators/javascript/ky.ts +315 -0
- package/src/generators/javascript/request.ts +152 -0
- package/src/generators/javascript/superagent.ts +373 -0
- package/src/generators/javascript/xhr.ts +192 -0
- package/src/generators/json.ts +293 -0
- package/src/generators/julia.ts +398 -0
- package/src/generators/kotlin.ts +355 -0
- package/src/generators/lua.ts +209 -0
- package/src/generators/matlab/common.ts +281 -0
- package/src/generators/matlab/httpinterface.ts +284 -0
- package/src/generators/matlab/matlab.ts +39 -0
- package/src/generators/matlab/webservices.ts +263 -0
- package/src/generators/objectivec.ts +297 -0
- package/src/generators/ocaml.ts +168 -0
- package/src/generators/perl.ts +237 -0
- package/src/generators/php/guzzle.ts +368 -0
- package/src/generators/php/php.ts +239 -0
- package/src/generators/php/requests.ts +103 -0
- package/src/generators/powershell.ts +430 -0
- package/src/generators/python/http.ts +167 -0
- package/src/generators/python/python.ts +1934 -0
- package/src/generators/r/httr.ts +328 -0
- package/src/generators/r/httr2.ts +268 -0
- package/src/generators/ruby/httparty.ts +351 -0
- package/src/generators/ruby/ruby.ts +564 -0
- package/src/generators/rust.ts +243 -0
- package/src/generators/swift.ts +235 -0
- package/src/generators/wget.ts +533 -0
- package/src/index.ts +89 -0
- package/src/parse.ts +72 -0
- package/src/shell/Parser.ts +8 -0
- package/src/shell/Word.ts +531 -0
- package/src/shell/tokenizer.ts +736 -0
- package/src/shell/webParser.ts +18 -0
- package/src/utils.ts +25 -0
- package/tools/compare-requests.ts +571 -0
- package/tools/extract_curl_args.py +511 -0
- package/tools/gen-test.ts +129 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# This script assumes ../curl/ is a git repo containing curl's source code
|
|
4
|
+
# and extracts the list of arguments curl accepts and writes the result as
|
|
5
|
+
# two JS objects (one for --long-options and one for -s (short) options)
|
|
6
|
+
# to ../src/util.ts.
|
|
7
|
+
#
|
|
8
|
+
# https://github.com/curl/curl/blob/master/src/tool_getparam.c#L72
|
|
9
|
+
#
|
|
10
|
+
# Each argument definition is composed of
|
|
11
|
+
# letter - a 1 or 2 character string which acts as both a unique identifier
|
|
12
|
+
# of this argument, as well as its short form if it's 1 character long.
|
|
13
|
+
# lname - the --long-name of this option
|
|
14
|
+
# desc - the type of the option, which specifies if the option consumes a
|
|
15
|
+
# second argument or not.
|
|
16
|
+
# ARG_STRING, ARG_FILENAME - consume a second argument
|
|
17
|
+
# ARG_BOOL, ARG_NONE - don't consume a second argument.
|
|
18
|
+
# TRUE / FALSE - no longer used
|
|
19
|
+
# ARG_BOOL arguments get a --no-<lname> counterpart. ARG_NONE arguments do not.
|
|
20
|
+
#
|
|
21
|
+
# Options can have the same `letter` when an option was renamed but
|
|
22
|
+
# the old name was also kept for backwards compatibility.
|
|
23
|
+
# We add a "name" property with the newest name to these options.
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import subprocess
|
|
28
|
+
import sys
|
|
29
|
+
from collections import Counter
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
# Git repo of curl's source code to extract the args from
|
|
33
|
+
CURL_REPO = Path(__file__).parent.parent / "curl"
|
|
34
|
+
|
|
35
|
+
OLD_INPUT_FILE = CURL_REPO / "src" / "main.c"
|
|
36
|
+
NEW_INPUT_FILE = CURL_REPO / "src" / "tool_getparam.c"
|
|
37
|
+
FILE_MOVED_TAG = "curl-7_23_0" # when the above change happened
|
|
38
|
+
|
|
39
|
+
# Originally there were only two arg "types": TRUE/FALSE which signified
|
|
40
|
+
# whether the option expected a value or was a boolean, respectively.
|
|
41
|
+
# Then in
|
|
42
|
+
# 5abfdc0140df0977b02506d16796f616158bfe88
|
|
43
|
+
# which was released as
|
|
44
|
+
NO_OPTIONS_TAG = "curl-7_19_0"
|
|
45
|
+
# all boolean (i.e. FALSE "type") options got an implicit --no-OPTION.
|
|
46
|
+
# Then TRUE/FALSE was changed to ARG_STRING/ARG_BOOL.
|
|
47
|
+
# Then it was realized that not all boolean options should have a
|
|
48
|
+
# --no-OPTION counterpart, so a new ARG_NONE type was added for those in
|
|
49
|
+
# 913c3c8f5476bd7bc4d8d00509396bd4b525b8fc
|
|
50
|
+
|
|
51
|
+
OPTS_START = "struct LongShort aliases[]= {"
|
|
52
|
+
OPTS_END = "};"
|
|
53
|
+
|
|
54
|
+
BOOL_TYPES = ["bool", "none"]
|
|
55
|
+
STR_TYPES = ["string", "filename"]
|
|
56
|
+
ALIAS_TYPES = BOOL_TYPES + STR_TYPES
|
|
57
|
+
RAW_ALIAS_TYPES = ALIAS_TYPES + ["true", "false"]
|
|
58
|
+
|
|
59
|
+
OUTPUT_FILE = Path(__file__).parent.parent / "src" / "curl" / "opts.ts"
|
|
60
|
+
|
|
61
|
+
JS_PARAMS_START = "BEGIN EXTRACTED OPTIONS"
|
|
62
|
+
JS_PARAMS_END = "END EXTRACTED OPTIONS"
|
|
63
|
+
JS_SHORT_PARAMS_START = "BEGIN EXTRACTED SHORT OPTIONS"
|
|
64
|
+
JS_SHORT_PARAMS_END = "END EXTRACTED SHORT OPTIONS"
|
|
65
|
+
|
|
66
|
+
PACKAGE_JSON = Path(__file__).parent.parent / "package.json"
|
|
67
|
+
CLI_FILE = Path(__file__).parent.parent / "src" / "cli.ts"
|
|
68
|
+
CLI_VERSION_LINE_START = "const VERSION = "
|
|
69
|
+
|
|
70
|
+
# These are options with the same `letter`, which are options that were
|
|
71
|
+
# renamed, along with their new name.
|
|
72
|
+
DUPES = {
|
|
73
|
+
"krb4": "krb",
|
|
74
|
+
"ftp-ssl": "ssl",
|
|
75
|
+
"ftp-ssl-reqd": "ssl-reqd",
|
|
76
|
+
"socks5-gssapi-service": "proxy-service-name",
|
|
77
|
+
# These argument names have been deleted,
|
|
78
|
+
# they should appear as deleted options.
|
|
79
|
+
"http-request": "request",
|
|
80
|
+
"ftp-ascii": "use-ascii",
|
|
81
|
+
"ftpport": "ftp-port",
|
|
82
|
+
"socks": "socks5",
|
|
83
|
+
}
|
|
84
|
+
for value in list(DUPES.values()):
|
|
85
|
+
DUPES[value] = value
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
parser = argparse.ArgumentParser(
|
|
89
|
+
prog="extract_curl_args",
|
|
90
|
+
description="extract a list of curl's arguments from its source code into a JavaScript file",
|
|
91
|
+
)
|
|
92
|
+
parser.add_argument("repo_dir", nargs="?", default=CURL_REPO, type=Path)
|
|
93
|
+
parser.add_argument(
|
|
94
|
+
"-w",
|
|
95
|
+
"--write",
|
|
96
|
+
action="store_true",
|
|
97
|
+
help="write changes to " + str(OUTPUT_FILE) + " and " + str(CLI_FILE),
|
|
98
|
+
)
|
|
99
|
+
args = parser.parse_args()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def is_git_repo(git_dir=args.repo_dir):
|
|
103
|
+
result = subprocess.run(
|
|
104
|
+
["git", "rev-parse", "--is-inside-work-tree"],
|
|
105
|
+
cwd=git_dir,
|
|
106
|
+
capture_output=True,
|
|
107
|
+
text=True,
|
|
108
|
+
)
|
|
109
|
+
return result.returncode == 0 and result.stdout.strip() == "true"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if not OUTPUT_FILE.is_file():
|
|
113
|
+
sys.exit(
|
|
114
|
+
f"{OUTPUT_FILE} doesn't exist. You should run this script from curlconverter/"
|
|
115
|
+
)
|
|
116
|
+
if not args.repo_dir.is_dir():
|
|
117
|
+
sys.exit(
|
|
118
|
+
f"{args.repo_dir} needs to be a git repo with curl's source code. "
|
|
119
|
+
"You can clone it with\n\n"
|
|
120
|
+
"git clone https://github.com/curl/curl ../curl"
|
|
121
|
+
# or modify the args.repo_dir variable above
|
|
122
|
+
)
|
|
123
|
+
if not is_git_repo(args.repo_dir):
|
|
124
|
+
sys.exit(f"{args.repo_dir} is not a git repo")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def git_pull(git_dir=args.repo_dir):
|
|
128
|
+
return subprocess.run(
|
|
129
|
+
["git", "pull"],
|
|
130
|
+
cwd=git_dir,
|
|
131
|
+
check=True,
|
|
132
|
+
capture_output=True,
|
|
133
|
+
text=True,
|
|
134
|
+
).stdout
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
git_pull()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def git_branch(git_dir=args.repo_dir):
|
|
141
|
+
branch = subprocess.run(
|
|
142
|
+
["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
|
143
|
+
cwd=git_dir,
|
|
144
|
+
check=True,
|
|
145
|
+
capture_output=True,
|
|
146
|
+
text=True,
|
|
147
|
+
).stdout
|
|
148
|
+
return branch.strip()
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def parse_aliases(lines):
|
|
152
|
+
aliases = {}
|
|
153
|
+
for line in lines:
|
|
154
|
+
if OPTS_START in line:
|
|
155
|
+
break
|
|
156
|
+
for line in lines:
|
|
157
|
+
line = line.strip()
|
|
158
|
+
if line.endswith(OPTS_END):
|
|
159
|
+
break
|
|
160
|
+
if not line.strip().startswith("{"):
|
|
161
|
+
continue
|
|
162
|
+
|
|
163
|
+
# main.c has comments on the same line
|
|
164
|
+
letter, lname, desc = line.split("/*")[0].strip().strip("{},").split(",")
|
|
165
|
+
|
|
166
|
+
letter = letter.strip().strip('"')
|
|
167
|
+
lname = lname.strip().strip('"')
|
|
168
|
+
type_ = desc.strip().removeprefix("ARG_").lower()
|
|
169
|
+
# The only difference is that ARG_FILENAMEs raise a warning if you pass a value
|
|
170
|
+
# that starts with '-'
|
|
171
|
+
if type_ == "filename":
|
|
172
|
+
type_ = "string"
|
|
173
|
+
# TODO: for most options, if you specify them more than once, only the last
|
|
174
|
+
# one is taken. For others, (such as --url) each value is appended to a list
|
|
175
|
+
# and all are processed. This would require parsing the C code in the switch
|
|
176
|
+
# statement that processes the options.
|
|
177
|
+
|
|
178
|
+
if 1 > len(letter) > 2:
|
|
179
|
+
raise ValueError(f"letter form of --{lname} must be 1 or 2 characters long")
|
|
180
|
+
if type_ not in RAW_ALIAS_TYPES:
|
|
181
|
+
raise ValueError(f"unknown desc for --{lname}: {desc!r}")
|
|
182
|
+
|
|
183
|
+
alias = {"letter": letter, "lname": lname, "type": type_}
|
|
184
|
+
if lname in aliases and aliases[lname] != alias:
|
|
185
|
+
print(
|
|
186
|
+
f"{lname!r} repeated with different values:\n"
|
|
187
|
+
+ f"{aliases[lname]}\n"
|
|
188
|
+
+ f"{alias}",
|
|
189
|
+
file=sys.stderr,
|
|
190
|
+
)
|
|
191
|
+
aliases[lname] = alias
|
|
192
|
+
|
|
193
|
+
return list(aliases.values())
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def fill_out_aliases(aliases, add_no_options=True, assumptions=set()):
|
|
197
|
+
# If both --option and --other-option have "oO" (for example) as their `letter`,
|
|
198
|
+
# add a "name" property with the main option's `lname`
|
|
199
|
+
letter_count = Counter(a["letter"] for a in aliases)
|
|
200
|
+
|
|
201
|
+
# "ARB_BOOL"-type OPTIONs have a --no-OPTION counterpart
|
|
202
|
+
no_aliases = []
|
|
203
|
+
|
|
204
|
+
for idx, alias in enumerate(aliases):
|
|
205
|
+
if alias["type"] == "true":
|
|
206
|
+
alias["type"] = "string"
|
|
207
|
+
if alias["type"] == "false":
|
|
208
|
+
alias["type"] = "bool" if add_no_options else "none"
|
|
209
|
+
|
|
210
|
+
if alias["type"] in BOOL_TYPES:
|
|
211
|
+
without_no = alias["lname"].removeprefix("no-").removeprefix("disable-")
|
|
212
|
+
if alias["lname"] != without_no:
|
|
213
|
+
assumption = f"Assuming --{alias['lname']} is {without_no!r}"
|
|
214
|
+
if assumption not in assumptions:
|
|
215
|
+
assumptions.add(assumption)
|
|
216
|
+
print(assumption, file=sys.stderr)
|
|
217
|
+
alias["name"] = without_no
|
|
218
|
+
|
|
219
|
+
alias["name"] = alias["lname"]
|
|
220
|
+
if letter_count[alias["letter"]] > 1:
|
|
221
|
+
# Raise KeyError if special case hasn't been added yet
|
|
222
|
+
candidate = DUPES[alias["lname"]]
|
|
223
|
+
if alias["lname"] != candidate:
|
|
224
|
+
alias["name"] = candidate
|
|
225
|
+
|
|
226
|
+
if alias["type"] == "bool":
|
|
227
|
+
no_alias = {
|
|
228
|
+
**alias,
|
|
229
|
+
"name": alias.get("name", alias["lname"]),
|
|
230
|
+
"lname": "no-" + alias["lname"],
|
|
231
|
+
# --no-OPTION options cannot be shortened
|
|
232
|
+
"expand": False,
|
|
233
|
+
}
|
|
234
|
+
no_aliases.append((idx, no_alias))
|
|
235
|
+
elif alias["type"] == "none":
|
|
236
|
+
# The none/bool distinction is irrelevant after the step above
|
|
237
|
+
alias["type"] = "bool"
|
|
238
|
+
|
|
239
|
+
for i, (insert_idx, no_alias) in enumerate(no_aliases):
|
|
240
|
+
# +1 so that --no-OPTION appears after --OPTION
|
|
241
|
+
aliases.insert(insert_idx + i + 1, no_alias)
|
|
242
|
+
|
|
243
|
+
return aliases
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def split(aliases):
|
|
247
|
+
long_args = {}
|
|
248
|
+
short_args = {}
|
|
249
|
+
for alias in aliases:
|
|
250
|
+
if alias["lname"] in long_args:
|
|
251
|
+
raise ValueError(f"duplicate lname: {alias['lname']!r}")
|
|
252
|
+
long_args[alias["lname"]] = {
|
|
253
|
+
k: v for k, v in alias.items() if k not in ["letter", "lname"]
|
|
254
|
+
}
|
|
255
|
+
if len(alias["letter"]) == 1:
|
|
256
|
+
alias_name = alias.get("name", alias["lname"])
|
|
257
|
+
if alias["letter"] == "N": # -N is short for --no-buffer
|
|
258
|
+
alias_name = "no-" + alias_name
|
|
259
|
+
if (
|
|
260
|
+
alias["letter"] in short_args
|
|
261
|
+
and short_args[alias["letter"]] != alias_name
|
|
262
|
+
):
|
|
263
|
+
raise ValueError(
|
|
264
|
+
f"duplicate short arg {alias['letter']!r}: {short_args[alias['letter']]!r} {alias_name!r}"
|
|
265
|
+
)
|
|
266
|
+
short_args[alias["letter"]] = alias_name
|
|
267
|
+
return long_args, short_args
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def format_as_js(d, indent=" ", indent_level=0):
|
|
271
|
+
for top_key, opt in d.items():
|
|
272
|
+
|
|
273
|
+
def quote(key):
|
|
274
|
+
return json.dumps(key, ensure_ascii=False)
|
|
275
|
+
|
|
276
|
+
def val_to_js(val):
|
|
277
|
+
if isinstance(val, str):
|
|
278
|
+
return quote(val)
|
|
279
|
+
if isinstance(val, bool):
|
|
280
|
+
return str(val).lower()
|
|
281
|
+
raise TypeError(f"can't convert values of type {type(val)} to JS")
|
|
282
|
+
|
|
283
|
+
if isinstance(opt, dict):
|
|
284
|
+
vals = [
|
|
285
|
+
f"{k if k.isalpha() else quote(k)}: {val_to_js(v)}"
|
|
286
|
+
for k, v in opt.items()
|
|
287
|
+
]
|
|
288
|
+
yield f"{indent * (indent_level + 1)}{quote(top_key)}: {{ {', '.join(vals)} }},"
|
|
289
|
+
elif isinstance(opt, str):
|
|
290
|
+
yield f"{indent * (indent_level + 1)}{quote(top_key)}: {val_to_js(opt)},"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def parse_tag(tag):
|
|
294
|
+
if not tag.startswith("curl-") or tag.startswith("curl_"):
|
|
295
|
+
return None
|
|
296
|
+
version = tag.removeprefix("curl-").removeprefix("curl_")
|
|
297
|
+
version, *extra = version.split("-", 1)
|
|
298
|
+
extra = extra[0] if extra else ""
|
|
299
|
+
major, minor, *patch = version.split("_", 2)
|
|
300
|
+
if len(patch) > 1:
|
|
301
|
+
raise ValueError(f"unknown patch version {patch} from tag {tag}")
|
|
302
|
+
patch = patch[0] if patch else "0"
|
|
303
|
+
if not patch.isdigit():
|
|
304
|
+
if extra:
|
|
305
|
+
raise ValueError(f"two extras? {tag}")
|
|
306
|
+
extra = patch
|
|
307
|
+
patch = "0"
|
|
308
|
+
if extra: # filter pre-releases
|
|
309
|
+
return None
|
|
310
|
+
return int(major), int(minor), int(patch)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def curl_tags(git_dir=args.repo_dir):
|
|
314
|
+
tags = (
|
|
315
|
+
subprocess.run(
|
|
316
|
+
["git", "tag"],
|
|
317
|
+
cwd=git_dir,
|
|
318
|
+
check=True,
|
|
319
|
+
capture_output=True,
|
|
320
|
+
text=True,
|
|
321
|
+
)
|
|
322
|
+
.stdout.strip()
|
|
323
|
+
.splitlines()
|
|
324
|
+
)
|
|
325
|
+
for tag in tags:
|
|
326
|
+
if parse_tag(tag):
|
|
327
|
+
yield tag
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def file_at_commit(filename, commit_hash, git_dir=args.repo_dir):
|
|
331
|
+
contents = subprocess.run(
|
|
332
|
+
["git", "cat-file", "-p", f"{commit_hash}:{filename}"],
|
|
333
|
+
cwd=git_dir,
|
|
334
|
+
capture_output=True,
|
|
335
|
+
check=True,
|
|
336
|
+
).stdout
|
|
337
|
+
try:
|
|
338
|
+
contents = contents.decode("utf-8")
|
|
339
|
+
except UnicodeDecodeError:
|
|
340
|
+
contents = contents.decode("latin1")
|
|
341
|
+
return iter(contents.splitlines())
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
if __name__ == "__main__":
|
|
345
|
+
# TODO: check that repo is up to date
|
|
346
|
+
if not is_git_repo(args.repo_dir):
|
|
347
|
+
sys.exit(f"{args.repo_dir} is not a git repo")
|
|
348
|
+
|
|
349
|
+
tags = sorted(curl_tags(args.repo_dir), key=parse_tag)
|
|
350
|
+
|
|
351
|
+
aliases = {}
|
|
352
|
+
short_aliases = {}
|
|
353
|
+
filename = "src/main.c"
|
|
354
|
+
add_no_options = False
|
|
355
|
+
for tag in tags:
|
|
356
|
+
if tag == FILE_MOVED_TAG:
|
|
357
|
+
filename = "src/tool_getparam.c"
|
|
358
|
+
if tag == NO_OPTIONS_TAG:
|
|
359
|
+
add_no_options = True
|
|
360
|
+
f = file_at_commit(filename, tag)
|
|
361
|
+
aliases[tag] = {}
|
|
362
|
+
short_aliases[tag] = {}
|
|
363
|
+
for alias in fill_out_aliases(parse_aliases(f), add_no_options):
|
|
364
|
+
alias["expand"] = alias.get("expand", True)
|
|
365
|
+
alias_name = alias.get("name", alias["lname"])
|
|
366
|
+
alias_name = DUPES.get(alias_name, alias_name)
|
|
367
|
+
# alias['name'] = alias_name
|
|
368
|
+
if alias["lname"] in aliases[tag] and aliases[tag][alias["lname"]] != alias:
|
|
369
|
+
raise ValueError("duplicate alias: --" + alias["lname"])
|
|
370
|
+
# We don't want to report when curl changed the internal ID of some option
|
|
371
|
+
if len(alias["letter"]) == 1:
|
|
372
|
+
short_aliases[tag][alias["letter"]] = (alias_name, alias["type"])
|
|
373
|
+
del alias["letter"]
|
|
374
|
+
lname = alias["lname"]
|
|
375
|
+
del alias["lname"]
|
|
376
|
+
# TODO: figure out what to do about how shortenings change over time
|
|
377
|
+
del alias["expand"]
|
|
378
|
+
aliases[tag][lname] = alias
|
|
379
|
+
# TODO: report how shortened --long options change
|
|
380
|
+
|
|
381
|
+
for cur_tag, next_tag in zip(aliases.keys(), list(aliases.keys())[1:]):
|
|
382
|
+
cur_aliases = short_aliases[cur_tag]
|
|
383
|
+
next_aliases = short_aliases[next_tag]
|
|
384
|
+
latest_aliases = short_aliases[list(aliases.keys())[-1]]
|
|
385
|
+
|
|
386
|
+
# We don't care about when options got added
|
|
387
|
+
# new_aliases = next_aliases.keys() - cur_aliases.keys()
|
|
388
|
+
removed_aliases = cur_aliases.keys() - next_aliases.keys()
|
|
389
|
+
changed_aliases = []
|
|
390
|
+
for common_alias in cur_aliases.keys() & next_aliases.keys():
|
|
391
|
+
if cur_aliases[common_alias] != next_aliases[common_alias]:
|
|
392
|
+
changed_aliases.append(common_alias)
|
|
393
|
+
|
|
394
|
+
if removed_aliases or changed_aliases:
|
|
395
|
+
header = f"{cur_tag} -> {next_tag}"
|
|
396
|
+
print(header)
|
|
397
|
+
print("=" * len(header))
|
|
398
|
+
for removed_alias in removed_aliases:
|
|
399
|
+
print(f"- -{removed_alias} {cur_aliases[removed_alias]}")
|
|
400
|
+
currently = latest_aliases.get(removed_alias)
|
|
401
|
+
if currently:
|
|
402
|
+
# Could've been removed and added back multiple times, so what
|
|
403
|
+
# it is on master is not necessarily how it was added back next.
|
|
404
|
+
print(" added back later and is currently " + str(currently))
|
|
405
|
+
print()
|
|
406
|
+
for changed_alias in changed_aliases:
|
|
407
|
+
print(f"- -{changed_alias} {cur_aliases[changed_alias]}")
|
|
408
|
+
print(f"+ -{changed_alias} {next_aliases[changed_alias]}")
|
|
409
|
+
currently = latest_aliases.get(changed_alias, "(no longer exists)")
|
|
410
|
+
if currently != next_aliases[changed_alias]:
|
|
411
|
+
print(" later became " + str(currently))
|
|
412
|
+
print()
|
|
413
|
+
|
|
414
|
+
print("-" * 80)
|
|
415
|
+
print()
|
|
416
|
+
|
|
417
|
+
for cur_tag, next_tag in zip(aliases.keys(), list(aliases.keys())[1:]):
|
|
418
|
+
cur_aliases = aliases[cur_tag]
|
|
419
|
+
next_aliases = aliases[next_tag]
|
|
420
|
+
|
|
421
|
+
new_aliases = next_aliases.keys() - cur_aliases.keys()
|
|
422
|
+
removed_aliases = cur_aliases.keys() - next_aliases.keys()
|
|
423
|
+
changed_aliases = []
|
|
424
|
+
for common_alias in cur_aliases.keys() & next_aliases.keys():
|
|
425
|
+
if cur_aliases[common_alias] != next_aliases[common_alias]:
|
|
426
|
+
changed_aliases.append(common_alias)
|
|
427
|
+
|
|
428
|
+
# We don't care when aliases were added, only when/if they are removed,
|
|
429
|
+
# but we need to be able to see if an alias was added because it's actually
|
|
430
|
+
# replacing a previous alias.
|
|
431
|
+
# Only reporting added aliases when there are removed or changed aliases
|
|
432
|
+
# is probably good enough for that purpose.
|
|
433
|
+
if removed_aliases or changed_aliases: # or new_aliases:
|
|
434
|
+
header = f"{cur_tag} -> {next_tag}"
|
|
435
|
+
print(header)
|
|
436
|
+
print("=" * len(header))
|
|
437
|
+
for new_alias in new_aliases:
|
|
438
|
+
print(f"+ --{new_alias}: {next_aliases[new_alias]}")
|
|
439
|
+
print()
|
|
440
|
+
for removed_alias in removed_aliases:
|
|
441
|
+
print(f"- --{removed_alias}: {cur_aliases[removed_alias]}")
|
|
442
|
+
print()
|
|
443
|
+
for changed_alias in changed_aliases:
|
|
444
|
+
print(f"- --{changed_alias}: {cur_aliases[changed_alias]}")
|
|
445
|
+
print(f"+ --{changed_alias}: {next_aliases[changed_alias]}")
|
|
446
|
+
print()
|
|
447
|
+
|
|
448
|
+
current_aliases = fill_out_aliases(
|
|
449
|
+
parse_aliases(file_at_commit(filename, tags[-1])), add_no_options
|
|
450
|
+
)
|
|
451
|
+
long_args, short_args = split(current_aliases)
|
|
452
|
+
|
|
453
|
+
js_params_lines = list(format_as_js(long_args))
|
|
454
|
+
js_short_params_lines = list(format_as_js(short_args))
|
|
455
|
+
|
|
456
|
+
new_lines = []
|
|
457
|
+
with open(OUTPUT_FILE) as f:
|
|
458
|
+
|
|
459
|
+
def add_between(f, new_lines, adding_lines, start, end):
|
|
460
|
+
for line in f:
|
|
461
|
+
new_lines.append(line)
|
|
462
|
+
if start in line:
|
|
463
|
+
break
|
|
464
|
+
else:
|
|
465
|
+
raise ValueError(f"{'// ' + start!r} not in {OUTPUT_FILE}")
|
|
466
|
+
|
|
467
|
+
new_lines += [l + "\n" for l in adding_lines]
|
|
468
|
+
for line in f:
|
|
469
|
+
if end in line:
|
|
470
|
+
new_lines.append(line)
|
|
471
|
+
break
|
|
472
|
+
else:
|
|
473
|
+
raise ValueError(f"{'// ' + end!r} not in {OUTPUT_FILE}")
|
|
474
|
+
|
|
475
|
+
add_between(f, new_lines, js_params_lines, JS_PARAMS_START, JS_PARAMS_END)
|
|
476
|
+
add_between(
|
|
477
|
+
f,
|
|
478
|
+
new_lines,
|
|
479
|
+
js_short_params_lines,
|
|
480
|
+
JS_SHORT_PARAMS_START,
|
|
481
|
+
JS_SHORT_PARAMS_END,
|
|
482
|
+
)
|
|
483
|
+
for line in f:
|
|
484
|
+
new_lines.append(line)
|
|
485
|
+
|
|
486
|
+
new_cli_lines = []
|
|
487
|
+
curl_version = tags[-1].removeprefix("curl-").replace("_", ".")
|
|
488
|
+
with open(PACKAGE_JSON) as f:
|
|
489
|
+
package_version = json.load(f)["version"]
|
|
490
|
+
cli_version = f"{package_version} (curl {curl_version})"
|
|
491
|
+
cli_version_line = CLI_VERSION_LINE_START + f'"{cli_version}";\n'
|
|
492
|
+
with open(CLI_FILE) as f:
|
|
493
|
+
for line in f:
|
|
494
|
+
if line.strip().startswith(CLI_VERSION_LINE_START):
|
|
495
|
+
break
|
|
496
|
+
new_cli_lines.append(line)
|
|
497
|
+
else:
|
|
498
|
+
raise ValueError(
|
|
499
|
+
f"no line in {CLI_FILE} starts with {CLI_VERSION_LINE_START!r}"
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
new_cli_lines.append(cli_version_line)
|
|
503
|
+
|
|
504
|
+
for line in f:
|
|
505
|
+
new_cli_lines.append(line)
|
|
506
|
+
|
|
507
|
+
if args.write:
|
|
508
|
+
with open(OUTPUT_FILE, "w", newline="\n") as f:
|
|
509
|
+
f.write("".join(new_lines))
|
|
510
|
+
with open(CLI_FILE, "w", newline="\n") as f:
|
|
511
|
+
f.write("".join(new_cli_lines))
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
import yargs from "yargs";
|
|
7
|
+
import { hideBin } from "yargs/helpers";
|
|
8
|
+
|
|
9
|
+
import { fixturesDir, converters } from "../test/test-utils.js";
|
|
10
|
+
import type { Converter } from "../test/test-utils.js";
|
|
11
|
+
|
|
12
|
+
const curlCommandDir = path.resolve(fixturesDir, "curl_commands");
|
|
13
|
+
|
|
14
|
+
const argv = await yargs(hideBin(process.argv))
|
|
15
|
+
.scriptName("gen-test")
|
|
16
|
+
.usage("Usage: $0 [-l <language>] [curl_command_filename...]")
|
|
17
|
+
.option("l", {
|
|
18
|
+
alias: "language",
|
|
19
|
+
describe:
|
|
20
|
+
"the language to convert the curl command to " +
|
|
21
|
+
"(`--language parser` saves parser state as JSON)",
|
|
22
|
+
choices: Object.keys(converters),
|
|
23
|
+
default: Object.keys(converters),
|
|
24
|
+
defaultDescription: "all of them",
|
|
25
|
+
demandOption: false,
|
|
26
|
+
type: "string",
|
|
27
|
+
})
|
|
28
|
+
.option("all", {
|
|
29
|
+
describe: "generate all tests for all languages",
|
|
30
|
+
default: false,
|
|
31
|
+
demandOption: false,
|
|
32
|
+
type: "boolean",
|
|
33
|
+
})
|
|
34
|
+
.positional("curl_command_filename", {
|
|
35
|
+
// this has no effect, it's here for --help
|
|
36
|
+
describe:
|
|
37
|
+
"the file to read the curl command from (or just its name without its path or file extension)",
|
|
38
|
+
type: "string",
|
|
39
|
+
})
|
|
40
|
+
.alias("h", "help")
|
|
41
|
+
.help().argv;
|
|
42
|
+
|
|
43
|
+
const languages: Converter[] = Array.isArray(argv.language)
|
|
44
|
+
? argv.language
|
|
45
|
+
: [argv.language];
|
|
46
|
+
for (const language of languages) {
|
|
47
|
+
// Create the directory if it doesn't exist
|
|
48
|
+
const outDir = path.resolve(curlCommandDir, "..", language);
|
|
49
|
+
if (!fs.existsSync(outDir)) {
|
|
50
|
+
console.error("creating directory " + outDir);
|
|
51
|
+
fs.mkdirSync(outDir);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (argv.all && argv._.length) {
|
|
56
|
+
console.error("--all passed, ignoring names of test files");
|
|
57
|
+
}
|
|
58
|
+
const overwriteExistingOnly = !argv._.length && !argv.all;
|
|
59
|
+
const inFiles =
|
|
60
|
+
!argv._.length || argv.all
|
|
61
|
+
? fs.readdirSync(curlCommandDir).filter((p) => p.endsWith(".sh"))
|
|
62
|
+
: argv._;
|
|
63
|
+
const inPaths = inFiles.map((infile) => {
|
|
64
|
+
// Remove path and file extension
|
|
65
|
+
const filename = path.parse(infile.toString()).name;
|
|
66
|
+
const testfile = path.join(curlCommandDir, filename + ".sh");
|
|
67
|
+
if (!fs.existsSync(testfile)) {
|
|
68
|
+
console.error("no such file: " + testfile);
|
|
69
|
+
process.exit();
|
|
70
|
+
}
|
|
71
|
+
return testfile;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const printEachFile =
|
|
75
|
+
inPaths.length < 10 || languages.length < Object.keys(converters).length;
|
|
76
|
+
let total = 0;
|
|
77
|
+
for (const inPath of inPaths) {
|
|
78
|
+
const curl = fs.readFileSync(inPath, "utf8");
|
|
79
|
+
for (const language of languages) {
|
|
80
|
+
const converter = converters[language];
|
|
81
|
+
const newFilename = path
|
|
82
|
+
.basename(inPath)
|
|
83
|
+
.replace(/\.sh$/, converter.extension);
|
|
84
|
+
const outDir = path.resolve(inPath, "../..", language);
|
|
85
|
+
if (!fs.existsSync(outDir)) {
|
|
86
|
+
console.error("creating directory " + outDir);
|
|
87
|
+
fs.mkdirSync(outDir);
|
|
88
|
+
}
|
|
89
|
+
const outPath = path.join(outDir, newFilename);
|
|
90
|
+
|
|
91
|
+
let code;
|
|
92
|
+
try {
|
|
93
|
+
code = converter.converter(curl);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error("error converting curl command to " + language);
|
|
96
|
+
console.error(inPath);
|
|
97
|
+
console.error();
|
|
98
|
+
console.error(curl);
|
|
99
|
+
console.error();
|
|
100
|
+
|
|
101
|
+
console.error(e);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Might as well generate the output to check
|
|
106
|
+
if (overwriteExistingOnly && !fs.existsSync(outPath)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const orig = fs.existsSync(outPath) ? fs.readFileSync(outPath, "utf8") : "";
|
|
111
|
+
fs.writeFileSync(outPath, code);
|
|
112
|
+
if (orig !== code) {
|
|
113
|
+
if (printEachFile) {
|
|
114
|
+
console.error("wrote to " + path.relative(fixturesDir, outPath));
|
|
115
|
+
} else {
|
|
116
|
+
total += 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!printEachFile) {
|
|
122
|
+
console.error("wrote " + total + " file" + (total === 1 ? "" : "s"));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// if (inPaths.length && languages.length) {
|
|
126
|
+
// console.error(
|
|
127
|
+
// "Please carefully check all the output for correctness before committing."
|
|
128
|
+
// );
|
|
129
|
+
// }
|