#!/usr/bin/env node

var optimist = require('optimist'),
	importFile = require('./index.js');

	var argv = optimist
		.usage(
			  "Usage: \033[1mimport\033[0m [options] [file …]\n\n"
			+ "Version: 0.0.5\n\n"
			+ "Minimized fork of smash.\n"
			+ "Concatenates one or more input files, outputting a single merged file.\n"
			+ "Any import statements in the input files are expanded in-place to the\n"
			+ "contents of the imported file. If the same file is imported multiple\n"
			+ "times, only the first instance of the file is included."
		)
		.options("list", {
			describe: "output a list of imported files",
			type: "boolean",
			default: false
		})
		.options("delimiter", {
			describe: "specify the delimiter used for concatenating files",
			type: "string",
			default: "\n"
		})
		.options("ignore-missing", {
			describe: "ignore missing files instead of throwing an error",
			type: "boolean",
			default: false
		})
		.options("help", {
			describe: "display this helpful message",
			type: "boolean",
			default: false
		})
		.check(function(argv) {
			if (argv.help){ return optimist.showHelp(); }
			if (!argv._.length){ throw new Error("input required"); }
			if (argv.list && argv.graph){ throw new Error("--list and --graph are exclusive"); }
		})
		.argv;

// Output to stdout
console.log( argv._.map(function(fileName){
	return importFile(fileName);
}).join(argv.delimiter) );