Less verbose logging.
[lightning.git] / exportnumpy.go
index e8854ace8c55f88a8cadf2f2e0b67682808b33c5..bab360aaebb489613e91601974d16b44d200385d 100644 (file)
@@ -6,18 +6,17 @@ import (
        "flag"
        "fmt"
        "io"
-       "log"
+       "io/ioutil"
        "net/http"
        _ "net/http/pprof"
        "os"
 
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "github.com/kshedden/gonpy"
+       log "github.com/sirupsen/logrus"
 )
 
-type exportNumpy struct {
-       output io.Writer
-}
+type exportNumpy struct{}
 
 func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
        var err error
@@ -31,8 +30,8 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
        runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
        projectUUID := flags.String("project", "", "project `UUID` for output data")
-       inputFilename := flags.String("i", "", "input `file`")
-       outputFilename := flags.String("o", "", "output `file`")
+       inputFilename := flags.String("i", "-", "input `file`")
+       outputFilename := flags.String("o", "-", "output `file`")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
                err = nil
@@ -40,7 +39,6 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        } else if err != nil {
                return 2
        }
-       cmd.output = stdout
 
        if *pprof != "" {
                go func() {
@@ -49,7 +47,7 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        }
 
        if !*runlocal {
-               if *outputFilename != "" {
+               if *outputFilename != "-" {
                        err = errors.New("cannot specify output file in container mode: not implemented")
                        return 1
                }
@@ -65,14 +63,30 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
                        return 1
                }
                runner.Args = []string{"export-numpy", "-local=true", "-i", *inputFilename, "-o", "/mnt/output/library.npy"}
-               err = runner.Run()
+               var output string
+               output, err = runner.Run()
                if err != nil {
                        return 1
                }
+               fmt.Fprintln(stdout, output+"/library.npy")
                return 0
        }
 
-       cgs, err := ReadCompactGenomes(stdin)
+       var input io.ReadCloser
+       if *inputFilename == "-" {
+               input = ioutil.NopCloser(stdin)
+       } else {
+               input, err = os.Open(*inputFilename)
+               if err != nil {
+                       return 1
+               }
+               defer input.Close()
+       }
+       cgs, err := ReadCompactGenomes(input)
+       if err != nil {
+               return 1
+       }
+       err = input.Close()
        if err != nil {
                return 1
        }
@@ -91,8 +105,8 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        }
 
        var output io.WriteCloser
-       if *outputFilename == "" {
-               output = nopCloser{cmd.output}
+       if *outputFilename == "-" {
+               output = nopCloser{stdout}
        } else {
                output, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
                if err != nil {