Skip to content

Commit 1039356

Browse files
kroppbep
authored andcommitted
commands: Support human-readable YAML boolean values in undraft
1 parent ccdd08d commit 1039356

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

‎commands/undraft.go‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
var undraftCmd = &cobra.Command{
2727
Use: "undraft path/to/content",
28-
Short: "Undraft changes the content's draft status from 'True' to 'False'",
29-
Long: `Undraft changes the content's draft status from 'True' to 'False'
28+
Short: "Undraft resets the content's draft status",
29+
Long: `Undraft resets the content's draft status
3030
and updates the date to the current date and time.
3131
If the content's draft status is 'False', nothing is done.`,
3232
RunE: Undraft,
@@ -138,14 +138,12 @@ L:
138138
for _, v := range fmLines {
139139
pos := bytes.Index(v, []byte("draft"))
140140
if pos != -1 {
141-
v = bytes.Replace(v, []byte("true"), []byte("false"), 1)
142-
goto write
141+
continue
143142
}
144143
pos = bytes.Index(v, []byte("date"))
145144
if pos != -1 { // if date field wasn't found, add it
146145
v = bytes.Replace(v, []byte(date), []byte(time.Now().Format(time.RFC3339)), 1)
147146
}
148-
write:
149147
buff.Write(v)
150148
buff.Write(lineEnding)
151149
}

‎commands/undraft_test.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525
)
2626

2727
var (
28-
jsonFM = "{\n \"date\": \"12-04-06\",\n \"title\": \"test json\"\n}"
29-
jsonDraftFM = "{\n \"draft\": true,\n \"date\": \"12-04-06\",\n \"title\":\"test json\"\n}"
30-
tomlFM = "+++\n date= \"12-04-06\"\n title= \"test toml\"\n+++"
31-
tomlDraftFM = "+++\n draft= true\n date= \"12-04-06\"\n title=\"test toml\"\n+++"
32-
yamlFM = "---\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
33-
yamlDraftFM = "---\n draft: true\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
28+
jsonFM = "{\n \"date\": \"12-04-06\",\n \"title\": \"test json\"\n}"
29+
jsonDraftFM = "{\n \"draft\": true,\n \"date\": \"12-04-06\",\n \"title\":\"test json\"\n}"
30+
tomlFM = "+++\n date= \"12-04-06\"\n title= \"test toml\"\n+++"
31+
tomlDraftFM = "+++\n draft= true\n date= \"12-04-06\"\n title=\"test toml\"\n+++"
32+
yamlFM = "---\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
33+
yamlDraftFM = "---\n draft: true\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
34+
yamlYesDraftFM = "---\n draft: yes\n date: \"12-04-06\"\n title: \"test yaml\"\n---"
3435
)
3536

3637
func TestUndraftContent(t *testing.T) {
@@ -44,6 +45,7 @@ func TestUndraftContent(t *testing.T) {
4445
{tomlDraftFM, ""},
4546
{yamlFM, "not a Draft: nothing was done"},
4647
{yamlDraftFM, ""},
48+
{yamlYesDraftFM, ""},
4749
}
4850

4951
for i, test := range tests {

0 commit comments

Comments
 (0)