Skip to content

Commit

Permalink
Add flavor config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Aug 12, 2024
1 parent 1e2c515 commit 530aeb2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/param_commit_failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func AddCommitFailuresParam(cmd *cobra.Command) *BoolParam {
},
cobraSettings: cobraSettings{
name: "commit-failures",
shorthand: "f",
shorthand: "F",
usage: "enable committing reverts on tests failure",
persistent: true,
},
Expand Down
52 changes: 52 additions & 0 deletions src/config/param_flavor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright (c) 2024 Murex
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package config

import (
"github.com/spf13/cobra"
)

// AddFlavorParam adds flavor parameter to the provided command
func AddFlavorParam(cmd *cobra.Command) *StringParam {
param := StringParam{
s: paramSettings{
viperSettings: viperSettings{
enabled: true,
keyPath: "config.tcr",
name: "flavor",
},
cobraSettings: cobraSettings{
name: "flavor",
shorthand: "f",
usage: "indicate the flavor to be used by TCR: nice (default) or original",
persistent: true,
},
},
v: paramValueString{
value: "",
defaultValue: "nice",
},
}
param.addToCommand(cmd)
return &param
}
4 changes: 4 additions & 0 deletions src/config/tcr_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type TcrConfig struct {
PollingPeriod *DurationParam
MobTimerDuration *DurationParam
AutoPush *BoolParam
Flavor *StringParam
CommitFailures *BoolParam
VCS *StringParam
MessageSuffix *StringParam
Expand All @@ -59,6 +60,7 @@ func (c TcrConfig) reset() {
c.PollingPeriod.reset()
c.MobTimerDuration.reset()
c.AutoPush.reset()
c.Flavor.reset()
c.CommitFailures.reset()
c.VCS.reset()
c.MessageSuffix.reset()
Expand Down Expand Up @@ -200,6 +202,7 @@ func AddParameters(cmd *cobra.Command, defaultDir string) {
Config.PollingPeriod = AddPollingPeriodParam(cmd)
Config.MobTimerDuration = AddMobTimerDurationParam(cmd)
Config.AutoPush = AddAutoPushParam(cmd)
Config.Flavor = AddFlavorParam(cmd)
Config.CommitFailures = AddCommitFailuresParam(cmd)
Config.VCS = AddVCSParam(cmd)
Config.MessageSuffix = AddMessageSuffixParam(cmd)
Expand All @@ -217,6 +220,7 @@ func UpdateEngineParams(p *params.Params) {
p.Toolchain = Config.Toolchain.GetValue()
p.PollingPeriod = Config.PollingPeriod.GetValue()
p.AutoPush = Config.AutoPush.GetValue()
p.Flavor = Config.Flavor.GetValue()
p.CommitFailures = Config.CommitFailures.GetValue()
p.VCS = Config.VCS.GetValue()
p.MessageSuffix = Config.MessageSuffix.GetValue()
Expand Down
1 change: 1 addition & 0 deletions src/config/tcr_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func Test_show_tcr_config_with_default_values(t *testing.T) {
fmt.Sprintf("%v.git.commit-failures: %v", prefix, false),
fmt.Sprintf("%v.git.polling-period: %v", prefix, 2*time.Second),
fmt.Sprintf("%v.mob-timer.duration: %v", prefix, 5*time.Minute),
fmt.Sprintf("%v.tcr.flavor: %v", prefix, "nice"),
fmt.Sprintf("%v.tcr.language: %v", prefix, ""),
fmt.Sprintf("%v.tcr.toolchain: %v", prefix, ""),
fmt.Sprintf("%v.tcr.trace: %v", prefix, "none"),
Expand Down
1 change: 1 addition & 0 deletions src/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Params struct {
Toolchain string
MobTurnDuration time.Duration
AutoPush bool
Flavor string
CommitFailures bool
PollingPeriod time.Duration
Mode runmode.RunMode
Expand Down
8 changes: 8 additions & 0 deletions src/params/params_test_data_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func AParamSet(builders ...func(params *Params)) *Params {
Toolchain: "",
MobTurnDuration: 0,
AutoPush: false,
Flavor: "",
PollingPeriod: 0,
Mode: runmode.OneShot{},
VCS: "git",
Expand Down Expand Up @@ -107,6 +108,13 @@ func WithAutoPush(value bool) func(params *Params) {
}
}

// WithFlavor sets the provided value as the flavor to be used
func WithFlavor(flavor string) func(params *Params) {
return func(params *Params) {
params.Flavor = flavor
}
}

// WithCommitFailures sets commit-failures flag to the provided value
func WithCommitFailures(value bool) func(params *Params) {
return func(params *Params) {
Expand Down

0 comments on commit 530aeb2

Please sign in to comment.