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

Added verbosity flag (-v) for cp, mv and rm commands #1129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicky1038
Copy link

@nicky1038 nicky1038 commented Aug 23, 2023

Closes #1127

The suggested verbose output is not claimed to be fully identical to the corresponding output in the original commands from coreutils. Though it is very similar, I also tried to make as few edits as possible.

@nicky1038 nicky1038 force-pushed the cp-mv-rm-verbose-output branch 2 times, most recently from 5c298ee to dd92b29 Compare August 23, 2023 21:14
@nicky1038
Copy link
Author

nicky1038 commented Aug 23, 2023

I had to force-push the same commit, because I've signed it, so that GitLab could unblock the PR. No code changed

common.unlinkSync(file);
if (options.verbose) {
console.log("removed '" + file + "'");
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this so that file is a method parameter? I'd also suggest passing options as a second parameter and then moving this function definition to the global scope, similar to what you've done with handleFIFO().

cp({ recursive: true }, src, thisDest);
rm({ recursive: true, force: true }, src);
cp({ recursive: true, verbose: options.verbose }, src, thisDest);
rm({ recursive: true, force: true, verbose: options.verbose }, src);
Copy link
Member

Choose a reason for hiding this comment

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

Good catch! 😄

@@ -84,6 +85,10 @@ function copyFileSync(srcFile, destFile, options) {
fs.closeSync(fdr);
fs.closeSync(fdw);
}

if (options.verbose) {
console.log("copied '" + srcFile + "' -> '" + destFile + "'");
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should drop the "copied" prefix. When I tested this on my linux machine, I don't see this in the output:

$ cp -vr src/ dest/
'src/' -> 'dest/'
'src/file.txt' -> 'dest/file.txt'
'src/sub1' -> 'dest/sub1'
'src/sub1/sub2' -> 'dest/sub1/sub2'
'src/sub1/sub2/file2.txt' -> 'dest/sub1/sub2/file2.txt'

On the other hand, keeping "copied" would be more consistent with the other commands, since those do say "removed" or "renamed" before the file name.

What do you think?

@@ -59,6 +63,9 @@ function rmdirSyncRecursive(dir, force, fromSymlink) {
try {
result = fs.rmdirSync(dir);
if (fs.existsSync(dir)) throw { code: 'EAGAIN' };
if (verbose) {
console.log("removed directory'" + dir + "'");
Copy link
Member

Choose a reason for hiding this comment

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

Add a space between directory and '

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Patch coverage: 55.17% and project coverage change: -0.83% ⚠️

Comparison is base (a3a7e74) 97.19% compared to head (1e3df2a) 96.36%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1129      +/-   ##
==========================================
- Coverage   97.19%   96.36%   -0.83%     
==========================================
  Files          36       36              
  Lines        1354     1375      +21     
==========================================
+ Hits         1316     1325       +9     
- Misses         38       50      +12     
Files Changed Coverage Δ
shell.js 69.23% <20.00%> (-30.77%) ⬇️
src/cp.js 90.29% <50.00%> (-1.24%) ⬇️
src/mv.js 95.74% <50.00%> (-2.04%) ⬇️
src/rm.js 91.02% <66.66%> (-5.99%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nfischer
Copy link
Member

It looks like there's a CI bug on the main branch (not a problem with your PR). I opened issue #1130 to work on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request (cp): -v flag for verbose output
2 participants