mirror of
https://github.com/denoland/deno.git
synced 2024-12-31 11:34:15 -05:00
Rename catjson.ts to catj.ts (denoland/deno_std#533)
Original: 2f4846fc3e
This commit is contained in:
parent
1a42695beb
commit
f549392fb6
2 changed files with 30 additions and 12 deletions
|
@ -1,18 +1,36 @@
|
||||||
# Deno Example Programs
|
# Deno example programs
|
||||||
|
|
||||||
These files are accessible for import via "https://deno.land/std/examples/".
|
This module contains small scripts that demonstrate use of Deno and its standard library.
|
||||||
|
|
||||||
Try it:
|
You can run these examples by importing them via `deno` command:
|
||||||
|
|
||||||
```
|
```
|
||||||
> deno https://deno.land/std/examples/gist.ts README.md
|
> deno https://deno.land/std/examples/echo_server.ts --allow-net
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alias Based Installation
|
Some of them are useful CLI programs that can be installed as executables:
|
||||||
|
|
||||||
Add this to your `.bash_profile`
|
`cat.ts` - print file to standard output
|
||||||
|
|
||||||
```
|
```
|
||||||
|
deno install deno_cat https://deno.land/examples.cat.ts --allow-read
|
||||||
|
deno_cat file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
`catj.ts` - print flattened JSON to standard output
|
||||||
|
|
||||||
|
```
|
||||||
|
deno install catj https://deno.land/examples/catj.ts --allow-read
|
||||||
|
catj example.json
|
||||||
|
catj file1.json file2.json
|
||||||
|
echo example.json | catj -
|
||||||
|
```
|
||||||
|
|
||||||
|
`gist.ts` - easily create and upload Gists
|
||||||
|
|
||||||
|
```
|
||||||
|
deno install gist https://deno.land/examples/gist.ts --allow-net --allow-env
|
||||||
export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens
|
export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens
|
||||||
alias gist="deno --allow-net --allow-env https://deno.land/std/examples/gist.ts"
|
gist --title "Example gist 1" script.ts
|
||||||
|
gist --t "Example gist 2" script2.ts
|
||||||
```
|
```
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// Install using `deno install`
|
// Install using `deno install`
|
||||||
// $ deno install catjson https://deno.land/std/examples/catjson.ts --allow-read
|
// $ deno install catj https://deno.land/std/examples/catj.ts --allow-read
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-use-before-define */
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||||
import { parse } from "../flags/mod.ts";
|
import { parse } from "../flags/mod.ts";
|
||||||
|
@ -83,15 +83,15 @@ async function main(): Promise<void> {
|
||||||
const parsedArgs = parse(Deno.args.slice(1));
|
const parsedArgs = parse(Deno.args.slice(1));
|
||||||
|
|
||||||
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
|
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
|
||||||
console.log("Usage: catjson [-h|--help] [file...]");
|
console.log("Usage: catj [-h|--help] [file...]");
|
||||||
console.log();
|
console.log();
|
||||||
console.log("Examples:");
|
console.log("Examples:");
|
||||||
console.log();
|
console.log();
|
||||||
console.log("// print file:\n catjson file.json");
|
console.log("// print file:\n catj file.json");
|
||||||
console.log();
|
console.log();
|
||||||
console.log("// print multiple files:\n catjson file1.json file2.json");
|
console.log("// print multiple files:\n catj file1.json file2.json");
|
||||||
console.log();
|
console.log();
|
||||||
console.log("// print from stdin:\n cat file.json | catjson -");
|
console.log("// print from stdin:\n cat file.json | catj -");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedArgs._[0] === "-") {
|
if (parsedArgs._[0] === "-") {
|
Loading…
Reference in a new issue