Skip to content

Commit

Permalink
Rename catjson.ts to catj.ts (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and ry committed Jul 11, 2019
1 parent 67641b8 commit 2f4846f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
32 changes: 25 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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
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
```
10 changes: 5 additions & 5 deletions examples/catjson.ts → examples/catj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

// 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 */
import { parse } from "../flags/mod.ts";
Expand Down Expand Up @@ -83,15 +83,15 @@ async function main(): Promise<void> {
const parsedArgs = parse(Deno.args.slice(1));

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("Examples:");
console.log();
console.log("// print file:\n catjson file.json");
console.log("// print file:\n catj file.json");
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("// print from stdin:\n cat file.json | catjson -");
console.log("// print from stdin:\n cat file.json | catj -");
}

if (parsedArgs._[0] === "-") {
Expand Down

0 comments on commit 2f4846f

Please sign in to comment.