By Developers, For Developers

Historical errata for Powerful Command-Line Applications in Go

PDF PgPaper PgTypeDescriptionFixed onComments
7TYPO

Second paragraph last sentence…
“Many of these tools are written in teh Go programming language.“
teh should be the

Third paragraph second sentence…
“It is the ideal choice to write command line tools as it provides the easy of use and flexibil- ity to quickly prototype new tools and…”
I think “easy” should be “ease”

2019-11-23
18TYPO

Typo in comment in func main():

// Calling the count function to coun the number of words
// received from the Standard Input and printing it out

See “coun” (should be “count”) in first line of above comment.

2019-11-23
23-24ERROR

path.Join does not use the correct separator on Windows. It creates a path like “…\\\\cmd\\\\todo/todo”.
Also, setting binName to “todo” was problematic. I could run the file it creates from the command line, but running it with cmd.Run() only resulted in “file does not exist”. Changing binName to “todo.exe” fixes the problem. I am not sure if there is another way to fix it and preserve the portability of the code.

2019-11-25
VTYPO

“Teh” instead of “the”

2019-11-23
7TYPO

It says: “Many of these tools are written in teh Go programming language”. “teh” should be “the”.

2019-11-30
VTYPO

in “as it provides the easy of use and flexibility to quickly prototype” it should probably read “ease of use”

2019-12-05
18TYPO

In the comment of the main() function the second instance of the word ‘count’ is spelled ‘coun’.

2019-12-14
9178TYPO

“info , of type os.Info containing metadata about the file or directory named by path , such as name, size, permissions, and others.”

Should be “of type os.FileInfo”

2020-01-18
10794TYPO

“the program will sned output to STDOUT” should be “send output”.

2020-01-18
118105SUGGEST

Consider using filepath.Glob when building list of filenames from tempDir. It might be a trade off between cleaner code and introducing a new function (filepath.Glob) and a more verbose way to build the list introducing filepath.Match and practicing iteration / appending to slices etc.

The two last code blocks on the page can be replaced with:

pattern := filepath.Join(tempDir, fmt.Sprintf(“*%s”, tc.cfg.ext))
expFiles, err := filepath.Glob(pattern)
if err != nil {
t.Fatal(err)
}

2020-01-18
16TYPO

Commend on Get() method code example reads:

// Get method opens the provided file name, decodes
// the JSON data and parse into a List

Should be something like:

// Get method opens the provided file name, decodes
// the JSON data and parses it into a List

2020-02-13
50TYPO

On page 50, there is the contents of “test1.md.html”. There are spaces before the first "

" tag, but those spaces are not generated when I run the program.

2020-03-18
53TYPO

On page 53, in the contents of “README.md.html”, there are spaces before the first "

" tag, but those spaces are not generated when I run the program.

2020-03-18
50SUGGEST

Please forget two reports I submitted. They are my mistakes. Sorry.

2020-03-18
5236TYPO

“… specify options once in ther shell configuration …”

should be “their” not “ther”

2020-03-18
6145TYPO

"In Go, you install external packages by using the go get tool. To install these two packages, run the following commands:

Since you’re using Go modules, you do not need to download these packages in advance."

it looks like you removed some stuff about using go get and updated it with the module system, but left some of the go get stuff behind.

6145SUGGEST

Actually, this applies to pretty much every example. You start out by telling the reader to import all of the packages they will need for the example. In this case, you are extending this to the external dependencies on blackfriday and bluemonday, relying on the compiler to add those dependencies to go.mod.

The problem I run into with this is that I am using an editor that is set up to use gofmt and goimports to automatically manage formatting and imports every time I save the file. This winds up removing all of those imports until they are actually used in the code. So far in the book I’ve just been ignoring the import section and allowing goimports to take care of that. But now with the external dependencies, it gets a little more complicated. I have to wait until I actually use bluemonday and blackfriday and add the imports at that time. Another option is to just run:

go get github.com/microcosm-cc/bluemonday
go get github.com/russross/blackfriday/v2

on the command line inside the project, which will add the necessary require statements to the go.mod file and make them available for auto-import via goimports. This is what I did and it worked well.

I understand that it’s a tough call because you don’t know what tool chain people are using.

1SUGGEST

It is great that there are exercises at the end of each chapter, however it would also be nice if you provided your own implementation of the solution, so that after completing the exercises the reader could compare to see the differences, learn what the reader may have done well or not so much, etc, etc..

6TYPO

Code sample for adding flags to the word counter main function has the following comment:

// Defining a boolean flag -l to count iines instead of words

Should be:

// Defining a boolean flag -l to count lines instead of words

31TYPO

Under the “Display Command Line Tool Usage” header, the word “Cmmand-line” is misspelled.

7ERROR

Running the TestCountLines test fails with the error message fails with error message TestCountLines: main_test.go:24: Expected 3, got 6 instead. Here is the environment running on macOS Catalina Version 10.15.4 and JONs-iMac:wc jon$ go version
go version go1.14.2 darwin/amd64 and here is the code// TestCountLines tests the count function set to count lines
func TestCountLines(t *testing.T) {
\tb := bytes.NewBufferString(“word1 word2 word3\
line2\
line3 word1”)
\texp := 3
res := count(b, true)
\tif res != exp {
\t\tt.Errorf(“Expected %d, got %d instead.\
”, exp, res)
\t}
}

Here is the full error message
JONs-iMac:wc jon$ go test -v
= RUN TestCountWords --- PASS: TestCountWords (0.00s) = RUN TestCountLines
TestCountLines: main_test.go:24: Expected 3, got 6 instead.
—- FAIL: TestCountLines (0.00s)
FAIL
exit status 1
FAIL\tpragprog.com/rggo/firstProgram/wc\t0.263s

My guess is that construction of the buffer is incorrect. Will play around with it to see if I can figure it out.

49TYPO

Towards the bottom of the first paragraph on page 49, on the far right, the word “functio” is misspelled. It should be “function”

59TYPO

In the comment of the “workingFiles/mdp.v3/main.go” code listing “// Open the file on the browser”, it seems like the word “on” should actually be “in”.

66TYPO

In the comment for the content struct there is a typo, “tto” should be “to”.

// content type represents the HTML content tto add into the template
type content struct {
Title string
Body template.HTML
}

20TYPO

‘func​ count(r io.Reader) ​int​ { ​ \t ​// A scanner is used to read text from the a Reader (such as files)​’

>> A scanner is used to read text from a Reader (remove the)

20TYPO

- When executed with one or more arguments, it will concatenate the arguments as a new item and it to the list.
+ When executed with one or more arguments, it will concatenate the arguments as a new item and add it to the list.

(Needs addition of word “add”)

0ERROR

Several test suites in “processes” fail (at least v3, v6, v7).

I’m running Go 1.14.2 on Linux amd64.

Categories: