From 46fa46c9f2d6bde65fb296f2a73db6564b4e8f5c Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 11 Dec 2023 22:03:28 +0700 Subject: [PATCH] Fix [Golang] [Module] Main Command (#32) - [+] fix(main.go): add validation for formatOption before proceeding with CSV conversion - [+] fix(main.go): handle invalid formatOption values and print error message --- main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 7617823..cc1b494 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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.") } }