robertkrimen / godocdown

Format package documentation (godoc) as GitHub friendly Markdown
526 stars 56 forks source link

Manual pull-request: "out-file" flag #2

Closed metaleap closed 11 years ago

metaleap commented 11 years ago

Hi, this tool is awesome but I had a minor need --- specifying a target output file name via args-flags. In my local copy I added this to global flag vars:

flag_outfile    = flag.String("outfile", "", "To print to a file instead of standard-output, specify a file name.")

Then in func main() at the very end changed the single fmt.Printfln(documentation) to this:

if len(*flag_outfile) > 0 {
    if err = ioutil.WriteFile(*flag_outfile, []byte(documentation), os.ModePerm); err != nil {
        panic(err)
    }
} else {
    fmt.Println(documentation)
}

Would you consider adding this (or something of this sort) to the tool source? Mainly so if you later on push other updates, I can update godocdown without having to re-apply this very minor but highly useful little customization.. ;)

metaleap commented 11 years ago

BTW I know in the terminal or in shell scripts you can just do godocdown -opt=ion > outfile.md, but imagine some scenario such as a text-editor's or some build-system's "pre-build commands" feature which does not support piping syntaxes, only "lists of commands with args"... if we put the write-to-file logic right in godocdown as per above, I as a user can stay cross-platform instead of having to wrestle with additional shell scripts or batch scripts etc...

robertkrimen commented 11 years ago

BTW I know in the terminal or in shell scripts you can just do...

You read my mind... :)

I will take a look, thanks.

metaleap commented 11 years ago

Awesome, thx!

robertkrimen commented 11 years ago

No problem, thanks. :+1: