Implement result listing from CLI
Change the schema to include ASN and Network Name in the results table
This commit is contained in:
@@ -4,13 +4,59 @@ 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("list", "List measurements")
|
||||
cmd := root.Command("list", "List results")
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
log.Info("Listing")
|
||||
ctx, err := root.Init()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to initialize root context")
|
||||
return err
|
||||
}
|
||||
doneResults, incompleteResults, err := database.ListResults(ctx.DB)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to list results")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("Results")
|
||||
for idx, result := range doneResults {
|
||||
output.ResultItem(output.ResultItemData{
|
||||
ID: result.ID,
|
||||
Index: idx,
|
||||
TotalCount: len(doneResults),
|
||||
Name: result.Name,
|
||||
StartTime: result.StartTime,
|
||||
NetworkName: result.NetworkName,
|
||||
Country: result.Country,
|
||||
ASN: result.ASN,
|
||||
Summary: result.Summary,
|
||||
Done: result.Done,
|
||||
DataUsageUp: result.DataUsageUp,
|
||||
DataUsageDown: result.DataUsageDown,
|
||||
})
|
||||
}
|
||||
log.Info("Incomplete results")
|
||||
for idx, result := range incompleteResults {
|
||||
output.ResultItem(output.ResultItemData{
|
||||
ID: result.ID,
|
||||
Index: idx,
|
||||
TotalCount: len(incompleteResults),
|
||||
Name: result.Name,
|
||||
StartTime: result.StartTime,
|
||||
NetworkName: result.NetworkName,
|
||||
Country: result.Country,
|
||||
ASN: result.ASN,
|
||||
Summary: result.Summary,
|
||||
Done: result.Done,
|
||||
DataUsageUp: result.DataUsageUp,
|
||||
DataUsageDown: result.DataUsageDown,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ var Cmd = kingpin.New("ooni", "")
|
||||
// Command is syntax sugar for defining sub-commands
|
||||
var Command = Cmd.Command
|
||||
|
||||
// Init should be called by all subcommand that care to have a ooni.OONI instance
|
||||
// Init should be called by all subcommand that care to have a ooni.Context instance
|
||||
var Init func() (*ooni.Context, error)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -40,8 +40,11 @@ func init() {
|
||||
}
|
||||
|
||||
result, err := database.CreateResult(ctx.DB, ctx.Home, database.Result{
|
||||
Name: *nettestGroup,
|
||||
StartTime: time.Now().UTC(),
|
||||
Name: *nettestGroup,
|
||||
StartTime: time.Now().UTC(),
|
||||
Country: ctx.Location.CountryCode,
|
||||
NetworkName: ctx.Location.NetworkName,
|
||||
ASN: fmt.Sprintf("%d", ctx.Location.ASN),
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("DB result error: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user