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

Feature request (cp): -v flag for verbose output #1127

Open
nicky1038 opened this issue Aug 21, 2023 · 3 comments · May be fixed by #1129
Open

Feature request (cp): -v flag for verbose output #1127

nicky1038 opened this issue Aug 21, 2023 · 3 comments · May be fixed by #1129
Labels
bash compat Compatibility issues with bash or POSIX behavior feature

Comments

@nicky1038
Copy link

nicky1038 commented Aug 21, 2023

The original cp command in Linux has -v flag, it prints out source and destination for every copied file line-by-line, e. g.:

'foo/some-file-1.txt' -> 'bar/foo/some-file-1.txt'
'foo/some-file-2.jpg' -> 'bar/foo/some-file-2.jpg'

It would be very useful to have this feature in the package, so that users could have more clue of what's going on when something is being copied.

@nfischer nfischer added feature bash compat Compatibility issues with bash or POSIX behavior labels Aug 22, 2023
@nfischer
Copy link
Member

Seems like a reasonable feature request. We could do the same for shell.mv() and shell.rm() too.

It looks like we already have something like this for shell.chmod(), where the behavior is simply console.log() each line. So this output would not be part of the .stdout string returned by the function. Does printing directly the console work for your use case, or do you need the output stored in .stdout for programmatic access?

shelljs/src/chmod.js

Lines 192 to 194 in f7a7c75

if (options.verbose) {
console.log(file + ' -> ' + newPerms.toString(8));
}

@nicky1038
Copy link
Author

nicky1038 commented Aug 22, 2023

@nfischer Thank you for such a fast response and your willingness to help!

My goal is just to print this information into the console. Still, doesn't console.log invoke process.stdout.write under the hood? If so, then there would be no flaws in its usage

@nfischer
Copy link
Member

Sorry, I think I was unclear. You're correct that console.log() prints to the "real" stdout. What I was talking about in my last comment is the ShellString return type, which has object properties named .stdout, .stderr, and .code: https://github.com/shelljs/shelljs#shellstringstr. We typically aim for ShellJS functions to return a string in the .stdout property which represents whatever the real Unix command would have printed to stdout (e.g., if Unix cat prints a file's contents to stdout, then shell.cat() returns a file's contents as a ShellString).

But if you don't need programmatic access to the output, then I think it's fine to just print directly to console like you've done in #1129.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash compat Compatibility issues with bash or POSIX behavior feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants