Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Fix [Golang] [Module] Main Command (#32)
Browse files Browse the repository at this point in the history
- [+] fix(main.go): add validation for formatOption before proceeding with CSV conversion
- [+] fix(main.go): handle invalid formatOption values and print error message
  • Loading branch information
H0llyW00dzZ authored Dec 11, 2023
1 parent 6275c7f commit 46fa46c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ func executeCSVConversion(rfs filesystem.FileSystem, ctx context.Context, reader
var csvFileName string
var err error

// Check if the format option is valid before proceeding
if formatOption != OutputFormatInline && formatOption != OutputFormatPerLine &&
formatOption != OutputFormatSeparateCSV && formatOption != OutputFormatJSONInCSV {
fmt.Println("Invalid CSV format option.")
return
}

if formatOption != OutputFormatSeparateCSV {
csvFileName, err = promptForInput(ctx, reader, PromptEnterCSVFileName)
if err != nil {
Expand All @@ -331,13 +338,11 @@ func executeCSVConversion(rfs filesystem.FileSystem, ctx context.Context, reader

switch formatOption {
case OutputFormatSeparateCSV:
// If the user chooses to create separate files, prompt for file names and execute accordingly.
// Pass the FileSystem to createSeparateCSVFiles
createSeparateCSVFiles(rfs, ctx, reader, sessions)
default:
// Otherwise, convert the sessions to a single CSV file.
// Pass the FileSystem to convertToSingleCSV
case OutputFormatInline, OutputFormatPerLine, OutputFormatJSONInCSV:
convertToSingleCSV(rfs, ctx, reader, sessions, formatOption, csvFileName)
default:
fmt.Println("Invalid format option.")
}
}

Expand Down

0 comments on commit 46fa46c

Please sign in to comment.