Skip to content

Commit 73e9fad

Browse files
committed
Merge branch 'dev'
2 parents 3987e20 + fd3af96 commit 73e9fad

24 files changed

Lines changed: 458 additions & 297 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
CHANGELOG.md
22

3+
.vim
4+
.log
5+
36
# code what you want:
47
poc.js
58
poc.ts
69
poc
710

8-
request.json
11+
request.json

cli.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,28 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import helpCommand from "./commands/help.ts";
9-
import versionCommand from "./commands/version.ts";
10-
import parse from "./utils/args/parser.ts";
11-
import output from "./utils/output/output.ts";
128
import { fetchFromArgs, fetchFromRequestFile } from "./utils/request/fetch.ts";
13-
import { getRequest } from "./utils/readJson.ts";
149
import { runCommandFilePath } from "./info.ts";
10+
import { getRequest } from "./utils/request/getRequest.ts";
11+
import versionCommand from "./commands/version.ts";
12+
import helpCommand from "./commands/help.ts";
13+
import Output from "./utils/output/output.ts";
14+
import parse from "./utils/args/parser.ts";
1515

16-
const denoArgs = Deno.args;
17-
const args = parse(denoArgs);
16+
const args = parse(Deno.args);
1817

1918
if (args) {
20-
const { type } = args;
19+
const { type, data } = args;
2120

2221
if (type === "flag") {
23-
const { flags } = args.data;
24-
console.log(flags.version ? versionCommand : helpCommand);
22+
console.log(data.flags.version ? versionCommand : helpCommand);
2523
}
2624

27-
if (type === "command") {
28-
const { command } = args.data;
29-
if (command === "run") {
30-
const alias = args.data.body;
31-
const request = await getRequest(alias, runCommandFilePath);
32-
output(await fetchFromRequestFile(request.url, request));
33-
}
25+
if (type === "command" && data.command === "run") {
26+
const alias = data.body;
27+
const request = await getRequest(alias, runCommandFilePath);
28+
Output.response(await fetchFromRequestFile(request.url, request));
3429
}
3530

36-
if (type === "request") {
37-
output(await fetchFromArgs(args.data));
38-
}
31+
if (type === "request") Output.response(await fetchFromArgs(data));
3932
} else console.log(helpCommand);

import_map.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"imports": {
3-
"fmt/": "https://deno.land/std@0.123.0/fmt/",
4-
"fs/": "https://deno.land/std@0.123.0/fs/",
5-
"merlin": "https://deno.land/x/merlin@v1.0.6/mod.ts"
3+
"fmt/": "https://deno.land/std@0.145.0/fmt/",
4+
"fs/": "https://deno.land/std@0.145.0/fs/",
5+
"merlin": "https://deno.land/x/merlin@v1.0.7/mod.ts",
6+
"tools-fs": "https://denopkg.com/crewdevio/tools@main/fs/mod.ts"
67
}
78
}

regex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const args = {
3333
},
3434
method: /^GET|POST|PUT|PATCH|DELETE$/,
3535
url: new RegExp(
36-
`^${protocolOrWWW.source}${validURLChars.source}(\\.|\\:)${validURLChars.source}$`
36+
`^${protocolOrWWW.source}${validURLChars.source}(\\.|\\:)${validURLChars.source}$`,
3737
),
3838
body: {
3939
...json,

run.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dev": "deno run -A --unstable --import-map=./import_map.json ./cli.ts",
44
"piwo": "deno run --allow-env --allow-net --allow-read --allow-write --no-check --import-map=./import_map.json ./cli.ts",
55
"test": "deno test -A --unstable --import-map=./import_map.json",
6-
"log": "ghlog crewdevio/piwo",
6+
"log": "trex exec ghlog crewdevio/piwo",
77
"preinstall": "cp -a .githooks/. .git/hooks/"
88
}
99
}

tests/args.test.ts

Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { Merlin } from "merlin";
22
import parse from "../utils/args/parser.ts";
3-
import type { ArgResult } from "./types.ts";
3+
import type { ArgsType } from "../types.ts";
44

55
const test = new Merlin();
66

