mirror of
https://github.com/muesli/service-tools.git
synced 2025-05-05 19:30:11 +08:00
Strip UnitOptions with empty value before serializing
This commit is contained in:
parent
1507309cdb
commit
c5be883f56
@ -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
12
main.go
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user