Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/ipdex/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetConfigFolder() (string, error) {

func IsSupportedOutputFormat(outputFormat string) bool {
switch outputFormat {
case display.JSONFormat, display.HumanFormat, display.CSVFormat:
case display.JSONFormat, display.HumanFormat, display.CSVFormat, display.PDFFormat:
return true
default:
return false
Expand Down
51 changes: 51 additions & 0 deletions cmd/ipdex/config/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -52,3 +53,53 @@ func IsValidInt(s string) bool {
_, err := strconv.Atoi(s)
return err == nil
}

// EnsureOutputPath checks if the output directory exists and offers to create it if not.
// Returns true if the path exists or was created, false if the user declined.
func EnsureOutputPath(outputPath string) (bool, error) {
if outputPath == "" {
return true, nil
}

absPath, err := filepath.Abs(outputPath)
if err != nil {
return false, err
}

// Check if path exists
info, err := os.Stat(absPath)
if err == nil {
// Path exists, check if it's a directory
if !info.IsDir() {
return false, fmt.Errorf("output path '%s' exists but is not a directory", absPath)
}
return true, nil
}

if !os.IsNotExist(err) {
return false, err
}

// Path doesn't exist, prompt to create
pterm.Warning.Printf("Output directory '%s' does not exist.\n", absPath)

confirm, err := pterm.DefaultInteractiveConfirm.
WithDefaultText("Do you want to create it?").
WithDefaultValue(true).
Show()
if err != nil {
return false, err
}

if !confirm {
return false, nil
}

// Create the directory
if err := os.MkdirAll(absPath, 0755); err != nil {
return false, fmt.Errorf("failed to create directory: %w", err)
}

pterm.Success.Printf("Created directory '%s'\n", absPath)
return true, nil
}
15 changes: 14 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ require (
github.com/charmbracelet/lipgloss v1.0.0
github.com/crowdsecurity/crowdsec v1.6.5-rc4.0.20250331124451-78a6179566a7
github.com/glebarez/sqlite v1.11.0
github.com/johnfercher/maroto/v2 v2.3.3
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
github.com/pterm/pterm v0.12.80
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/wcharczuk/go-chart/v2 v2.1.2
golang.org/x/text v0.23.0
gorm.io/gorm v1.25.12
)
Expand All @@ -20,20 +23,25 @@ require (
atomicgo.dev/schedule v0.1.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blackfireio/osinfo v1.0.5 // indirect
github.com/boombuler/barcode v1.0.1 // indirect
github.com/charmbracelet/x/ansi v0.4.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/crowdsecurity/go-cs-lib v0.0.16 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/f-amaral/go-async v0.3.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hhrutter/lzw v1.0.0 // indirect
github.com/hhrutter/tiff v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/johnfercher/go-tree v1.0.5 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
Expand All @@ -43,7 +51,10 @@ require (
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pdfcpu/pdfcpu v0.6.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/phpdave11/gofpdf v1.4.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
Expand All @@ -57,10 +68,12 @@ require (
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
Expand Down
Loading