Skip to content

Commit

Permalink
[#635] fix: Parameter does not work (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta committed Aug 2, 2024
1 parent 9497902 commit a8cb619
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/dry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func dryCmd() *cobra.Command {
os.Exit(1)
}

workflow, err := dag.Load(cfg.BaseConfig, args[0], params)
workflow, err := dag.Load(cfg.BaseConfig, args[0], removeQuotes(params))
if err != nil {
initLogger.Error("Workflow load failed", "error", err, "file", args[0])
os.Exit(1)
Expand Down
10 changes: 9 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func startCmd() *cobra.Command {
os.Exit(1)
}

workflow, err := dag.Load(cfg.BaseConfig, args[0], params)
workflow, err := dag.Load(cfg.BaseConfig, args[0], removeQuotes(params))
if err != nil {
initLogger.Error("Workflow load failed", "error", err, "file", args[0])
os.Exit(1)
Expand Down Expand Up @@ -110,3 +110,11 @@ func startCmd() *cobra.Command {
cmd.Flags().BoolP("quiet", "q", false, "suppress output")
return cmd
}

// removeQuotes removes the surrounding quotes from the string.
func removeQuotes(s string) string {
if len(s) > 1 && s[0] == '"' && s[len(s)-1] == '"' {
return s[1 : len(s)-1]
}
return s
}
22 changes: 18 additions & 4 deletions internal/dag/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ func TestBuilder_BuildParams(t *testing.T) {
"2": "x",
},
},
{
name: "QuotedParams",
params: `x="1" y="2"`,
expected: map[string]string{
"x": "1",
"y": "2",
},
},
{
name: "ComplexParams",
params: "first P1=foo P2=${FOO} P3=`/bin/echo BAR` X=bar Y=${P1} Z=\"A B C\"",
Expand All @@ -173,11 +181,17 @@ func TestBuilder_BuildParams(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dg, err := unmarshalData([]byte(fmt.Sprintf(`
env:
- %s
var data string
if tt.env != "" {
data = fmt.Sprintf(`env:
- %s
params: %s
`, tt.env, tt.params)))
`, tt.env, tt.params)
} else {
data = fmt.Sprintf(`params: %s
`, tt.params)
}
dg, err := unmarshalData([]byte(data))
require.NoError(t, err)

def, err := decode(dg)
Expand Down
3 changes: 2 additions & 1 deletion internal/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func SetupTest(t *testing.T) Setup {
err := os.Setenv("HOME", tmpDir)
require.NoError(t, err)

viper.AddConfigPath(config.ConfigDir)
configDir := filepath.Join(tmpDir, "config")
viper.AddConfigPath(configDir)
viper.SetConfigType("yaml")
viper.SetConfigName("admin")

Expand Down

0 comments on commit a8cb619

Please sign in to comment.