Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cmd/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"os"

"github.com/activecm/rita/v5/config"
"github.com/activecm/rita/v5/database"
Expand Down Expand Up @@ -91,18 +92,18 @@ var ViewCommand = &cli.Command{
return err
}

// check for updates after running the command
if err := CheckForUpdate(cfg); err != nil {
return err
// check for updates after running the command, skip if using output flag
if !cCtx.Bool("stdout") {
if err := CheckForUpdate(cfg); err != nil {
return err
}
}

return nil
},
}

func runViewCmd(cfg *config.Config, dbName string, stdout bool, search string, limit int) error {
fmt.Printf("Viewing database: %s\n", dbName)

// connect to database
db, err := database.ConnectToDB(context.Background(), dbName, cfg, nil)
if err != nil {
Expand All @@ -120,6 +121,14 @@ func runViewCmd(cfg *config.Config, dbName string, stdout bool, search string, l

// if stdout was requested, get CSV output
if stdout {
outInfo, err := os.Stdout.Stat()
if err != nil {
return err
}
// display the message only when printing stdout to the terminal
if (outInfo.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
fmt.Printf("Viewing database: %s\n", dbName)
}

// get CSV output
csvData, err := viewer.GetCSVOutput(db, minTimestamp, util.GetRelativeFirstSeenTimestamp(useCurrentTime, maxTimestamp), search, limit)
Expand Down