I'm using the cli Go package: https://github.com/codegangsta/cli
package main
import (
"fmt"
"github.com/codegangsta/cli"
"io/ioutil"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "m2k"
app.Usage = "convert markdown to kindle"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "file",
Value: "english",
Usage: "language for the greeting",
},
}
app.Action = func(c *cli.Context) {
file := "default"
if len(c.Args()) > 0 {
file = c.Args()[0]
}
//fmt.Println("file %s", file)
fmt.Println("file %s", file)
b, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("output.txt", b, 0644)
if err != nil {
panic(err)
}
}
app.Run(os.Args)
}
I'm a Go beginner. So I probably did something very wrong.
I do this in the command line (I have a file called markdown.txt
in the directory):
~/go/io$ go run io.go -file markdown.txt
But I get this error:
created by runtime.main /usr/lib/go/src/pkg/runtime/proc.c:221 exit status 2
EDIT:
I wrote fmt.Println("file %s", file)
to app.Action
but nothing is printed. Does this tell something about the problem?