Skip to content

Commit

Permalink
Use pipes in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
doesdev committed Mar 18, 2018
1 parent 947a080 commit 8e5fe26
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cli-update.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /usr/bin/env node
'use strict'

const ngo = require('./index.js')({update: true})
ngo().then((r) => console.log(r.stdout || r.stdout)).catch(console.error)
const go = require('./index.js')({update: true})()
go.stdout.pipe(process.stdout)
go.stderr.pipe(process.stderr)
go.catch(() => {})
7 changes: 4 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! /usr/bin/env node
'use strict'

const ngo = require('./index.js')()
const args = process.argv.slice(2)

ngo(args).then((r) => console.log(r.stdout || r.stdout)).catch(console.error)
const go = require('./index.js')()(args)
go.stdout.pipe(process.stdout)
go.stderr.pipe(process.stderr)
go.catch(() => {})
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function runner (args, opts) {
if (opts.installDeps === false) return go
go.catch((err) => {
let dep = (`${err}`.match(/cannot find package "(.+?)"/) || [])[1]
if (!dep || lastDep === dep) return Promise.reject(err)
if (!dep || lastDep === dep) return
lastDep = dep
let getDep = execa(env.ngoBin, ['get', dep], opts)
return getDep.then(() => run()).catch(() => Promise.reject(err))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngo",
"version": "2.3.3",
"version": "2.4.0",
"description": "Run Go commands, whether your Go env is in place or not",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 8e5fe26

Please sign in to comment.