ooni-probe-cli/internal/cli/run/run.go

95 lines
2.7 KiB
Go
Raw Normal View History

package run
import (
"github.com/alecthomas/kingpin"
2018-02-12 16:45:13 +01:00
"github.com/apex/log"
2018-06-29 16:50:05 +02:00
"github.com/fatih/color"
"github.com/ooni/probe-cli/internal/cli/onboard"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/nettests"
2020-11-13 18:42:10 +01:00
"github.com/ooni/probe-cli/internal/ooni"
)
func init() {
cmd := root.Command("run", "Run a test group or OONI Run link")
var nettestGroupNamesBlue []string
var probe *ooni.Probe
2019-10-02 18:23:14 +02:00
2019-12-02 17:05:02 +01:00
for name := range nettests.NettestGroups {
nettestGroupNamesBlue = append(nettestGroupNamesBlue, color.BlueString(name))
2018-06-22 14:55:00 +02:00
}
noCollector := cmd.Flag("no-collector", "Disable uploading measurements to a collector").Bool()
cmd.Action(func(_ *kingpin.ParseContext) error {
2019-10-02 18:23:14 +02:00
var err error
probe, err = root.Init()
2018-02-12 16:45:13 +01:00
if err != nil {
log.Errorf("%s", err)
return err
}
if err = onboard.MaybeOnboarding(probe); err != nil {
log.WithError(err).Error("failed to perform onboarding")
return err
}
if *noCollector == true {
probe.Config().Sharing.UploadResults = false
}
2019-10-02 18:23:14 +02:00
return nil
})
2018-02-13 17:11:22 +01:00
2019-10-02 18:23:14 +02:00
websitesCmd := cmd.Command("websites", "")
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
2019-10-02 18:23:14 +02:00
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "websites",
Probe: probe,
InputFiles: *inputFile,
Inputs: *input,
})
2019-10-02 18:23:14 +02:00
})
imCmd := cmd.Command("im", "")
imCmd.Action(func(_ *kingpin.ParseContext) error {
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "im",
Probe: probe,
})
2019-10-02 18:23:14 +02:00
})
performanceCmd := cmd.Command("performance", "")
performanceCmd.Action(func(_ *kingpin.ParseContext) error {
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "performance",
Probe: probe,
})
2019-10-02 18:23:14 +02:00
})
middleboxCmd := cmd.Command("middlebox", "")
middleboxCmd.Action(func(_ *kingpin.ParseContext) error {
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "middlebox",
Probe: probe,
})
2019-10-02 18:23:14 +02:00
})
circumventionCmd := cmd.Command("circumvention", "")
circumventionCmd.Action(func(_ *kingpin.ParseContext) error {
return nettests.RunGroup(nettests.RunGroupConfig{
GroupName: "circumvention",
Probe: probe,
})
})
2019-10-02 18:23:14 +02:00
allCmd := cmd.Command("all", "").Default()
allCmd.Action(func(_ *kingpin.ParseContext) error {
log.Infof("Running %s tests", color.BlueString("all"))
2019-12-02 17:05:02 +01:00
for tg := range nettests.NettestGroups {
group := nettests.RunGroupConfig{GroupName: tg, Probe: probe}
if err := nettests.RunGroup(group); err != nil {
2019-10-02 18:23:14 +02:00
log.WithError(err).Errorf("failed to run %s", tg)
2018-03-08 13:46:21 +01:00
}
2018-02-13 17:11:22 +01:00
}
2019-10-02 18:23:14 +02:00
return nil
})
}