Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #375

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
/* eslint-disable no-console */
'use strict';
import fs from 'fs';

const args = process.argv.slice(2);

console.log('Command-line arguments:', args);

if (args.length === 4) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition args.length === 4 is incorrect for checking the number of command-line arguments. It should be args.length !== 2 to ensure exactly two arguments (source and destination) are provided.

console.error('Usage: node app.js <source> <destination>');
process.exit(1);
}

const [source, destination] = args;

if (source === destination) {
console.error('Source and destination are the same. No action taken.');
process.exit(0);
}

try {
const sourceStats = fs.statSync(source);

if (!sourceStats.isFile()) {
console.error('Source is not a file.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After logging the error 'Source is not a file.', the program should exit with a non-zero status to indicate an error. Consider adding process.exit(1); here.


const destinationStats =
fs.existsSync(destination) && fs.statSync(destination);

if (destinationStats && destinationStats.isDirectory()) {
console.error('Destination is a directory.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After logging the error 'Destination is a directory.', the program should exit with a non-zero status to indicate an error. Consider adding process.exit(1); here.


fs.copyFile(source, destination, (err) => {
if (err) {
console.error(err);
}
console.log(`File copied from ${source} to ${destination}`);
});
} catch (error) {
console.error(error.message);
}
Loading