mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 14:13:07 +00:00
31 lines
593 B
CoffeeScript
31 lines
593 B
CoffeeScript
_ = require('lodash')
|
|
|
|
# TODO: Find a sane way to test streams
|
|
exports.readStdin = (callback) ->
|
|
stdin = process.stdin
|
|
|
|
stdin.resume()
|
|
stdin.setEncoding('utf8')
|
|
|
|
result = []
|
|
|
|
stdin.on('error', callback)
|
|
|
|
stdin.on 'data', (chunk) ->
|
|
result.push(chunk)
|
|
|
|
stdin.on 'end', ->
|
|
result = result.join()
|
|
return callback(null, result)
|
|
|
|
exports.parseCredentials = (credentials, callback) ->
|
|
result = credentials.split(':')
|
|
|
|
if result.length isnt 2
|
|
error = new Error('Invalid credentials')
|
|
return callback?(error)
|
|
|
|
callback? null,
|
|
username: _.first(result)
|
|
password: _.last(result)
|