balena-cli/lib/resin/ui/patterns/patterns.coffee

34 lines
739 B
CoffeeScript
Raw Normal View History

2014-11-21 17:23:29 +00:00
async = require('async')
2014-12-02 15:08:22 +00:00
pace = require('pace')
fs = require('fs')
2014-11-26 17:27:57 +00:00
widgets = require('../widgets/widgets')
2014-12-02 15:08:22 +00:00
server = require('../../server/server')
2014-11-21 17:23:29 +00:00
exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) ->
async.waterfall([
(callback) ->
if confirmAttribute
return callback(null, true)
2014-11-26 17:27:57 +00:00
widgets.confirmRemoval(name, callback)
2014-11-21 17:23:29 +00:00
(confirmed, callback) ->
return callback() if not confirmed
deleteFunction(callback)
], outerCallback)
2014-12-02 15:08:22 +00:00
exports.downloadFile = (url, dest, callback) ->
bar = null
server.request
method: 'GET'
url: url
pipe: fs.createWriteStream(dest)
, (error) ->
return callback(error)
, (state) ->
return if not state?
bar ?= pace(state.total)
bar.op(state.received)