Skip to content

Commit

Permalink
feat: Implement command-line flags for input params
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pblittle committed Sep 11, 2024
1 parent 3d3650c commit 1bc7919
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ cd albatross
Albatross is a command-line application. Here's how to use it:

```shell
go run main.go <launch_monitor_type> <input_csv_file>
go run main.go -type <launch_monitor_type> -input <input_csv_file>
```

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
Expand Down
27 changes: 16 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"flag"
"os"
"strings"

Expand All @@ -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 <launch_monitor_type> <input_csv_file>", 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 <launch_monitor_type> -input <input_csv_file>", 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)
}
Expand All @@ -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{
Expand Down

0 comments on commit 1bc7919

Please sign in to comment.