Skip to content

Commit

Permalink
fix: exit with status 1 if property isn't deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Nov 16, 2023
1 parent ac4b61e commit 139776d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.0
0.14.1
5 changes: 3 additions & 2 deletions ini.sml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ struct
end

fun stringify (ini: ini_data) : string =
let val sections = map stringifySection ini
val concat = String.concatWith "\n" sections
let
val sections = map stringifySection ini
val concat = String.concatWith "\n" sections
in
if concat = "" then "" else concat ^ "\n"
end
Expand Down
17 changes: 6 additions & 11 deletions initool.sml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ fun exitWithError (output: string) (err: string) =
OS.Process.exit (OS.Process.failure)
end

datatype result =
Output of string
| FailureOutput of string
| Error of string
datatype result = Output of string | FailureOutput of string | Error of string

fun processFileCustom quiet successFn filterFn filename =
let
Expand Down Expand Up @@ -98,7 +95,7 @@ fun helpCommand [] = Output allUsage
Error (invalidUsage ^ (formatArgs (cmd :: rest)) ^ "\n" ^ usage ^ cmd)

fun versionCommand [] =
let val version = "0.14.0"
let val version = "0.14.1"
in Output (version ^ "\n")
end
| versionCommand [_] = versionCommand []
Expand Down Expand Up @@ -207,13 +204,11 @@ fun deleteCommand (opts: Id.options) [_, filename, section] =
| deleteCommand opts [_, filename, section, key] =
(* Delete property *)
let
val q =
Ini.RemoveProperty
{ section = Id.fromStringWildcard section
, key = Id.fromStringWildcard key
}
val section = Id.fromStringWildcard section
val key = Id.fromStringWildcard key
val q = Ini.RemoveProperty {section = section, key = key}
val successFn = fn (parsed, _) =>
Ini.sectionExists opts (Id.fromStringWildcard section) parsed
Ini.propertyExists opts section key parsed
in
processFile successFn (Ini.select opts q) filename
end
Expand Down
3 changes: 2 additions & 1 deletion tests/delete-property.command
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
$INITOOL d tests/test.ini foo name2
$INITOOL d tests/test.ini foo name2 && echo deleted || echo unchanged
$INITOOL d tests/test.ini foo name5 && echo deleted || echo unchanged
15 changes: 15 additions & 0 deletions tests/delete-property.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ name2="repeat value"
name1=baz1
name2=baz2
name3=baz3
deleted
[foo]
name1=foo1
name2=foo2
name3="repeat value"

[bar]
name1=bar1
name2="repeat value"

[baz]
name1=baz1
name2=baz2
name3=baz3
unchanged

0 comments on commit 139776d

Please sign in to comment.