Entry is aware if its ment as a slice or not

This is needed for printing out the values, as at this part in the
code there is no access to the NodeConf and only there the information
if the Entry is ment as a slice or not is available.

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2024-02-28 12:26:21 +01:00
committed by Jonathon Anderson
parent fc80c4745c
commit 76a40f1364
3 changed files with 36 additions and 17 deletions

View File

@@ -62,6 +62,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix a rendering bug in the documentation for GRUB boot support. #1132
- Fix a locking issue with concurrent read/writes for node status. #1174
- Fix shim and grub detection for aarch64. #1145
- wwctl [profile|node] list -a handles now slices correclty. #1113
## 4.5.0, 2024-02-08

View File

@@ -140,6 +140,7 @@ type Entry struct {
altvalue []string
from string
def []string
isSlice bool
}
/*

View File

@@ -114,6 +114,7 @@ func (ent *Entry) SetSlice(val []string) {
} else if len(val) == 1 && val[0] == "" { // check also for an "empty" slice
return
}
ent.isSlice = true
if util.InSlice(GetUnsetVerbs(), val[0]) {
ent.value = []string{}
} else {
@@ -152,6 +153,7 @@ func (ent *Entry) SetAltSlice(val []string, from string) {
if len(val) == 0 {
return
}
ent.isSlice = true
ent.altvalue = append(ent.altvalue, val...)
if ent.from == "" {
ent.from = from
@@ -177,11 +179,12 @@ func (ent *Entry) SetDefaultSlice(val []string) {
if len(val) == 0 {
return
}
ent.isSlice = true
ent.def = val
}
/*
Set default etry as bool
Set default entry as bool
*/
func (ent *Entry) SetDefaultB(val bool) {
if val {
@@ -347,27 +350,41 @@ func (ent *Entry) GetIntPtr() *int {
* Misc
*
*********/
/*
Returns the value of Entry if it was defined set or
alternative is presend. Default value is in '()'. If
nothing is defined '--' is returned.
Gets the the entry of the value in following order
* node value if set
* profile value if set
* default value if set
*/
func (ent *Entry) Print() (ret string) {
if len(ent.value) != 0 || len(ent.altvalue) != 0 {
combList := append(ent.value, ent.altvalue...)
ret = strings.Join(cleanList(combList), ",")
if len(negList(combList)) > 0 {
ret += " ~{" + strings.Join(negList(combList), ",") + "}"
func (ent *Entry) Print() string {
if !ent.isSlice {
if len(ent.value) != 0 {
return ent.value[0]
}
if len(ent.altvalue) != 0 {
return ent.altvalue[0]
}
if len(ent.def) != 0 {
return "(" + ent.def[0] + ")"
}
} else {
var ret string
if len(ent.value) != 0 || len(ent.altvalue) != 0 {
combList := append(ent.value, ent.altvalue...)
ret = strings.Join(cleanList(combList), ",")
if len(negList(combList)) > 0 {
ret += " ~{" + strings.Join(negList(combList), ",") + "}"
}
}
if ret != "" {
return ret
}
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"
}
}
if ret != "" {
return ret
}
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"
}
return "--"
}