forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use top-level for-await in various places (denoland/deno#3217)
- Loading branch information
Showing
7 changed files
with
84 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
const url = Deno.args[1]; | ||
const res = await fetch(url); | ||
const url_ = Deno.args[1]; | ||
const res = await fetch(url_); | ||
await Deno.copy(Deno.stdout, res.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,59 @@ | ||
#!/usr/bin/env -S deno --allow-net --allow-env | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
|
||
const { args, env, exit, readFile } = Deno; | ||
import { parse } from "https://deno.land/std/flags/mod.ts"; | ||
|
||
function pathBase(p: string): string { | ||
const parts = p.split("/"); | ||
return parts[parts.length - 1]; | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const token = env()["GIST_TOKEN"]; | ||
if (!token) { | ||
console.error("GIST_TOKEN environmental variable not set."); | ||
console.error("Get a token here: https://github.com/settings/tokens"); | ||
exit(1); | ||
} | ||
|
||
const parsedArgs = parse(args.slice(1)); | ||
|
||
if (parsedArgs._.length === 0) { | ||
console.error( | ||
"Usage: gist.ts --allow-env --allow-net [-t|--title Example] some_file " + | ||
"[next_file]" | ||
); | ||
exit(1); | ||
} | ||
|
||
const files = {}; | ||
for (const filename of parsedArgs._) { | ||
const base = pathBase(filename); | ||
const content = await readFile(filename); | ||
const contentStr = new TextDecoder().decode(content); | ||
files[base] = { content: contentStr }; | ||
} | ||
const token = Deno.env()["GIST_TOKEN"]; | ||
if (!token) { | ||
console.error("GIST_TOKEN environmental variable not set."); | ||
console.error("Get a token here: https://github.com/settings/tokens"); | ||
Deno.exit(1); | ||
} | ||
|
||
const content = { | ||
description: parsedArgs.title || parsedArgs.t || "Example", | ||
public: false, | ||
files: files | ||
}; | ||
const body = JSON.stringify(content); | ||
const parsedArgs = parse(Deno.args.slice(1)); | ||
|
||
const res = await fetch("https://api.github.com/gists", { | ||
method: "POST", | ||
headers: [ | ||
["Content-Type", "application/json"], | ||
["User-Agent", "Deno-Gist"], | ||
["Authorization", `token ${token}`] | ||
], | ||
body | ||
}); | ||
if (parsedArgs._.length === 0) { | ||
console.error( | ||
"Usage: gist.ts --allow-env --allow-net [-t|--title Example] some_file " + | ||
"[next_file]" | ||
); | ||
Deno.exit(1); | ||
} | ||
|
||
if (res.ok) { | ||
const resObj = await res.json(); | ||
console.log("Success"); | ||
console.log(resObj["html_url"]); | ||
} else { | ||
const err = await res.text(); | ||
console.error("Failure to POST", err); | ||
} | ||
const files = {}; | ||
for (const filename of parsedArgs._) { | ||
const base = pathBase(filename); | ||
const content = await Deno.readFile(filename); | ||
const contentStr = new TextDecoder().decode(content); | ||
files[base] = { content: contentStr }; | ||
} | ||
|
||
main(); | ||
const content = { | ||
description: parsedArgs.title || parsedArgs.t || "Example", | ||
public: false, | ||
files: files | ||
}; | ||
const body = JSON.stringify(content); | ||
|
||
const res = await fetch("https://api.github.com/gists", { | ||
method: "POST", | ||
headers: [ | ||
["Content-Type", "application/json"], | ||
["User-Agent", "Deno-Gist"], | ||
["Authorization", `token ${token}`] | ||
], | ||
body | ||
}); | ||
|
||
if (res.ok) { | ||
const resObj = await res.json(); | ||
console.log("Success"); | ||
console.log(resObj["html_url"]); | ||
} else { | ||
const err = await res.text(); | ||
console.error("Failure to POST", err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters