From 99842a3fb3c082260f8f54855e210f6b2520899a Mon Sep 17 00:00:00 2001 From: Jonny Burger Date: Thu, 30 Mar 2017 16:43:15 +0200 Subject: [PATCH] Allow input from stdin --- index.js | 14 ++++++++++---- package.json | 1 + yarn.lock | 4 ++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 9da9ddc..c7734c4 100755 --- a/index.js +++ b/index.js @@ -1,13 +1,19 @@ #!/usr/bin/env node const open = require('open-pip') const ora = require('ora') +const getStdin = require('get-stdin') const spinner = ora().start() -const input = process.argv[2] +getStdin() +.then(stdin => { + if (stdin) return stdin.trim(); -if (!input) throw new Error('No url supplied') - -open(input).then(() => { + const input = process.argv[2] + if (!input) throw new Error('No url supplied') + return input +}) +.then(input => open(input)) +.then(() => { spinner.stopAndPersist({ symbol: '🌟', text: 'Running!' }) }) .catch((err) => { diff --git a/package.json b/package.json index 549ad31..035cb39 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "open-pip": "index.js" }, "dependencies": { + "get-stdin": "^5.0.1", "open-pip": "^3.0.5", "ora": "^1.2.0" } diff --git a/yarn.lock b/yarn.lock index 21988c8..57c7bea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -86,6 +86,10 @@ fs-promise@^2.0.2: mz "^2.6.0" thenify-all "^1.6.0" +get-stdin@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + graceful-fs@^4.1.2, graceful-fs@^4.1.6: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"