Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify custom software name and version #94

Merged
merged 2 commits into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/cli/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func init() {
isVerbose := Cmd.Flag("verbose", "Enable verbose log output.").Short('v').Bool()
isBatch := Cmd.Flag("batch", "Enable batch command line usage.").Bool()

softwareName := Cmd.Flag(
"software-name", "Override application name",
).Default("ooniprobe-cli").String()
softwareVersion := Cmd.Flag(
"software-version", "Override the application version",
).Default(version.Version).String()

Cmd.PreAction(func(ctx *kingpin.ParseContext) error {
if *isBatch {
log.SetHandler(batch.Default)
Expand All @@ -45,7 +52,7 @@ func init() {
}

ctx := ooni.NewContext(*configPath, homePath)
err = ctx.Init()
err = ctx.Init(*softwareName, *softwareVersion)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion nettests/nettests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func newTestingContext(t *testing.T) *ooni.Context {
testingConfig := path.Join("..", "testdata", "testing-config.json")
shutil.Copy(testingConfig, configPath, false)
ctx := ooni.NewContext(configPath, homePath)
err = ctx.Init()
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
err = ctx.Init(swName, swVersion)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions ooni.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ooni/probe-cli/internal/enginex"
"github.com/ooni/probe-cli/internal/legacy"
"github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-cli/version"
engine "github.com/ooni/probe-engine"
"github.com/pkg/errors"
"upper.io/db.v3/lib/sqlbuilder"
Expand Down Expand Up @@ -48,12 +47,13 @@ func (c *Context) IsTerminated() bool {
return i != 0
}

// Terminate interrupts the running context
func (c *Context) Terminate() {
atomic.AddInt64(&c.isTerminatedAtomicInt, 1)
}

// Init the OONI manager
func (c *Context) Init() error {
func (c *Context) Init(softwareName, softwareVersion string) error {
var err error

if err = legacy.MaybeMigrateHome(); err != nil {
Expand Down Expand Up @@ -102,8 +102,8 @@ func (c *Context) Init() error {
sess, err := engine.NewSession(engine.SessionConfig{
KVStore: kvstore,
Logger: enginex.Logger,
SoftwareName: "ooniprobe-desktop",
SoftwareVersion: version.Version,
SoftwareName: softwareName,
SoftwareVersion: softwareVersion,
AssetsDir: utils.AssetsDir(c.Home),
TempDir: c.TempDir,
})
Expand Down
4 changes: 3 additions & 1 deletion ooni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ func TestInit(t *testing.T) {
defer os.RemoveAll(ooniHome)

ctx := NewContext("", ooniHome)
if err := ctx.Init(); err != nil {
swName := "ooniprobe-cli-tests"
swVersion := "3.0.0-alpha"
if err := ctx.Init(swName, swVersion); err != nil {
t.Error(err)
t.Fatal("failed to init the context")
}
Expand Down