Add import -o argument.
authorTom Clegg <tom@tomclegg.ca>
Mon, 2 Mar 2020 14:53:12 +0000 (09:53 -0500)
committerTom Clegg <tom@tomclegg.ca>
Mon, 2 Mar 2020 14:53:12 +0000 (09:53 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

import.go

index a38abc6861aaecf593c3e987a6036470d8ae43bc..49a7c7a885b2e1478a6b31b9e5bcda4cdbdd24fd 100644 (file)
--- a/import.go
+++ b/import.go
@@ -26,6 +26,7 @@ import (
 type importer struct {
        tagLibraryFile string
        refFile        string
+       outputFile     string
        encoder        *gob.Encoder
 }
 
@@ -40,6 +41,7 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        flags.SetOutput(stderr)
        flags.StringVar(&cmd.tagLibraryFile, "tag-library", "", "tag library fasta `file`")
        flags.StringVar(&cmd.refFile, "ref", "", "reference fasta `file`")
+       flags.StringVar(&cmd.outputFile, "o", "", "output `file`")
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
@@ -75,8 +77,21 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
                        log.Printf("tilelib.Len() == %d", tilelib.Len())
                }
        }()
-       w := bufio.NewWriter(stdout)
+
+       var outfile *os.File
+       var w *bufio.Writer
+       if cmd.outputFile == "" {
+               w = bufio.NewWriter(stdout)
+       } else {
+               outfile, err = os.OpenFile(cmd.outputFile, os.O_CREATE|os.O_WRONLY, 0777)
+               if err != nil {
+                       return 1
+               }
+               defer outfile.Close()
+               w = bufio.NewWriter(outfile)
+       }
        cmd.encoder = gob.NewEncoder(w)
+
        err = cmd.tileInputs(tilelib, infiles)
        if err != nil {
                return 1
@@ -85,6 +100,12 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        if err != nil {
                return 1
        }
+       if outfile != nil {
+               err = outfile.Close()
+               if err != nil {
+                       return 1
+               }
+       }
        return 0
 }