aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2018-01-04 23:05:24 +0100
committerKamil Cholewiński <harry666t@gmail.com>2018-01-04 23:05:24 +0100
commitf9176edf260ba185e327f6b16cdb78b4d6c9d876 (patch)
tree11708bc70808024bd48022abe9418c42d9f025a7
parent1492a9d34b7a18227966be133e2fadcd0fdbd57a (diff)
downloadjudo-f9176edf260ba185e327f6b16cdb78b4d6c9d876.zip
judo-f9176edf260ba185e327f6b16cdb78b4d6c9d876.tar.gz
judo-f9176edf260ba185e327f6b16cdb78b4d6c9d876.tar.bz2
Fix some of the mess with timeout duration
-rw-r--r--job.go4
-rw-r--r--main.go13
2 files changed, 8 insertions, 9 deletions
diff --git a/job.go b/job.go
index 55310bd..b236ebc 100644
--- a/job.go
+++ b/job.go
@@ -82,14 +82,14 @@ func (script *Script) IsDirMode() bool {
// NewJob creates a new Job object.
func NewJob(
inventory *Inventory, script *Script, command *Command,
- env map[string]string, timeout uint64) (job *Job) {
+ env map[string]string, timeout time.Duration) (job *Job) {
// https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1)
return &Job{
Inventory: inventory,
Command: command,
Script: script,
- Timeout: time.Duration(timeout) * time.Second,
+ Timeout: timeout,
AddEnv: env,
signals: signals,
}
diff --git a/main.go b/main.go
index 5561615..639028e 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,6 @@ package main
import (
"fmt"
- "log"
"os"
"strconv"
"strings"
@@ -31,7 +30,7 @@ func parseArgs(args []string) (
var script *Script
var command *Command
- var timeout uint64 = 30
+ var timeout = time.Duration(30) * time.Second
env := make(map[string]string)
for _, opt := range opts {
@@ -43,12 +42,12 @@ func parseArgs(args []string) (
case "-s":
script, err = NewScript(opt.Arg())
if err != nil {
- return nil, nil, err.Error(), 111, nil
+ return nil, nil, usage, 111, nil
}
case "-c":
command = NewCommand(opt.Arg())
case "-t":
- timeout, err = strconv.ParseUint(opt.Arg(), 10, 64)
+ timeout, err = time.ParseDuration(opt.Arg())
if err != nil {
return nil, nil, usage, 111, err
}
@@ -72,7 +71,7 @@ func parseArgs(args []string) (
}
inventory := NewInventory()
- inventory.Timeout = time.Duration(timeout) * time.Second
+ inventory.Timeout = timeout
job = NewJob(inventory, script, command, env, timeout)
return job, names, "", 0, nil
@@ -113,8 +112,8 @@ func parseEnvArg(arg string, env map[string]string) error {
func main() {
job, names, msg, status, err := parseArgs(os.Args[1:])
if err != nil {
- log.Fatal(err)
- os.Exit(111)
+ fmt.Println(err)
+ status = 111
}
if msg != "" {
fmt.Println(msg)