-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse system property switches correctly
- Loading branch information
Showing
12 changed files
with
59 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
js7-base/shared/src/main/scala/js7/base/log/LoggingEscapeCodes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
js7-base/shared/src/main/scala/js7/base/utils/SystemPropertiesExtensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package js7.base.utils | ||
|
||
import js7.base.convert.As.StringAsBoolean | ||
import scala.sys.SystemProperties | ||
|
||
object SystemPropertiesExtensions: | ||
|
||
extension (properties: SystemProperties) | ||
def asSwitch(key: String): Boolean = | ||
properties.get(key) match | ||
case None => false | ||
case Some("") => true | ||
case Some(string) => StringAsBoolean(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
js7-base/shared/src/test/scala/js7/base/utils/SystemPropertiesExtensionsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package js7.base.utils | ||
|
||
import js7.base.test.OurTestSuite | ||
import js7.base.utils.SystemPropertiesExtensions.asSwitch | ||
|
||
final class SystemPropertiesExtensionsTest extends OurTestSuite: | ||
|
||
"asSwitch" in: | ||
assert(sys.props.asSwitch("js7.SystemPropertiesExtensionsTest.undefined") == false) | ||
|
||
Seq( | ||
"" -> true, | ||
"false" -> false, | ||
"off" -> false, | ||
"no" -> false, | ||
"true" -> true, | ||
"on" -> true, | ||
"yes" -> true | ||
).foreach: (string, bool) => | ||
val key = "js7.SystemPropertiesExtensionsTest" | ||
sys.props.put(key, string) | ||
assert(sys.props.asSwitch(key) == bool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters