Skip to content

Commit

Permalink
Allow '=' in parameter values
Browse files Browse the repository at this point in the history
This lets parameter values be any string (possibly requiring quoting).
  • Loading branch information
squaremo committed Oct 15, 2019
1 parent 2a0ab67 commit f903778
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 1 addition & 5 deletions params_option.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -50,10 +49,7 @@ func (p *paramsOption) setFromFile(s string) error {
}

func (p *paramsOption) setFromCommandline(s string) error {
parts := strings.Split(s, "=")
if len(parts) != 2 {
return errors.New("input parameters are of the form name=value")
}
parts := strings.SplitN(s, "=", 2)
path := parts[0]
v := parts[1]

Expand Down
6 changes: 6 additions & 0 deletions tests/test-params-parsing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as std from '@jkcfg/std';
import * as param from '@jkcfg/std/param';

for (const name of ['foo.1', 'foo.2', 'foo.3', 'foo.4', 'foo.5', 'foo.6']) {
std.log(`${name}: ${param.String(name)}`);
}
1 change: 1 addition & 0 deletions tests/test-params-parsing.js.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jk run ./test-params-parsing.js -p foo.1=bar.1 -p "foo.2=bar.2" -p 'foo.3=bar.3' -p foo.4="bar.4" -p "foo.5=bar=5" -p 'foo.6=bar=6'
6 changes: 6 additions & 0 deletions tests/test-params-parsing.js.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
foo.1: bar.1
foo.2: bar.2
foo.3: bar.3
foo.4: bar.4
foo.5: bar=5
foo.6: bar=6

0 comments on commit f903778

Please sign in to comment.