Allow to specify custom software name and version (#94)

In turn, this allows us to identify as ooniprobe-cli v3.0.0-rc.5.

Closes #41.
This commit is contained in:
Simone Basso 2019-12-29 14:07:57 +01:00 committed by GitHub
parent c4a87eaab7
commit 1e8b482c23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View File

@ -25,6 +25,13 @@ func init() {
isVerbose := Cmd.Flag("verbose", "Enable verbose log output.").Short('v').Bool() isVerbose := Cmd.Flag("verbose", "Enable verbose log output.").Short('v').Bool()
isBatch := Cmd.Flag("batch", "Enable batch command line usage.").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 { Cmd.PreAction(func(ctx *kingpin.ParseContext) error {
if *isBatch { if *isBatch {
log.SetHandler(batch.Default) log.SetHandler(batch.Default)
@ -45,7 +52,7 @@ func init() {
} }
ctx := ooni.NewContext(*configPath, homePath) ctx := ooni.NewContext(*configPath, homePath)
err = ctx.Init() err = ctx.Init(*softwareName, *softwareVersion)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,7 +19,9 @@ func newTestingContext(t *testing.T) *ooni.Context {
testingConfig := path.Join("..", "testdata", "testing-config.json") testingConfig := path.Join("..", "testdata", "testing-config.json")
shutil.Copy(testingConfig, configPath, false) shutil.Copy(testingConfig, configPath, false)
ctx := ooni.NewContext(configPath, homePath) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -12,7 +12,6 @@ import (
"github.com/ooni/probe-cli/internal/enginex" "github.com/ooni/probe-cli/internal/enginex"
"github.com/ooni/probe-cli/internal/legacy" "github.com/ooni/probe-cli/internal/legacy"
"github.com/ooni/probe-cli/utils" "github.com/ooni/probe-cli/utils"
"github.com/ooni/probe-cli/version"
engine "github.com/ooni/probe-engine" engine "github.com/ooni/probe-engine"
"github.com/pkg/errors" "github.com/pkg/errors"
"upper.io/db.v3/lib/sqlbuilder" "upper.io/db.v3/lib/sqlbuilder"
@ -48,12 +47,13 @@ func (c *Context) IsTerminated() bool {
return i != 0 return i != 0
} }
// Terminate interrupts the running context
func (c *Context) Terminate() { func (c *Context) Terminate() {
atomic.AddInt64(&c.isTerminatedAtomicInt, 1) atomic.AddInt64(&c.isTerminatedAtomicInt, 1)
} }
// Init the OONI manager // Init the OONI manager
func (c *Context) Init() error { func (c *Context) Init(softwareName, softwareVersion string) error {
var err error var err error
if err = legacy.MaybeMigrateHome(); err != nil { if err = legacy.MaybeMigrateHome(); err != nil {
@ -102,8 +102,8 @@ func (c *Context) Init() error {
sess, err := engine.NewSession(engine.SessionConfig{ sess, err := engine.NewSession(engine.SessionConfig{
KVStore: kvstore, KVStore: kvstore,
Logger: enginex.Logger, Logger: enginex.Logger,
SoftwareName: "ooniprobe-desktop", SoftwareName: softwareName,
SoftwareVersion: version.Version, SoftwareVersion: softwareVersion,
AssetsDir: utils.AssetsDir(c.Home), AssetsDir: utils.AssetsDir(c.Home),
TempDir: c.TempDir, TempDir: c.TempDir,
}) })

View File

@ -15,7 +15,9 @@ func TestInit(t *testing.T) {
defer os.RemoveAll(ooniHome) defer os.RemoveAll(ooniHome)
ctx := NewContext("", 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.Error(err)
t.Fatal("failed to init the context") t.Fatal("failed to init the context")
} }