Skip to content

Commit

Permalink
chore(cmd): refactor config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
geyslan committed Aug 16, 2023
1 parent add4054 commit 0611b6d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/tracee/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
)

var (
cfgFile string
helpFlag bool
rootCmd = &cobra.Command{
cfgFileFlag string
helpFlag bool

rootCmd = &cobra.Command{
Use: "tracee",
Short: "Trace OS events and syscalls using eBPF",
Long: `Tracee uses eBPF technology to tap into your system and give you
Expand All @@ -44,7 +45,7 @@ access to hundreds of events that help you understand how your system behaves.`,
}
os.Exit(0)
}
initConfig()
checkConfigFlag()
}
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -137,7 +138,7 @@ func initCmd() error {

// config is not bound to viper
rootCmd.Flags().StringVar(
&cfgFile,
&cfgFileFlag,
"config",
"",
"<file>\t\t\t\tGlobal config file (yaml, json between others - see documentation)",
Expand Down Expand Up @@ -322,12 +323,12 @@ func initCmd() error {
return nil
}

func initConfig() {
if cfgFile == "" {
func checkConfigFlag() {
if cfgFileFlag == "" {
return
}

cfgFile, err := filepath.Abs(cfgFile)
cfgFile, err := filepath.Abs(cfgFileFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", errfmt.WrapError(err))
os.Exit(1)
Expand Down

0 comments on commit 0611b6d

Please sign in to comment.