I have the following code
package main
import (
"fmt"
"flag"
)
var outputOnly bool
func something() string {
if outputOnly {
fmt.Println("outputting only")
} else {
fmt.Println("executing commands")
}
return "blah"
}
func main() {
vmoutputonlyPtr := flag.Bool("outputonly",false,"If set it will only output the commands it would execute, naturally without the correct parameter values set.")
flag.Parse()
outputOnly := *vmoutputonlyPtr
if outputOnly {
fmt.Println("outputonly commands will not execute")
}
var blah string
blah = something()
fmt.Println("blah is " + blah)
}
But the output is this:
$ ./se -outputonly
outputonly commands will not execute
executing commands
ie. it appears that the function something() is aware of the global variable, but does not reflect its true value. This is my first attempt at golang. What am I doing wrong?