feat(winreg): squashed commits

This commit is contained in:
will 2021-11-15 21:21:41 +00:00 committed by Jan De Dobbeleer
parent e3b6dbe91e
commit 18570c9cd0
4 changed files with 42 additions and 10 deletions

View file

@ -27,7 +27,7 @@ const (
)
func (n *new) enabled() bool {
true
return true
}
func (n *new) string() string {

View file

@ -32,11 +32,17 @@ func (wr *winreg) enabled() bool {
var err error
wr.Value, err = wr.env.getWindowsRegistryKeyValue(registryPath, registryKey)
if len(fallback) > 0 && (err != nil || len(wr.Value) == 0) {
wr.Value = fallback
return true
if err != nil {
if len(fallback) > 0 {
wr.Value = fallback
return true
}
return false
}
return err == nil && len(wr.Value) > 0
return true
}
func (wr *winreg) string() string {

View file

@ -44,20 +44,20 @@ func TestRegQueryEnabled(t *testing.T) {
ExpectedValue: "cortana",
},
{
CaseDescription: "Fallback value on empty",
CaseDescription: "Empty string value (no error) should display empty string even in presence of fallback",
Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion",
Key: "InstallTime",
Output: "",
Fallback: "anaconda",
ExpectedSuccess: true,
ExpectedValue: "anaconda",
ExpectedValue: "",
},
{
CaseDescription: "Empty no fallback disabled",
CaseDescription: "Empty string value (no error) should display empty string",
Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion",
Key: "InstallTime",
Output: "",
ExpectedSuccess: false,
ExpectedSuccess: true,
ExpectedValue: "",
},
}

View file

@ -182,7 +182,7 @@
"angular",
"php",
"wifi",
"regquery"
"winreg"
]
},
"style": {
@ -1725,6 +1725,32 @@
"title": "Registry Key",
"description": "The key under he registry path to get (case insensitive). If left blank, will get the value of the (Default) key in the registry_path",
"default": ""
},
"query_fail_behaviour" : {
"type":"string",
"title": "Query failure behaviour",
"description": "What to do when the registry query fails",
"default":"hide_segment",
"enum": ["hide_segment", "display_fallback_string"]
},
"query_fail_fallback_string": {
"type": "string",
"title": "Query Failure fallback string",
"description": "In the event of a failure to get the requested key, this string will be displayed in the segment if 'query_fail_behaviour' is set to 'display_fallback_string'",
"default": ""
},
"query_fail_behaviour" : {
"type":"string",
"title": "Query failure behaviour",
"description": "What to do when the registry query fails",
"default":"hide_segment",
"enum": ["hide_segment", "display_fallback_string", "show_debug_info"]
},
"query_fail_fallback_string": {
"type": "string",
"title": "Query Failure fallback string",
"description": "In the event of a failure to get the requested key, this string will be displayed in the segment if 'query_fail_behaviour' is set to 'display_fallback_string'",
"default": ""
}
}
}