feat(libminiooni): implement --version and --limit (#247)

See https://github.com/ooni/probe/issues/1380
This commit is contained in:
Simone Basso 2021-03-08 18:31:42 +01:00 committed by GitHub
parent 0477903187
commit 4da372a84d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@ type Options struct {
HomeDir string HomeDir string
Inputs []string Inputs []string
InputFilePaths []string InputFilePaths []string
Limit int64
NoJSON bool NoJSON bool
NoCollector bool NoCollector bool
ProbeServicesURL string ProbeServicesURL string
@ -54,6 +55,7 @@ type Options struct {
TorBinary string TorBinary string
Tunnel string Tunnel string
Verbose bool Verbose bool
Version bool
Yes bool Yes bool
} }
@ -87,6 +89,10 @@ func init() {
&globalOptions.Inputs, "input", 'i', &globalOptions.Inputs, "input", 'i',
"Add test-dependent input to the test input", "INPUT", "Add test-dependent input to the test input", "INPUT",
) )
getopt.FlagLong(
&globalOptions.Limit, "limit", 0,
"Limit the number of URLs tested by Web Connectivity", "N",
)
getopt.FlagLong( getopt.FlagLong(
&globalOptions.NoJSON, "no-json", 'N', "Disable writing to disk", &globalOptions.NoJSON, "no-json", 'N', "Disable writing to disk",
) )
@ -126,6 +132,9 @@ func init() {
getopt.FlagLong( getopt.FlagLong(
&globalOptions.Verbose, "verbose", 'v', "Increase verbosity", &globalOptions.Verbose, "verbose", 'v', "Increase verbosity",
) )
getopt.FlagLong(
&globalOptions.Version, "version", 0, "Print version and exit",
)
getopt.FlagLong( getopt.FlagLong(
&globalOptions.Yes, "yes", 0, "I accept the risk of running OONI", &globalOptions.Yes, "yes", 0, "I accept the risk of running OONI",
) )
@ -149,6 +158,10 @@ func fatalIfFalse(cond bool, msg string) {
// integrate this function to either handle the panic of ignore it. // integrate this function to either handle the panic of ignore it.
func Main() { func Main() {
getopt.Parse() getopt.Parse()
if globalOptions.Version {
fmt.Printf("%s\n", version.Version)
os.Exit(0)
}
fatalIfFalse(len(getopt.Args()) == 1, "Missing experiment name") fatalIfFalse(len(getopt.Args()) == 1, "Missing experiment name")
MainWithConfiguration(getopt.Arg(0), globalOptions) MainWithConfiguration(getopt.Arg(0), globalOptions)
} }
@ -362,7 +375,7 @@ func MainWithConfiguration(experimentName string, currentOptions Options) {
SourceFiles: currentOptions.InputFilePaths, SourceFiles: currentOptions.InputFilePaths,
InputPolicy: builder.InputPolicy(), InputPolicy: builder.InputPolicy(),
Session: sess, Session: sess,
URLLimit: 17, URLLimit: currentOptions.Limit,
}) })
inputs, err := inputLoader.Load(context.Background()) inputs, err := inputLoader.Load(context.Background())
fatalOnError(err, "cannot load inputs") fatalOnError(err, "cannot load inputs")