77
test.assertEqual("GET: api.github.com", {
88
expect() {
99
return parse(["api.github.com"]);
1010
},
11-
toBe(): ArgResult {
11+
toBe(): ArgsType {
1212
return {
13-
url: "api.github.com",
14-
method: "GET",
13+
data: {
14+
url: "api.github.com",
15+
method: "GET",
16+
},
17+
type: "request",
1518
};
1619
},
1720
});
@@ -20,10 +23,13 @@ test.assertEqual("GET (explicit): api.github.com", {
2023
expect() {
2124
return parse(["GET", "api.github.com"]);
2225
},
23-
toBe(): ArgResult {
26+
toBe(): ArgsType {
2427
return {
25-
method: "GET",
26-
url: "api.github.com",
28+
data: {
29+
method: "GET",
30+
url: "api.github.com",
31+
},
32+
type: "request",
2733
};
2834
},
2935
});
@@ -32,10 +38,13 @@ test.assertEqual("GET: complex url", {
3238
expect() {
3339
return parse(["localhost:8080/[pgk]/?id=20"]);
3440
},
35-
toBe(): ArgResult {
41+
toBe(): ArgsType {
3642
return {
37-
url: "localhost:8080/[pgk]/?id=20",
38-
method: "GET",
43+
data: {
44+
url: "localhost:8080/[pgk]/?id=20",
45+
method: "GET",
46+
},
47+
type: "request",
3948
};
4049
},
4150
});
@@ -44,12 +53,15 @@ test.assertEqual("POST: send a email", {
4453
expect() {
4554
return parse(["POST", "localhost:8080", "email=foo@bar.com"]);
4655
},
47-
toBe(): ArgResult {
56+
toBe(): ArgsType {
4857
return {
49-
method: "POST",
50-
url: "localhost:8080",
51-
headers: { "Content-Type": "application/json" },
52-
body: { email: "foo@bar.com" },
58+
data: {
59+
method: "POST",
60+
url: "localhost:8080",
61+
headers: { "content-type": "application/json" },
62+
body: { email: "foo@bar.com" },
63+
},
64+
type: "request",
5365
};
5466
},
5567
});
@@ -62,12 +74,15 @@ test.assertEqual("POST: send a url", {
6274
"url=http://localhost:8080/api/foo_bar",
6375
]);
6476
},
65-
toBe(): ArgResult {
77+
toBe(): ArgsType {
6678
return {
67-
method: "POST",
68-
url: "localhost:8080",
69-
headers: { "Content-Type": "application/json" },
70-
body: { url: "http://localhost:8080/api/foo_bar" },
79+
data: {
80+
method: "POST",
81+
url: "localhost:8080",
82+
headers: { "content-type": "application/json" },
83+
body: { url: "http://localhost:8080/api/foo_bar" },
84+
},
85+
type: "request",
7186
};
7287
},
7388
});
@@ -76,12 +91,15 @@ test.assertEqual("POST: multiple values", {
7691
expect() {
7792
return parse(["POST", "localhost:8080", "foo=bar", "bar=foo"]);
7893
},
79-
toBe(): ArgResult {
94+
toBe(): ArgsType {
8095
return {
81-
method: "POST",
82-
url: "localhost:8080",
83-
headers: { "Content-Type": "application/json" },
84-
body: { foo: "bar", bar: "foo" },
96+
data: {
97+
method: "POST",
98+
url: "localhost:8080",
99+
headers: { "content-type": "application/json" },
100+
body: { foo: "bar", bar: "foo" },
101+
},
102+
type: "request",
85103
};
86104
},
87105
});
@@ -90,12 +108,15 @@ test.assertEqual("POST: value with spaces", {
90108
expect() {
91109
return parse(["POST", "localhost:8080", "foo=one bar"]);
92110
},
93-
toBe(): ArgResult {
111+
toBe(): ArgsType {
94112
return {
95-
method: "POST",
96-
url: "localhost:8080",
97-
headers: { "Content-Type": "application/json" },
98-
body: { foo: "one bar" },
113+
data: {
114+
method: "POST",
115+
url: "localhost:8080",
116+
headers: { "content-type": "application/json" },
117+
body: { foo: "one bar" },
118+
},
119+
type: "request",
99120
};
100121
},
101122
});
@@ -111,14 +132,17 @@ test.assertEqual("POST: with object and array", {
111132
"magic]}",
112133
]);
113134
},
114-
toBe(): ArgResult {
135+
toBe(): ArgsType {
115136
return {
116-
method: "POST",
117-
url: "localhost:8080",
118-
headers: { "Content-Type": "application/json" },
119-
body: {
120-
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
137+
data: {
138+
method: "POST",
139+
url: "localhost:8080",
140+
headers: { "content-type": "application/json" },
141+
body: {
142+
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
143+
},
121144
},
145+
type: "request",
122146
};
123147
},
124148
});
@@ -134,14 +158,17 @@ test.assertEqual("PUT: with object and array", {
134158
"magic]}",
135159
]);
136160
},
137-
toBe(): ArgResult {
161+
toBe(): ArgsType {
138162
return {
139-
method: "PUT",
140-
url: "localhost:8080",
141-
headers: { "Content-Type": "application/json" },
142-
body: {
143-
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
163+
data: {
164+
method: "PUT",
165+
url: "localhost:8080",
166+
headers: { "content-type": "application/json" },
167+
body: {
168+
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
169+
},
144170
},
171+
type: "request",
145172
};
146173
},
147174
});
@@ -157,14 +184,17 @@ test.assertEqual("PATCH: with object and array", {
157184
"magic]}",
158185
]);
159186
},
160-
toBe(): ArgResult {
187+
toBe(): ArgsType {
161188
return {
162-
method: "PATCH",
163-
url: "localhost:8080",
164-
headers: { "Content-Type": "application/json" },
165-
body: {
166-
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
189+
data: {
190+
method: "PATCH",
191+
url: "localhost:8080",
192+
headers: { "content-type": "application/json" },
193+
body: {
194+
person: { name: "Deno Merlin", age: 24, hobbies: ["test", "magic"] },
195+
},
167196
},
197+
type: "request",
168198
};
169199
},
170200
});
@@ -173,10 +203,10 @@ test.assertEqual("DELETE", {
173203
expect() {
174204
return parse(["DELETE", "localhost:8080"]);
175205
},
176-
toBe(): ArgResult {
206+
toBe(): ArgsType {
177207
return {
178-
method: "DELETE",
179-
url: "localhost:8080",
208+
data: { method: "DELETE", url: "localhost:8080" },
209+
type: "request",
180210
};
181211
},
182212
});

tests/form.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { ArgsType } from "../types.ts";
12
import { Merlin } from "merlin";
23
import parse from "../utils/args/parser.ts";
3-
import type { ArgResult, FlagResult } from "./types.ts";
44

55
const test = new Merlin();
66

@@ -21,7 +21,7 @@ test.assertEqual("POST a formData with -f flag", {
2121

2222
return { short, complete };
2323
},
24-
toBe(): FlagResult {
24+
toBe() {
2525
const formData = new FormData();
2626
formData.append(
2727
"person",
@@ -32,12 +32,15 @@ test.assertEqual("POST a formData with -f flag", {
3232
}`),
3333
);
3434

35-
const result: ArgResult = {
36-
method: "POST",
37-
url: "localhost:8080",
38-
flags: { form: true },
39-
headers: undefined,
40-
body: formData,
35+
const result: ArgsType = {
36+
data: {
37+
method: "POST",
38+
url: "localhost:8080",
39+
flags: { form: true },
40+
headers: undefined,
41+
body: formData,
42+
},
43+
type: "request",
4144
};
4245

4346
return {

tests/help.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { ArgsType } from "../types.ts";
12
import { Merlin } from "merlin";
23
import parse from "../utils/args/parser.ts";
3-
import type { ArgResult, FlagResult } from "./types.ts";
44

55
const test = new Merlin();
66

@@ -10,8 +10,16 @@ test.assertEqual("help flag", {
1010
const complete = parse(["--help"]);
1111
return { short, complete };
1212
},
13-
toBe(): FlagResult {
14-
const result: ArgResult = { flags: { help: true } };
13+
toBe() {
14+
const result: ArgsType = {
15+
data: {
16+
flags: {
17+
help: true,
18+
},
19+
},
20+
type: "flag",
21+
};
22+
1523
return {
1624
short: result,
1725
complete: result,

0 commit comments

Comments
 (0)