package works

import (
	"bytes"
	"os/exec"
	"time"
)

func Uname(param ...string) (string, error) {
	//var cmdParam string
	unameCmd := exec.Command("uname")
	if len(param) != 0 {
		//for _, p := range param {
		//	cmdParam += p
		//}
		unameCmd = exec.Command("uname", param...)
	}
	var out bytes.Buffer
	unameCmd.Stdout = &out
	err := unameCmd.Run()
	if err != nil {
		return "", err
	}
	return out.String(), err
}

func Wait(param ...string) (string, error) {
	time.Sleep(10 * time.Second)
	return "worker sleep 10s", nil
}

func Echo(param ...string) (string, error) {
	var out string
	for _, v := range param {
		out += v + " "
	}
	return out, nil
}

func Works() map[string]interface{} {
	return map[string]interface{}{
		"uname": Uname,
		"wait":  Wait,
		"echo":  Echo,
	}
}
