7cde93fca4
1. the description of the command and the helper function are clear hints that the command is intended to show a single JSON measurement at a time (also the use case seems clear) [*] 2. the function used to read lines was failing for all my measurements that take input. Since that was not the optimal pattern anyway, use a better pattern to fix it. 3. some changes are automatically applied by my editor (VSCode with the Go plugin) and I am fine with them. 4. while reading code, I also applied my preferred pattern wrt whitespaces, i.e.: no whitespace inside functions, if a function feels too long in this way, just break it. Closes #57 [*] Even if we want to show many measurements at a time, which does not seem needed, given the UI patterns, this functionality won't be P0. What is P0 is to bless a new beta and give to @sarathms binaries for all archs that support a basic `show`.
29 lines
734 B
Go
29 lines
734 B
Go
package nettest
|
|
|
|
import (
|
|
"github.com/alecthomas/kingpin"
|
|
"github.com/apex/log"
|
|
"github.com/ooni/probe-cli/internal/cli/root"
|
|
"github.com/ooni/probe-cli/internal/database"
|
|
"github.com/ooni/probe-cli/internal/output"
|
|
)
|
|
|
|
func init() {
|
|
cmd := root.Command("show", "Show a specific measurement")
|
|
msmtID := cmd.Arg("id", "the id of the measurement to show").Required().Int64()
|
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
|
ctx, err := root.Init()
|
|
if err != nil {
|
|
log.WithError(err).Error("failed to initialize root context")
|
|
return err
|
|
}
|
|
msmt, err := database.GetMeasurementJSON(ctx.DB, *msmtID)
|
|
if err != nil {
|
|
log.Errorf("error: %v", err)
|
|
return err
|
|
}
|
|
output.MeasurementJSON(msmt)
|
|
return nil
|
|
})
|
|
}
|