s6-netdev/execline.go

42 lines
828 B
Go

package s6netdev
import (
"fmt"
"strings"
)
const (
NETDEV_EXECLINE_HEADER = "#!/bin/execlineb -P"
)
func ExeclineDefine(param, value string) string {
return fmt.Sprintf("define %s %s", param, value)
}
func ExeclineExport(param, value string) string {
return fmt.Sprintf("export %s %s", param, value)
}
func ExeclineXDGEnvdirConfig(name S6SvcName) string {
return fmt.Sprintf("s6-envdir -I ${XDG_CONFIG_HOME}/env/%s", name.Sanitize())
}
func ExeclineImportas(name string, strict bool, def string) string {
var s = []string{
"importas",
}
if strict {
s = append(s, "-i")
}
if def != "" {
s = append(s, "-D", def)
}
// Always assume we import to same name
s = append(s, name, name)
return strings.Join(s, " ")
}
func ExeclineXDGConfig() string {
return ExeclineImportas("XDG_CONFIG_HOME", true, "")
}