From 87e1b79036a724588699a60cf1a2b1cd779b6bf7 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Fri, 17 Mar 2017 16:38:22 +0900 Subject: [PATCH] Fix nil-ponter in TUI --- commands/tui.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/commands/tui.go b/commands/tui.go index 5e9fa77439..925a503f18 100644 --- a/commands/tui.go +++ b/commands/tui.go @@ -27,15 +27,18 @@ import ( c "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/report" + "github.com/future-architect/vuls/util" "github.com/google/subcommands" ) // TuiCmd is Subcommand of host discovery mode type TuiCmd struct { - lang string - debugSQL bool - resultsDir string + lang string + debugSQL bool + debug bool + logDir string + resultsDir string refreshCve bool cvedbtype string cvedbpath string @@ -57,8 +60,10 @@ func (*TuiCmd) Usage() string { [-cvedb-type=sqlite3|mysql] [-cvedb-path=/path/to/cve.sqlite3] [-cvedb-url=http://127.0.0.1:1323 or mysql connection string] - [-results-dir=/path/to/results] [-refresh-cve] + [-results-dir=/path/to/results] + [-log-dir=/path/to/log] + [-debug] [-debug-sql] [-pipe] @@ -70,6 +75,9 @@ func (p *TuiCmd) SetFlags(f *flag.FlagSet) { // f.StringVar(&p.lang, "lang", "en", "[en|ja]") f.BoolVar(&p.debugSQL, "debug-sql", false, "debug SQL") + defaultLogDir := util.GetDefaultLogDir() + f.StringVar(&p.logDir, "log-dir", defaultLogDir, "/path/to/log") + wd, _ := os.Getwd() defaultResultsDir := filepath.Join(wd, "results") f.StringVar(&p.resultsDir, "results-dir", defaultResultsDir, "/path/to/results") @@ -109,7 +117,13 @@ func (p *TuiCmd) SetFlags(f *flag.FlagSet) { // Execute execute func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { c.Conf.Lang = "en" + + // Setup Logger + c.Conf.Debug = p.debug c.Conf.DebugSQL = p.debugSQL + c.Conf.LogDir = p.logDir + util.Log = util.NewCustomLogger(c.ServerInfo{}) + c.Conf.ResultsDir = p.resultsDir c.Conf.CveDBType = p.cvedbtype c.Conf.CveDBPath = p.cvedbpath