-
Notifications
You must be signed in to change notification settings - Fork 427
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
base: master
Are you sure you want to change the base?
Develop #375
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
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.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
const destinationStats = | ||
fs.existsSync(destination) && fs.statSync(destination); | ||
|
||
if (destinationStats && destinationStats.isDirectory()) { | ||
console.error('Destination is a directory.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
fs.copyFile(source, destination, (err) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
console.log(`File copied from ${source} to ${destination}`); | ||
}); | ||
} catch (error) { | ||
console.error(error.message); | ||
} |
There was a problem hiding this comment.
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 beargs.length !== 2
to ensure exactly two arguments (source and destination) are provided.