mirror of
https://github.com/Luzifer/ansible-role-version.git
synced 2024-12-25 03:51:21 +00:00
37 lines
894 B
Go
37 lines
894 B
Go
|
package examples
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// CheckArgs should be used to ensure the right command line arguments are
|
||
|
// passed before executing an example.
|
||
|
func CheckArgs(arg ...string) {
|
||
|
if len(os.Args) < len(arg)+1 {
|
||
|
Warning("Usage: %s %s", os.Args[0], strings.Join(arg, " "))
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// CheckIfError should be used to naively panics if an error is not nil.
|
||
|
func CheckIfError(err error) {
|
||
|
if err == nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err))
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
|
||
|
// Info should be used to describe the example commands that are about to run.
|
||
|
func Info(format string, args ...interface{}) {
|
||
|
fmt.Printf("\x1b[34;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
|
||
|
}
|
||
|
|
||
|
// Warning should be used to display a warning
|
||
|
func Warning(format string, args ...interface{}) {
|
||
|
fmt.Printf("\x1b[36;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
|
||
|
}
|