WIP Refactor to ensure carriage returns are removed, plus tests #3
Loading…
Reference in New Issue
No description provided.
Delete Branch "asdf/gfu:no_carriage_returns_allowed"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
gfu was inconsistent with carriage returns, removing them whenever a line is modified but leaving them on the unmodified lines.
This change uses
bufio
scanner
to read lines, because it strips all line terminators automatically. It has an added advantage of not having to manage End Of File state when reading.I added some basic tests to make sure the output is correct, but this required some changes to the design of
readFile()
.outFile
is also no longer a global variable, but is returned/accepted as required.This needs a bit of review before consideration for merging, namely:
buildComments
is nowbuildInfoText
because it matches the documentation.This all looks good to me. You mentioned it as a work in progress, so I will leave the PR open for now and keep an eye out for updates to it.
What do you think about the header/footer functionality? Is that something that makes sense in this application? Can you think of anything else that would be good? The only thing I can think of is a flag to direct to a different output file.... that is largely taken care of by your stdout flag though as someone can just direct into a file. Maybe listing that as an example usage would be a good call? That way those less familiar with nix style piping and redirecting can still take advantage of that as a feature?
So, if I am understanding correctly, this states that the default scanner behavior is scanLines, yeah? In which case this all makes sense. It is weird that they hide that fact in this method rather than mentioning it in the docs to scan itself.
That is right. I actually found out about it while searching how to deal with both types of line termination styles, and by then using the examples.
I think it would probably make sense to move the newline to
errorExit
itself, that way it does not have to be added to every errorExit that gets called. What do you think?@ -129,2 +127,3 @@
func main() {
deconstructCommentLinks := flag.Bool("d", false, "Deconstruct a gophermap's info text lines back to plain text")
//command-line flags and responses
deconstructInfoTextLines := flag.Bool("d", false, "Deconstruct a gophermap's info text lines back to plain text")
I agree with changing this everywhere for consistency (from commentLinks to InfoTextLines). Good call.
I read the linked stack overflow page and I'm not sure why they are doing differently with flags (in the answer I mean, the question is way different from what is going on in gfu). Do you mean moving the flag variables into global space and out of main? Or something else?
Yes, sorry, the question I linked to isn't really relevant. I meant that moving as much of the flag management out of
main()
would improve readability. The style that is in the answer is the approach I will try.Also, to respond to your main review text, I agree with all your suggestions. The "roadmap" might look like:
Do you know much about makefiles? I really want to include a man page with bombadillo... but I dont really know make at all. Is that the right tool for that job? I am also thinking that with v2 I might try to get it together as a snap package once it is ready for release. Sorry, off topic for this repo.
That roadmap looks great :)
I made a new issue on Bombadillo to cover this. Generally, anything I learn here I'll apply to Bombadillo as well (I started this while making changes to bombadillo-info).
To answer your question: I've only looked in to what is possible, but will have to learn any of the methods.
Awesome.
This PR looks good to me, is it ready for merge? Or were you still adding more (I felt like I had not merged it for some reason or other relating to that).
Still working my way through it, I'll update once I have completed the work.
OK, this PR has all intended items complete, and is ready for merge after review.
This last commit changes:
log.Fatalln
init()
and global variablesIt was fun to make and I learned a lot.
Looks great! I was confused about a small part but then saw what you did. Makes perfect sense (it had to do with a named return and me not noticing it so wondering why you werent returning an error... but you were).
I'm gonna merge it. You've done a great job with this! The changes will, I think, be really beneficial. :)