/**
 * @author Titus Wormer
 * @copyright 2015 Titus Wormer
 * @license MIT
 * @module mdast:cli:log
 * @fileoverview Log a file context on successful completion.
 */

'use strict';

/*
 * Dependencies.
 */

var report = require('vfile-reporter');

/**
 * Output diagnostics to stdout(4) or stderr(4).
 *
 * @param {CLI} context - CLI engine.
 */
function log(context) {
    var files = context.files;
    var frail = context.frail;
    var applicables = files.filter(function (file) {
        return file.namespace('mdast:cli').providedByUser;
    });
    var hasFailed = files.some(function (file) {
        return file.hasFailed() || (frail && file.messages.length);
    });
    var diagnostics = report(applicables, {
        'quiet': context.quiet,
        'silent': context.silent
    });

    if (diagnostics) {
        context[hasFailed ? 'stderr' : 'stdout'](diagnostics);
    }
}

/*
 * Expose.
 */

module.exports = log;

/**
 * @author Titus Wormer
 * @copyright 2015 Titus Wormer
 * @license MIT
 * @module mdast:cli:log
 * @fileoverview Log a file context on successful completion.
 */

'use strict';

/*
 * Dependencies.
 */

var report = require('vfile-reporter');

/**
 * Output diagnostics to stdout(4) or stderr(4).
 *
 * @param {CLI} context - CLI engine.
 */
function log(context) {
    var files = context.files;
    var applicables = files.filter(function (file) {
        return file.namespace('mdast:cli').providedByUser;
    });
    var diagnostics = report(applicables, {
        'quiet': context.quiet,
        'silent': context.silent
    });

    if (diagnostics) {
        context.stderr(diagnostics);
    }
}

/*
 * Expose.
 */

module.exports = log;

Move all info output of mdast(1) to stderr(4)
Move all info output of mdast(1) to stderr(4)

This changes moves all reporting output, even when not including
failure messages, from stout(4) to stderr(4).

Thus, when piping only stdout(4) from mdast(1) into a file, only
the markdown is written.

Closes GH-47.
