Skip to content

Commit

Permalink
use either Command (if not empty), or Entrypoint, not both
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-gierakowski committed Nov 11, 2023
1 parent b2b59c2 commit 33eef85
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 37 deletions.
12 changes: 3 additions & 9 deletions src/loader/merger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
)

func getBaseProcess() *types.ProcessConfig {
command := "command"

return &types.ProcessConfig{
Name: "proc1",
Disabled: false,
IsDaemon: false,
Command: &command,
Command: "command",
LogLocation: "",
Environment: types.Environment{
"k1=v1",
Expand Down Expand Up @@ -59,13 +57,11 @@ func getBaseProcess() *types.ProcessConfig {
}

func getOverrideProcess() *types.ProcessConfig {
command := "override command"

return &types.ProcessConfig{
Name: "proc1",
Disabled: false,
IsDaemon: false,
Command: &command,
Command: "override command",
LogLocation: "",
Environment: types.Environment{
"k0=v0",
Expand Down Expand Up @@ -124,13 +120,11 @@ func getOverrideProcess() *types.ProcessConfig {
}

func getMergedProcess() *types.ProcessConfig {
command := "override command"

return &types.ProcessConfig{
Name: "proc1",
Disabled: false,
IsDaemon: false,
Command: &command,
Command: "override command",
LogLocation: "",
Environment: types.Environment{
"k0=v0",
Expand Down
6 changes: 2 additions & 4 deletions src/tui/proc-info-form.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ func (pv *pcView) createProcInfoForm(info *types.ProcessConfig, ports *types.Pro
f.SetFieldTextColor(tcell.ColorBlack)
f.SetButtonsAlign(tview.AlignCenter)
f.SetTitle("Process " + info.Name + " Info")
addStringIfNotEmpty("Entrypoint:", strings.Join(*info.Entrypoint, " "), f)
if info.Command != nil {
addStringIfNotEmpty("Command:", *info.Command, f)
}
addStringIfNotEmpty("Entrypoint:", strings.Join(info.Entrypoint, " "), f)
addStringIfNotEmpty("Command:", info.Command, f)
addStringIfNotEmpty("Working Directory:", info.WorkingDir, f)
addStringIfNotEmpty("Log Location:", info.LogLocation, f)
addDropDownIfNotEmpty("Environment:", info.Environment, f)
Expand Down
4 changes: 2 additions & 2 deletions src/types/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type ProcessConfig struct {
Name string
Disabled bool `yaml:"disabled,omitempty"`
IsDaemon bool `yaml:"is_daemon,omitempty"`
Command *string `yaml:"command,omitempty"`
Entrypoint *[]string `yaml:"entrypoint,omitempty"`
Command string `yaml:"command"`
Entrypoint []string `yaml:"entrypoint"`
LogLocation string `yaml:"log_location,omitempty"`
LoggerConfig *LoggerConfig `yaml:"log_configuration,omitempty"`
Environment Environment `yaml:"environment,omitempty"`
Expand Down
38 changes: 16 additions & 22 deletions src/types/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,28 @@ func (p *Project) assignDefaultProcessValues() {

func (p *Project) validateProcessCommand() {
for name, proc := range p.Processes {
if proc.Entrypoint == nil {
if proc.Command == nil {
message := fmt.Sprintf("Error: Neither command nor entrypoint is set for process: %s", name)
command := proc.Command
entrypoint := proc.Entrypoint

if command != "" {
if len(entrypoint) > 0 {
message := fmt.Sprintf("Both command and entrypoint are set! Using command and ignoring entrypoint (procces: %s)", name)
fmt.Println(message)
log.Fatal().Msg(message)
log.Error().Msg(message)
}
proc.Entrypoint = &[]string{
p.ShellConfig.ShellCommand,

proc.Executable = p.ShellConfig.ShellCommand;
proc.Args = []string{
p.ShellConfig.ShellArgument,
command,
}
} else {
if len(*proc.Entrypoint) == 0 && (proc.Command == nil || *proc.Command == "") {
message := fmt.Sprintf("If entrypoint is empty, command needs to be non-empty (procces: %s)", name)
fmt.Println(message)
log.Fatal().Msg(message)
}
}

if len(*proc.Entrypoint) == 0 {
proc.Executable = *proc.Command
proc.Args = []string{}
} else {
entrypoint := *proc.Entrypoint
} else if len(entrypoint) > 0 {
proc.Executable = entrypoint[0]
proc.Args = entrypoint[1:]
if proc.Command != nil {
proc.Args = append(proc.Args, *proc.Command)
}
} else {
message := fmt.Sprintf("Either command or entrypoint need to be non-empty (procces: %s)", name)
fmt.Println(message)
log.Fatal().Msg(message)
}

p.Processes[name] = proc
Expand Down

0 comments on commit 33eef85

Please sign in to comment.