# All files index.js

91.67% Statements 22/24
91.67% Branches 11/12
100% Functions 3/3
91.67% Lines 22/24

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    571x
    1x

    1x

    18x
    4x
    4x

    14x
    14x

    18x
    2x

    18x
    2x

    18x
    18x
    2x

    18x
    18x
    1x
    1x

    17x

    17x

    17x

     var exec = require('child_process').exec
    var parse = require('./parse')

    module.exports = function df(aOptions, aCallback) {
        var options
        var callback

        if (typeof aOptions === 'function') {
            options = {}
            callback = aOptions
        } else {
            options = aOptions
            callback = aCallback
        }

        // TODO: this should throw an error because invoking df without a callback function is pointless.
        // It's a breaking change to be made after releasing 0.1.4
        if (typeof callback !== 'function') {
            callback = function() {}
        }

        // TODO: this should invoke callback with an error
        // It's a breaking change to be made after releasing 0.1.4
        if (typeof options !== 'object') {
            options = {}
        }

        // TODO: snould validate options and merge with defaults
        // It's a breaking change to be made after releasing 0.1.4

        // TODO: should throw if prefixMultiplier is not a string
        // It should invoke callback with `err` but it's a breaking change

        // TODO: should fail if unit is not a string

        var command = 'df -kP'
        if (options.file) {
            command += ' ' + options.file
        }

        exec(command, function(err, stdout, stderr) {
            if (err) {
                callback(err)
                return
            }

            Iif (stderr) {
                callback(new Error(err))
                return
            }

            var entries = parse(stdout, options)

            callback(null, entries)
        })
    }