import { p as BaseCommand, u as flags } from "../main-DvUje0hm.js";
import { t as __decorate } from "../decorate-DcF3lt7P.js";
import string from "@poppinss/utils/string";
import { EnvEditor } from "@adonisjs/env/editor";
//#region commands/generate_key.ts
/**
* The generate key command is used to generate the app key
* and write it inside the .env file.
*
* @example
* ```
* ace generate:key
* ace generate:key --show
* ace generate:key --force
* ```
*/
var GenerateKey = class extends BaseCommand {
	/**
	* The command name
	*/
	static commandName = "generate:key";
	/**
	* The command description
	*/
	static description = "Generate a cryptographically secure APP_KEY and write it to the .env file. Use --show to print without writing";
	async run() {
		let writeToFile = process.env.NODE_ENV !== "production";
		if (this.force) writeToFile = true;
		if (this.show) writeToFile = false;
		const secureKey = string.random(32);
		if (writeToFile) {
			const editor = await EnvEditor.create(this.app.appRoot);
			editor.add("APP_KEY", secureKey, true);
			await editor.save();
			this.logger.action("add APP_KEY to .env").succeeded();
		} else this.logger.log(`APP_KEY = ${secureKey}`);
	}
};
__decorate([flags.boolean({ description: "Display the key on the terminal, instead of writing it to .env file" })], GenerateKey.prototype, "show", void 0);
__decorate([flags.boolean({ description: "Force update .env file in production environment" })], GenerateKey.prototype, "force", void 0);
//#endregion
export { GenerateKey as default };
