Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Add --timeout flag #153

Merged
merged 1 commit into from Mar 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions distrobuilder/main.go
Expand Up @@ -61,6 +61,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
Expand All @@ -73,6 +74,7 @@ type cmdGlobal struct {
flagCleanup bool
flagCacheDir string
flagOptions []string
flagTimeout uint

definition *shared.Definition
sourceDir string
Expand Down Expand Up @@ -113,6 +115,8 @@ func main() {
"", "Cache directory"+"``")
app.PersistentFlags().StringSliceVarP(&globalCmd.flagOptions, "options", "o",
[]string{}, "Override options (list of key=value)"+"``")
app.PersistentFlags().UintVarP(&globalCmd.flagTimeout, "timeout", "t", 0,
"Timeout in seconds"+"``")

// LXC sub-commands
LXCCmd := cmdLXC{global: &globalCmd}
Expand All @@ -128,6 +132,18 @@ func main() {
buildDirCmd := cmdBuildDir{global: &globalCmd}
app.AddCommand(buildDirCmd.command())

// Timeout handler
go func() {
// No timeout set
if globalCmd.flagTimeout == 0 {
return
}

time.Sleep(time.Duration(globalCmd.flagTimeout) * time.Second)
fmt.Println("Timed out")
os.Exit(1)
}()

// Run the main command and handle errors
err := app.Execute()
if err != nil {
Expand Down