From 1770ab0562dcde87cba28ca0118313cb5093584e Mon Sep 17 00:00:00 2001 From: vilich Date: Sun, 28 Dec 2025 12:23:47 +0100 Subject: [PATCH 1/2] add --- src/app.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/app.js b/src/app.js index ad9a93a..c4f3b72 100644 --- a/src/app.js +++ b/src/app.js @@ -1 +1,46 @@ +/* eslint-disable no-console */ 'use strict'; + +const { cp, stat } = require('fs/promises'); + +async function copyFile() { + const [, , source, dest] = process.argv; + + if (!source || !dest) { + console.error('Please provide both source and destination paths.'); + + return; + } + + if (source === dest) { + return; + } + + try { + const stats = await stat(source); + + if (stats.isDirectory()) { + console.error('Source path is a directory, not a file.'); + + return; + } + + try { + await cp(source, dest); + } catch (error) { + console.error(`Error copying file: ${error.message}`); + } + } catch (error) { + if (error.code === 'ENOENT') { + console.error('Source file does not exist.'); + + return; + } else { + console.error(error.message); + } + + process.exit(0); + } +} + +copyFile(); From 6249df564b179aefc49f7206426b67d026b6ef68 Mon Sep 17 00:00:00 2001 From: vilich Date: Sun, 28 Dec 2025 12:28:45 +0100 Subject: [PATCH 2/2] add --- src/app.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/app.js b/src/app.js index c4f3b72..00282c1 100644 --- a/src/app.js +++ b/src/app.js @@ -8,12 +8,11 @@ async function copyFile() { if (!source || !dest) { console.error('Please provide both source and destination paths.'); - - return; + process.exit(1); } if (source === dest) { - return; + process.exit(0); } try { @@ -21,25 +20,18 @@ async function copyFile() { if (stats.isDirectory()) { console.error('Source path is a directory, not a file.'); - - return; + process.exit(1); } - try { - await cp(source, dest); - } catch (error) { - console.error(`Error copying file: ${error.message}`); - } + await cp(source, dest); } catch (error) { if (error.code === 'ENOENT') { console.error('Source file does not exist.'); - - return; } else { console.error(error.message); } - process.exit(0); + process.exit(1); } }