Add -p parameter to give custom project name

This commit is contained in:
Alexis ANNEIX 2024-02-01 16:44:14 +01:00
parent 52e629b69a
commit 57d30172be
No known key found for this signature in database
GPG key ID: 0B5144893F6F50AD
2 changed files with 9 additions and 4 deletions

View file

@ -26,8 +26,9 @@ var (
date string
buildSource = "unknown"
configFlag = false
debuggingFlag = false
configFlag = false
debuggingFlag = false
projectName string = ""
composeFiles []string
)
@ -51,6 +52,7 @@ func main() {
flaggy.Bool(&configFlag, "c", "config", "Print the current default config")
flaggy.Bool(&debuggingFlag, "d", "debug", "a boolean")
flaggy.StringSlice(&composeFiles, "f", "file", "Specify alternate compose files")
flaggy.String(&projectName, "p", "project", "Specify a custom project name")
flaggy.SetVersion(info)
flaggy.Parse()
@ -71,7 +73,7 @@ func main() {
log.Fatal(err.Error())
}
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir)
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir, projectName)
if err != nil {
log.Fatal(err.Error())
}

View file

@ -487,7 +487,7 @@ type AppConfig struct {
}
// NewAppConfig makes a new app config
func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag bool, composeFiles []string, projectDir string) (*AppConfig, error) {
func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag bool, composeFiles []string, projectDir string, projectName string) (*AppConfig, error) {
configDir, err := findOrCreateConfigDir(name)
if err != nil {
return nil, err
@ -502,6 +502,9 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
if len(composeFiles) > 0 {
userConfig.CommandTemplates.DockerCompose += " -f " + strings.Join(composeFiles, " -f ")
}
if len(projectName) > 0 {
userConfig.CommandTemplates.DockerCompose += " -p " + projectName
}
appConfig := &AppConfig{
Name: name,