From 2511587506adcd020497c3a25d951cd4972469ca Mon Sep 17 00:00:00 2001 From: corporateuser <87529059+corporateuser@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:48:26 +0200 Subject: [PATCH 1/4] fix: add timeout to waiting for URL from stdin --- commands/deploy_command.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/commands/deploy_command.go b/commands/deploy_command.go index 8c947e8..e1e0135 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -43,6 +43,7 @@ const ( strategyOpt = "strategy" skipTestingPhase = "skip-testing-phase" skipIdleStart = "skip-idle-start" + readStringTimeout = 30 * time.Second ) type listFlag struct { @@ -496,6 +497,16 @@ func (c *DeployCommand) getMtaArchive(parsedArguments []string, mtaElementsCalcu return buildMtaArchiveFromDirectory(mtaArgument, mtaElementsCalculator) } +func getInput(input chan string, fileReader fs.File) { + in := bufio.NewReader(fileReader) + result, err := in.ReadString('\n') + if err != nil { + log.Tracef("could not read from stdin: %v\n", err) + } + + input <- result +} + func (c *DeployCommand) tryReadingFileUrl() string { stat, err := c.FileUrlReader.Stat() if err != nil { @@ -503,9 +514,15 @@ func (c *DeployCommand) tryReadingFileUrl() string { } if stat.Mode()&fs.ModeCharDevice == 0 { - in := bufio.NewReader(c.FileUrlReader) - input, _ := in.ReadString('\n') - return strings.TrimSpace(input) + input := make(chan string, 1) + go getInput(input) + select { + case i := <-input: + return strings.TrimSpace(i) + case <- time.After(readStringTimeout): + log.Tracef("the timeout period elapsed prios to receiving input from stdin") + return "" + } } return "" } From 131933ab45a645fa55a665e602812e499f7fd224 Mon Sep 17 00:00:00 2001 From: Dmitrii Trukhanov Date: Tue, 18 Jun 2024 13:53:14 +0200 Subject: [PATCH 2/4] fix: missing argument --- commands/deploy_command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/deploy_command.go b/commands/deploy_command.go index e1e0135..ecbd670 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -515,7 +515,7 @@ func (c *DeployCommand) tryReadingFileUrl() string { if stat.Mode()&fs.ModeCharDevice == 0 { input := make(chan string, 1) - go getInput(input) + go getInput(input, c.FileUrlReader) select { case i := <-input: return strings.TrimSpace(i) From 15abcf7732a00923b0ac4b4b60e5d678da6771a4 Mon Sep 17 00:00:00 2001 From: Dmitrii Trukhanov Date: Wed, 19 Jun 2024 10:58:25 +0200 Subject: [PATCH 3/4] chore: typo --- commands/deploy_command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/deploy_command.go b/commands/deploy_command.go index ecbd670..b550a78 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -520,7 +520,7 @@ func (c *DeployCommand) tryReadingFileUrl() string { case i := <-input: return strings.TrimSpace(i) case <- time.After(readStringTimeout): - log.Tracef("the timeout period elapsed prios to receiving input from stdin") + log.Tracef("the timeout period elapsed prior to receiving input from stdin") return "" } } From 4bc070d8e2e1a774e0767255b0a2c3ec51857777 Mon Sep 17 00:00:00 2001 From: Dmitrii Trukhanov Date: Wed, 19 Jun 2024 11:14:07 +0200 Subject: [PATCH 4/4] chore: add output --- commands/deploy_command.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/deploy_command.go b/commands/deploy_command.go index b550a78..b149082 100644 --- a/commands/deploy_command.go +++ b/commands/deploy_command.go @@ -514,13 +514,15 @@ func (c *DeployCommand) tryReadingFileUrl() string { } if stat.Mode()&fs.ModeCharDevice == 0 { + // Print flow clarifying message + ui.Say("Trying to get MTA archive URL from STDIN") input := make(chan string, 1) go getInput(input, c.FileUrlReader) select { case i := <-input: return strings.TrimSpace(i) - case <- time.After(readStringTimeout): - log.Tracef("the timeout period elapsed prior to receiving input from stdin") + case <-time.After(readStringTimeout): + ui.Say(terminal.FailureColor("The timeout period elapsed prior to receiving input from stdin")) return "" } }