From 1bc7919d2f6a2c4bd62202a0598c9be2994449ab Mon Sep 17 00:00:00 2001 From: "P. Barrett Little" Date: Tue, 10 Sep 2024 23:23:01 -0400 Subject: [PATCH] feat: Implement command-line flags for input params Enhance user interface by replacing positional arguments with named flags for specifying launch monitor type and input file. This change improves usability and provides clearer documentation in both the README and the application itself. The new approach offers better flexibility for future expansions and adheres to common CLI conventions, making the tool more intuitive for users. --- README.md | 9 +++++++-- main.go | 27 ++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 157cabe..9db4049 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,20 @@ cd albatross Albatross is a command-line application. Here's how to use it: ```shell -go run main.go +go run main.go -type -input ``` For example: ```shell -go run main.go mlm2pro input_data.csv +go run main.go -type mlm2pro -input input_data.csv ``` +Command-line flags: + +- `-type`: Specifies the launch monitor type (e.g., "mlm2pro") +- `-input`: Specifies the path to the input CSV file + This will process the `input_data.csv` file using the MLM2Pro launch monitor type and output a file named `input_data_processed.csv` in the same directory. ## Testing diff --git a/main.go b/main.go index 3babd7f..e52e7c0 100755 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( + "flag" "os" "strings" @@ -19,27 +20,31 @@ func main() { // Initialize the logger logging.InitLogger() - // Parse command-line arguments - if len(os.Args) != 3 { - logging.Fatal("Usage: go run main.go ", nil) + // Define command-line flags + launchMonitorType := flag.String("type", "", "Launch monitor type (e.g., mlm2pro)") + inputFile := flag.String("input", "", "Input CSV file path") + flag.Parse() + + // Validate command-line arguments + if *launchMonitorType == "" || *inputFile == "" { + logging.Fatal("Usage: go run main.go -type -input ", nil) } - launchMonitorType := normalizeLaunchMonitorType(os.Args[1]) - inputFile := os.Args[2] + normalizedType := normalizeLaunchMonitorType(*launchMonitorType) // Validate launch monitor type - if !isValidLaunchMonitorType(launchMonitorType) { + if !isValidLaunchMonitorType(normalizedType) { logging.Fatal("Error: Invalid launch monitor type. Supported type is mlm2pro.", logging.Fields{ - "providedType": launchMonitorType, + "providedType": normalizedType, }) } // Process shot data from the input file - shotData, err := parsers.ProcessShotData(inputFile, launchMonitorType) + shotData, err := parsers.ProcessShotData(*inputFile, normalizedType) if err != nil { logging.Error("Error processing shot data", err, logging.Fields{ - "inputFile": inputFile, - "launchMonitorType": launchMonitorType, + "inputFile": *inputFile, + "launchMonitorType": normalizedType, }) os.Exit(1) } @@ -56,7 +61,7 @@ func main() { }) // Write processed data to an output file - outputFile := utils.ReplaceFileExtension(inputFile, "_processed.csv") + outputFile := utils.ReplaceFileExtension(*inputFile, "_processed.csv") writer := writer.ShotPatternWriter{} if err := writer.Write(outputFile, shotData); err != nil { logging.Error("Error writing output file", err, logging.Fields{