"use strict";

const colors = require("colors/safe");
const fs = require("fs");
const fsextra = require("fs-extra");
const path = require("path");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils");

program
	.command("start")
	.option("-H, --host <ip>", `${colors.bold.red("[DEPRECATED]")} to set the IP address or hostname for the web server to listen on, use ${colors.bold("-c host=<ip>")} instead`)
	.option("-P, --port <port>", `${colors.bold.red("[DEPRECATED]")} to set the port to listen on, use ${colors.bold("-c port=<port>")} instead`)
	.option("-B, --bind <ip>", `${colors.bold.red("[DEPRECATED]")} to set the local IP to bind to for outgoing connections, use ${colors.bold("-c bind=<ip>")} instead`)
	.option("    --public", `${colors.bold.red("[DEPRECATED]")} to start in public mode, use ${colors.bold("-c public=true")} instead`)
	.option("    --private", `${colors.bold.red("[DEPRECATED]")} to start in private mode, use ${colors.bold("-c public=false")} instead`)
	.description("Start the server")
	.on("--help", Utils.extraHelp)
	.action(function(options) {
		initalizeConfig();

		const server = require("../server");

		if (options.host) {
			log.warn(`${colors.bold("-H, --host <ip>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c host=<ip>")} instead.`);
		}
		if (options.port) {
			log.warn(`${colors.bold("-P, --port <port>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c port=<port>")} instead.`);
		}
		if (options.bind) {
			log.warn(`${colors.bold("-B, --bind <ip>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c bind=<ip>")} instead.`);
		}
		if (options.public) {
			log.warn(`${colors.bold("--public")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c public=true")} instead.`);
		}
		if (options.private) {
			log.warn(`${colors.bold("--private")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c public=false")} instead.`);
		}

		var mode = Helper.config.public;
		if (options.public) {
			mode = true;
		} else if (options.private) {
			mode = false;
		}

		Helper.config.host = options.host || Helper.config.host;
		Helper.config.port = options.port || Helper.config.port;
		Helper.config.bind = options.bind || Helper.config.bind;
		Helper.config.public = mode;

		server();
	});

function initalizeConfig() {
	if (!fs.existsSync(Helper.getConfigPath())) {
		fsextra.ensureDirSync(Helper.getHomePath());
		fs.chmodSync(Helper.getHomePath(), "0700");
		fsextra.copySync(path.resolve(path.join(
			__dirname,
			"..",
			"..",
			"defaults",
			"config.js"
		)), Helper.getConfigPath());
		log.info(`Configuration file created at ${colors.green(Helper.getConfigPath())}.`);
	}

	fsextra.ensureDirSync(Helper.getUsersPath());
}

@@ -281,762 +281,8 @@
 t%22)%0A
-%09.option(%22-H, --host %3Cip%3E%22, %60$%7Bcolors.bold.red(%22%5BDEPRECATED%5D%22)%7D to set the IP address or hostname for the web server to listen on, use $%7Bcolors.bold(%22-c host=%3Cip%3E%22)%7D instead%60)%0A%09.option(%22-P, --port %3Cport%3E%22, %60$%7Bcolors.bold.red(%22%5BDEPRECATED%5D%22)%7D to set the port to listen on, use $%7Bcolors.bold(%22-c port=%3Cport%3E%22)%7D instead%60)%0A%09.option(%22-B, --bind %3Cip%3E%22, %60$%7Bcolors.bold.red(%22%5BDEPRECATED%5D%22)%7D to set the local IP to bind to for outgoing connections, use $%7Bcolors.bold(%22-c bind=%3Cip%3E%22)%7D instead%60)%0A%09.option(%22    --public%22, %60$%7Bcolors.bold.red(%22%5BDEPRECATED%5D%22)%7D to start in public mode, use $%7Bcolors.bold(%22-c public=true%22)%7D instead%60)%0A%09.option(%22    --private%22, %60$%7Bcolors.bold.red(%22%5BDEPRECATED%5D%22)%7D to start in private mode, use $%7Bcolors.bold(%22-c public=false%22)%7D instead%60)%0A
 %09.de
@@ -361,23 +361,16 @@
 unction(
-options
 ) %7B%0A%09%09in
@@ -430,1319 +430,8 @@
 %22);%0A
-%0A%09%09if (options.host) %7B%0A%09%09%09log.warn(%60$%7Bcolors.bold(%22-H, --host %3Cip%3E%22)%7D is $%7Bcolors.bold.red(%22deprecated%22)%7D and will be removed in The Lounge v3. Use $%7Bcolors.bold(%22-c host=%3Cip%3E%22)%7D instead.%60);%0A%09%09%7D%0A%09%09if (options.port) %7B%0A%09%09%09log.warn(%60$%7Bcolors.bold(%22-P, --port %3Cport%3E%22)%7D is $%7Bcolors.bold.red(%22deprecated%22)%7D and will be removed in The Lounge v3. Use $%7Bcolors.bold(%22-c port=%3Cport%3E%22)%7D instead.%60);%0A%09%09%7D%0A%09%09if (options.bind) %7B%0A%09%09%09log.warn(%60$%7Bcolors.bold(%22-B, --bind %3Cip%3E%22)%7D is $%7Bcolors.bold.red(%22deprecated%22)%7D and will be removed in The Lounge v3. Use $%7Bcolors.bold(%22-c bind=%3Cip%3E%22)%7D instead.%60);%0A%09%09%7D%0A%09%09if (options.public) %7B%0A%09%09%09log.warn(%60$%7Bcolors.bold(%22--public%22)%7D is $%7Bcolors.bold.red(%22deprecated%22)%7D and will be removed in The Lounge v3. Use $%7Bcolors.bold(%22-c public=true%22)%7D instead.%60);%0A%09%09%7D%0A%09%09if (options.private) %7B%0A%09%09%09log.warn(%60$%7Bcolors.bold(%22--private%22)%7D is $%7Bcolors.bold.red(%22deprecated%22)%7D and will be removed in The Lounge v3. Use $%7Bcolors.bold(%22-c public=false%22)%7D instead.%60);%0A%09%09%7D%0A%0A%09%09var mode = Helper.config.public;%0A%09%09if (options.public) %7B%0A%09%09%09mode = true;%0A%09%09%7D else if (options.private) %7B%0A%09%09%09mode = false;%0A%09%09%7D%0A%0A%09%09Helper.config.host = options.host %7C%7C Helper.config.host;%0A%09%09Helper.config.port = options.port %7C%7C Helper.config.port;%0A%09%09Helper.config.bind = options.bind %7C%7C Helper.config.bind;%0A%09%09Helper.config.public = mode;%0A%0A
 %09%09se

Remove deprecated options for `thelounge start`