Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cobra.Command{ SilenceErrors: true, SilenceUsage: true, Use: "Should", Short: "check env variable contains a space delimited word", Example: ` export MAKE="data hugo exe ko" clog Should MAKE "hugo" # $?==0 if $MAKE contains the word "hugo" clog Should NUKE "folders" # $?==0 if $NUKE contains the word "folders" `, Run: func(cmd *cobra.Command, args []string) { if len(args) < 2 { cmd.Help() os.Exit(1) } if debug { slogger.UsePrettyLogger(slog.LevelDebug) } needle := args[1] haystackEnv := args[0] haystack, envExists := os.LookupEnv(haystackEnv) if envExists { words := strings.Split(haystack, " ") found := false for i := range words { if words[i] == needle { found = true } } if found { dbg := fmt.Sprintf("clog Should $%s \"%s\" - ✅ found in(%s)", haystackEnv, needle, haystack) slog.Debug(dbg) os.Exit(0) } else { dbg := fmt.Sprintf("clog Should $%s \"%s\" ❌ missing from(%s)", haystackEnv, needle, haystack) slog.Debug(dbg) os.Exit(1) } } else { dbg := fmt.Sprintf("clog Should $%s \"%s\" - ❌ missing env %s", haystackEnv, needle, haystackEnv) slog.Debug(dbg) os.Exit(2) } }, }
Command define the cobra settings for this command
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.