Strip UnitOptions with empty value before serializing

This commit is contained in:
Christian Muehlhaeuser 2018-03-13 02:50:38 +01:00
parent 1507309cdb
commit c5be883f56
No known key found for this signature in database
GPG Key ID: BA4CF857DD4117E9
2 changed files with 13 additions and 1 deletions

View File

@ -187,7 +187,7 @@ func executeCreate() error {
&unit.UnitOption{"Install", "WantedBy", createOpts.WantedBy},
}
r := unit.Serialize(u)
r := unit.Serialize(stripEmptyOptions(u))
b, err := ioutil.ReadAll(r)
if err != nil {
return fmt.Errorf("Encountered error while reading output: %v", err)

12
main.go
View File

@ -7,6 +7,7 @@ import (
"os"
"strings"
"github.com/coreos/go-systemd/unit"
"github.com/spf13/cobra"
)
@ -42,6 +43,17 @@ func (s Strings) Contains(n string) bool {
return false
}
func stripEmptyOptions(options []*unit.UnitOption) []*unit.UnitOption {
var opts []*unit.UnitOption
for _, opt := range options {
if len(opt.Value) > 0 {
opts = append(opts, opt)
}
}
return opts
}
func readString(prompt string, required bool) (string, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s: ", prompt)