Repository navigation
Conversation
Write the listing to a file instead of standard output. Progress and log output keep going to the terminal, so a listing can be captured while watching --progress. lsjson wrote to os.Stdout directly; it now writes to the chosen writer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change do?
Adds
--output-filetols,lsl,lsd,lsfandlsjson, so the listing can go to a file while--progressand the log keep the terminal. This is option 1 from the issue, which @ncw preferred over sending progress to stderr.Today, redirecting stdout with
-Pcaptures the progress block as well, because the ls commands write throughos.Stdout, which--progressintercepts (operations.SyncFprintfspecial-casesw == os.Stdout). A file passed to the same functions is written directly, so nothing new is needed infs/operations.cmd/ls/lshelpgets the flag and anOutput()helper that returnsos.Stdoutor the created file, modelled onhashsum --output-file. It lives inlshelpbecause all five commands already import it for the shared help, which also gains a sentence about the flag. The name followshashsum(and the issue) rather thantree --output.ls,lsl,lsdandlsfpass the writer to theoperations.List*/Lsffunctions they already call withos.Stdout.lsjsonwas the only one writingos.Stdoutdirectly, withfmt.Print*for the brackets and separators. Its body moves intolsJSON(ctx, fsrc, remote, w io.Writer)and every write goes towwith the error checked. Output is unchanged: I comparedlsjson -Randlsjson --statfrom this branch and from master byte for byte oncmd/lsf/testfiles.Without the flag all five commands still pass the real
os.Stdout, so--progressinterception behaves as before.Testing
cmd/ls/lshelp/lshelp_test.go:Output()returnsos.Stdoutwhen the flag is empty, writes to and closes the file when set, and returns an error for a path that cannot be created.cmd/lsjson/lsjson_test.go:lsJSONwrites a parseable listing, and a--statitem, to the given writer, usingcmd/lsf/testfiles; an empty directory gives exactly[\n]\n.cmd/lsf/testfiles:ls,lsl,lsd,lsf,lsjson -Randlsjson --statwith--output-fileleave stdout empty and write the listing to the file;lsjson -R --output-file x.json -Pshows only the progress block on the terminal andx.jsonparses; a path in a missing directory fails withfailed to create output file ....go build ./...,go test -raceon the five packages, andgolangci-lint run(v2.15.0) on them all pass.No change to
docs/content/commands, which is generated at release time; the flag shows up in--helpand the sentence in the shared help covers the usage.Linked issue
Fixes #8358
Checklist
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.