Skip to content

Commit 45ccaf7

Browse files
author
Rees Dooley
authored
Add ability to leave comments in flat files (#10)
* Add ability to leave comments in flat files * just dont upload them * #9 * Add comment in multiline str test * and some more readme sections
1 parent a9fc5fa commit 45ccaf7

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,29 @@ alpha_first="sandwich
3131
hotdog"
3232
other_thing=barbeque
3333
```
34+
35+
### Multiline values
36+
Multiline values like `alpha_first` in the above are supported, but and subsequent lines in the value must be indented.
37+
38+
39+
### Comments
40+
41+
Comments in flat config files are allowed and not written to dynamo
42+
`#` within multiline values must be indented
43+
e.g.
44+
```
45+
❯ cat example.conf
46+
environment=confidynt-example
47+
#a comment
48+
other="
49+
#a thing"
50+
❯ confidynt --table=deployment write example.conf
51+
example.conf written to deployment
52+
```
53+
Results in
54+
```
55+
❯ confidynt --table=deployment read environment confidynt-example
56+
environment=confidynt-example
57+
other="
58+
#a thing"
59+
```

cli/write.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func Write(table string, path string, ds service.Dynamo, w io.Writer) {
3636
// Ignore blank lines
3737
continue
3838
}
39+
if strings.HasPrefix(line, "#") {
40+
// Ignore comments in flat files
41+
continue
42+
}
3943
if propRe.MatchString(line) {
4044
if key != "" {
4145
config[key] = value

cli/write_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ func TestWrite(t *testing.T) {
2929
conf := types.Config{}
3030
conf[key] = val
3131
conf["other_key"] = "other_val"
32+
conf["multi_key"] = "\"multi\n #linething\""
3233

3334
text := "key=val\n"
35+
text += "# a comment\n"
3436
text += "other_key=other_val\n"
37+
text += "multi_key=\"multi\n #linething\"\n"
3538
ioutil.WriteFile(path, []byte(text), 0644)
3639

3740
buf := new(bytes.Buffer)

0 commit comments

Comments
 (0)