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

Commit

Permalink
Don't use a flag for the input file.
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Jul 17, 2020
1 parent b65e0e2 commit 93c2df5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ etc.
```

```
$ usl -in measurements.csv 10 50 100 150 200 250 300
$ usl measurements.csv 10 50 100 150 200 250 300
URL parameters: σ=0.02772985648395876, κ=0.00010434289088915312, λ=89.98778453648904
max throughput: 1883.7622524836281, max concurrency: 96
contention constrained
Expand Down
20 changes: 10 additions & 10 deletions cmd/usl/usl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//
// We can then run the USL binary:
//
// usl -in data.csv
// usl data.csv
//
// USL parses the given CSV file as a series of (concurrency, throughput) points, calculates the USL
// parameters using quadratic regression, and then prints out the details of the model, along with a
Expand All @@ -41,7 +41,7 @@
// Finally, we can provide USL a series of additional data points to provide
// estimates for:
//
// usl -in data.csv 128 256 512
// usl data.csv 128 256 512
//
// USL will output the data in CSV format on STDOUT.
//
Expand Down Expand Up @@ -70,7 +70,6 @@ func main() {

//nolint:goerr113 // not a package
func run() error {
input := flag.String("in", "", "input file")
nCol := flag.Int("n_col", 1, "column index of concurrency values")
rCol := flag.Int("r_col", 2, "column index of latency values")
skipHeaders := flag.Bool("skip_headers", false, "skip the first line")
Expand All @@ -79,17 +78,18 @@ func run() error {
noGraph := flag.Bool("no_graph", false, "don't print the graph")

flag.Usage = func() {
_, _ = fmt.Fprintf(os.Stderr, "Usage: usl <-in input.csv> [options] [points...]\n\n")
_, _ = fmt.Fprintf(os.Stderr, "Usage: usl <input.csv> [options] [points...]\n\n")

flag.PrintDefaults()
}
flag.Parse()

if len(*input) == 0 {
return fmt.Errorf("no input files provided")
if len(flag.Args()) == 0 {
flag.Usage()
return fmt.Errorf("no input file provided")
}

measurements, err := parseCSV(*input, *nCol, *rCol, *skipHeaders)
measurements, err := parseCSV(flag.Arg(0), *nCol, *rCol, *skipHeaders)
if err != nil {
return fmt.Errorf("error parsing %w", err)
}
Expand All @@ -101,7 +101,7 @@ func run() error {

printModel(m, measurements, *noGraph, *width, *height)

return printPredictions(m)
return printPredictions(m, flag.Args()[1:])
}

func printModel(m *usl.Model, measurements []usl.Measurement, noGraph bool, width, height int) {
Expand Down Expand Up @@ -149,8 +149,8 @@ func printModel(m *usl.Model, measurements []usl.Measurement, noGraph bool, widt
_, _ = fmt.Fprintln(os.Stderr)
}

func printPredictions(m *usl.Model) error {
for _, s := range flag.Args() {
func printPredictions(m *usl.Model, args []string) error {
for _, s := range args {
n, err := strconv.ParseFloat(s, 64)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/usl/usl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestBadThroughput(t *testing.T) {
}

func TestMainRun(t *testing.T) {
stdout, stderr := fakeMain(t, "-in", "example.csv", "1", "2", "3")
stdout, stderr := fakeMain(t, "example.csv", "1", "2", "3")

assert.Equal(t, "stdout",
`1.000000,89.987785
Expand Down

0 comments on commit 93c2df5

Please sign in to comment.