-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_options.go
60 lines (53 loc) · 1.65 KB
/
root_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
package cmd
import (
"github.com/at0x0ft/pathru/pkg/domain"
"github.com/docker/compose/v2/cmd/compose"
"github.com/spf13/pflag"
)
type rootOptions struct {
baseService *OptionData[string]
composeOpts *rootComposeOptions
devcontainerOpts *rootDevcontainerOptions
}
func createRootOptions() *rootOptions {
return &rootOptions{
composeOpts: &rootComposeOptions{},
devcontainerOpts: &rootDevcontainerOptions{},
}
}
func (opts *rootOptions) set(f *pflag.FlagSet) {
opts.baseService = CreateStringPersistentOptionData(
f,
domain.HOST_BASE_SERVICE,
"base-service",
"b",
"base current service name",
)
opts.composeOpts.set(f)
opts.devcontainerOpts.set(f)
}
func (opts *rootOptions) parse() error {
return opts.devcontainerOpts.parse()
}
func (opts *rootOptions) getProjectOptions() *compose.ProjectOptions {
res := &compose.ProjectOptions{
Profiles: opts.composeOpts.profiles.Value(),
ProjectName: opts.composeOpts.projectName.Value(),
ConfigPaths: opts.composeOpts.configPaths.Value(),
EnvFiles: opts.composeOpts.envFiles.Value(),
ProjectDir: opts.composeOpts.projectDir.Value(),
}
if !opts.composeOpts.configPaths.IsSet() && opts.devcontainerOpts.state == DATA_IS_SET {
res.ConfigPaths = opts.devcontainerOpts.data.dockerComposeFile
}
if !opts.composeOpts.projectDir.IsSet() && opts.devcontainerOpts.state == DATA_IS_SET {
res.ProjectDir = opts.devcontainerOpts.data.localWorkspaceFolder
}
return res
}
func (opts *rootOptions) getBaseService() string {
if !opts.baseService.IsSet() && opts.devcontainerOpts.state == DATA_IS_SET {
return opts.devcontainerOpts.data.service
}
return opts.baseService.Value()
}