Skip to content

Commit d2e19c7

Browse files
author
jdv
committed
adding csv output creating report and details csv files
proper csv format split from file output system + some facorization
1 parent 02f285a commit d2e19c7

File tree

9 files changed

+1289
-42
lines changed

9 files changed

+1289
-42
lines changed

cmd/ipdex/config/global.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package config
22

33
var (
4-
OutputFormat string
5-
ForceRefresh bool
6-
Yes bool
7-
Detailed bool
8-
ReportName string
9-
Batching bool
4+
OutputFormat string
5+
OutputFilePath string
6+
ForceRefresh bool
7+
Yes bool
8+
Detailed bool
9+
ReportName string
10+
Batching bool
1011
)

cmd/ipdex/config/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func GetConfigFolder() (string, error) {
3838

3939
func IsSupportedOutputFormat(outputFormat string) bool {
4040
switch outputFormat {
41-
case display.JSONFormat, display.HumanFormat:
41+
case display.JSONFormat, display.HumanFormat, display.CSVFormat:
4242
return true
4343
default:
4444
return false

cmd/ipdex/file/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func FileCommand(file string, forceRefresh bool, yes bool) {
206206
}
207207
}
208208
stats := reportClient.GetStats(report)
209-
if err := reportClient.Display(report, stats, viper.GetString(config.OutputFormatOption), config.Detailed); err != nil {
209+
if err := reportClient.Display(report, stats, viper.GetString(config.OutputFormatOption), config.Detailed, config.OutputFilePath); err != nil {
210210
style.Fatal(err.Error())
211211
}
212212
if !reportExist && outputFormat == display.HumanFormat {

cmd/ipdex/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func init() {
7575
rootCmd.Flags().BoolVarP(&config.ForceRefresh, "refresh", "r", false, "Force refresh an IP or all the IPs of a report")
7676
rootCmd.Flags().BoolVarP(&config.Yes, "yes", "y", false, "Say automatically yes to the warning about the number of IPs to scan")
7777
rootCmd.PersistentFlags().BoolVarP(&config.Detailed, "detailed", "d", false, "Show all informations about an IP or a report")
78-
rootCmd.PersistentFlags().StringVarP(&config.OutputFormat, "output", "o", "", "Output format: human or json")
78+
rootCmd.PersistentFlags().StringVarP(&config.OutputFormat, "output", "o", "", "Output format: human, json, or csv")
79+
rootCmd.PersistentFlags().StringVar(&config.OutputFilePath, "output-path", "", "Output file path for saving reports in the format specified by -o (saves report and details files separately)")
7980
rootCmd.Flags().StringVarP(&config.ReportName, "name", "n", "", "Report name when scanning a file or making a search query")
8081
rootCmd.Flags().BoolVarP(&config.Batching, "batch", "b", false, "Use batching to request the CrowdSec API. Make sure you have a premium API key to use this feature.")
8182
}

cmd/ipdex/report/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewShowCommand() *cobra.Command {
5454
} else {
5555
style.Fatal("Please provide a report ID or file used in the report you want to show with `ipdex report show 1`")
5656
}
57-
if err := reportClient.Display(report, report.Stats, viper.GetString(config.OutputFormatOption), config.Detailed); err != nil {
57+
if err := reportClient.Display(report, report.Stats, viper.GetString(config.OutputFormatOption), config.Detailed, config.OutputFilePath); err != nil {
5858
style.Fatal(err.Error())
5959
}
6060
fmt.Println()

cmd/ipdex/search/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func SearchCommand(query string, since string, maxResult int) {
118118
style.Fatalf("unable to create report: %s", err)
119119
}
120120
stats := reportClient.GetStats(report)
121-
if err := reportClient.Display(report, stats, viper.GetString(config.OutputFormatOption), config.Detailed); err != nil {
121+
if err := reportClient.Display(report, stats, viper.GetString(config.OutputFormatOption), config.Detailed, config.OutputFilePath); err != nil {
122122
style.Fatal(err.Error())
123123
}
124124
if outputFormat == display.HumanFormat {

0 commit comments

Comments
 (0)