-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplan-options.go
79 lines (66 loc) · 1.6 KB
/
plan-options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package nixpacks
import (
"errors"
)
type PlanOptions struct {
Path string
//Command to install language dependencies.
InstallCommand string
//Command to build the image,
//it will overwrite the default build command
BuildCommand string
//Command to run when starting the container
StartCommand string
//Additional nix packages to install in the environment
NixPackages []string
//Additional apt packages to install in the environment
AptPackages []string
//Additional nix libraries to install in the environment
NixLibraries []string
//Environment variables to set in the container
Envs []Env
//Path to config file
Config string
}
func (p PlanOptions) Validate() error {
if p.Path == "" {
return errors.New("path is required")
}
return nil
}
func (o PlanOptions) ToArgs() []string {
var args []string
if o.InstallCommand != "" {
args = append(args, "--install-cmd", o.InstallCommand)
}
if o.BuildCommand != "" {
args = append(args, "--build-cmd", o.BuildCommand)
}
if o.StartCommand != "" {
args = append(args, "--start-cmd", o.StartCommand)
}
if len(o.NixPackages) != 0 {
for _, pkg := range o.NixPackages {
args = append(args, "--pkgs", pkg)
}
}
if len(o.AptPackages) != 0 {
for _, pkg := range o.AptPackages {
args = append(args, "--apt", pkg)
}
}
if len(o.NixLibraries) != 0 {
for _, lib := range o.NixLibraries {
args = append(args, "--libs", lib)
}
}
if len(o.Envs) != 0 {
for _, env := range o.Envs {
args = append(args, "--env", env.Key+"="+env.Value)
}
}
if o.Config != "" {
args = append(args, "--config", o.Config)
}
return args
}