diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index ea24490..ea28880 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -80,6 +80,22 @@ async function writePrivateFile( } } +async function preflightWriteTargets(filePaths: string[]): Promise { + for (const filePath of filePaths) { + try { + await fs.access(filePath); + throw new Error( + `Error: the file '${c.underline(path.basename(filePath))}' already exists in directory ${c.underline(path.dirname(filePath))}`, + ); + } catch (error) { + const err = error as NodeJS.ErrnoException; + if (err.code !== "ENOENT") { + throw error; + } + } + } +} + export async function initCommand(_args: string[]): Promise { p.intro(c.bold("myst init")); p.note( @@ -189,10 +205,9 @@ export async function initCommand(_args: string[]): Promise { const configPath = path.join(outDir, "myst.config.json"); try { - await Promise.all([ - writePrivateFile(envPath, envContent), - writePrivateFile(configPath, configContent), - ]); + await preflightWriteTargets([envPath, configPath]); + await writePrivateFile(envPath, envContent); + await writePrivateFile(configPath, configContent); } catch (e) { s.stop(); p.cancel( diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 2aa5616..49f55c9 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -25,9 +25,6 @@ interface CLIConfig { const config: CLIConfig = { commands: [ { name: "init", desc: "Bootstrap Myst and generate config/env files" }, - { name: "start", desc: "Start Myst grant access control services" }, - { name: "stop", desc: "Stop Myst grant access control services" }, - { name: "status", desc: "List the health of running Myst services" }, ], globalFlags: [ { name: ["-h", "--help"], desc: "Display help information" }, @@ -80,6 +77,12 @@ async function main(): Promise { const [command, ...options] = process.argv.slice(2); const flags = options.filter((o) => o.startsWith("-")); + if (flags.includes("-v") || flags.includes("--version")) { + process.stdout.write(`${pkg.version}\n`); + process.exitCode = 0; + return; + } + if (!command || flags.includes("-h") || flags.includes("--help")) { process.stdout.write(`${HELP_TEXT}`); process.exitCode = 0;