From a2a3c6a72c510151b0c1b0fb83b17a41b628ee77 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 4 Apr 2024 21:30:55 +0200 Subject: [PATCH] feat(miniooni): add --software-name and --software-version (#1544) Closes https://github.com/ooni/probe/issues/2691 --- internal/cmd/miniooni/javascript.go | 2 +- internal/cmd/miniooni/main.go | 20 ++++++++++++++++++-- internal/cmd/miniooni/main_test.go | 10 ++++++++-- internal/cmd/miniooni/session.go | 10 ++-------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/internal/cmd/miniooni/javascript.go b/internal/cmd/miniooni/javascript.go index e0cfec0514..57183be66d 100644 --- a/internal/cmd/miniooni/javascript.go +++ b/internal/cmd/miniooni/javascript.go @@ -10,7 +10,7 @@ import ( ) // registerJavaScript registers the javascript subcommand -func registerJavaScript(rootCmd *cobra.Command, globalOptions *Options) { +func registerJavaScript(rootCmd *cobra.Command, _ *Options) { subCmd := &cobra.Command{ Use: "javascript", Short: "Very experimental command to run JavaScript snippets", diff --git a/internal/cmd/miniooni/main.go b/internal/cmd/miniooni/main.go index dc3e5b7340..37d29e4e10 100644 --- a/internal/cmd/miniooni/main.go +++ b/internal/cmd/miniooni/main.go @@ -40,6 +40,8 @@ type Options struct { RepeatEvery int64 ReportFile string SnowflakeRendezvous string + SoftwareName string + SoftwareVersion string TorArgs []string TorBinary string Tunnel string @@ -133,6 +135,20 @@ func main() { "rendezvous method for --tunnel=torsf (one of: \"domain_fronting\" and \"amp\")", ) + flags.StringVar( + &globalOptions.SoftwareName, + "software-name", + "miniooni", + "Set the name of the application", + ) + + flags.StringVar( + &globalOptions.SoftwareVersion, + "software-version", + version.Version, + "Set the version of the application", + ) + flags.StringSliceVar( &globalOptions.TorArgs, "tor-args", @@ -268,7 +284,7 @@ func registerAllExperiments(rootCmd *cobra.Command, globalOptions *Options) { // nothing } - if doc := documentationForOptions(name, factory); doc != "" { + if doc := documentationForOptions(factory); doc != "" { flags.StringSliceVarP( &globalOptions.ExtraOptions, "option", @@ -376,7 +392,7 @@ func mainSingleIteration(logger model.Logger, experimentName string, currentOpti runx(ctx, sess, experimentName, annotations, extraOptions, currentOptions) } -func documentationForOptions(name string, factory *registry.Factory) string { +func documentationForOptions(factory *registry.Factory) string { var sb strings.Builder options, err := factory.Options() if err != nil || len(options) < 1 { diff --git a/internal/cmd/miniooni/main_test.go b/internal/cmd/miniooni/main_test.go index 8199c2fb25..17aade91df 100644 --- a/internal/cmd/miniooni/main_test.go +++ b/internal/cmd/miniooni/main_test.go @@ -1,12 +1,18 @@ package main -import "testing" +import ( + "testing" + + "github.com/ooni/probe-cli/v3/internal/version" +) func TestSimple(t *testing.T) { if testing.Short() { t.Skip("skip test in short mode") } MainWithConfiguration("example", &Options{ - Yes: true, + SoftwareName: "miniooni", + SoftwareVersion: version.Version, + Yes: true, }) } diff --git a/internal/cmd/miniooni/session.go b/internal/cmd/miniooni/session.go index e02fff21e9..a78517ea1f 100644 --- a/internal/cmd/miniooni/session.go +++ b/internal/cmd/miniooni/session.go @@ -12,12 +12,6 @@ import ( "github.com/ooni/probe-cli/v3/internal/legacy/kvstore2dir" "github.com/ooni/probe-cli/v3/internal/model" "github.com/ooni/probe-cli/v3/internal/runtimex" - "github.com/ooni/probe-cli/v3/internal/version" -) - -const ( - softwareName = "miniooni" - softwareVersion = version.Version ) // newSessionOrPanic creates and starts a new session or panics on failure @@ -44,8 +38,8 @@ func newSessionOrPanic(ctx context.Context, currentOptions *Options, Logger: logger, ProxyURL: proxyURL, SnowflakeRendezvous: currentOptions.SnowflakeRendezvous, - SoftwareName: softwareName, - SoftwareVersion: softwareVersion, + SoftwareName: currentOptions.SoftwareName, + SoftwareVersion: currentOptions.SoftwareVersion, TorArgs: currentOptions.TorArgs, TorBinary: currentOptions.TorBinary, TunnelDir: tunnelDir,