Skip to content

Commit

Permalink
feat(miniooni): add --software-name and --software-version (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Apr 4, 2024
1 parent 75c36e6 commit a2a3c6a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/miniooni/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions internal/cmd/miniooni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Options struct {
RepeatEvery int64
ReportFile string
SnowflakeRendezvous string
SoftwareName string
SoftwareVersion string
TorArgs []string
TorBinary string
Tunnel string
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions internal/cmd/miniooni/main_test.go
Original file line number Diff line number Diff line change
@@ -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,
})
}
10 changes: 2 additions & 8 deletions internal/cmd/miniooni/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit a2a3c6a

Please sign in to comment.