-
Notifications
You must be signed in to change notification settings - Fork 4
/
exec.go
39 lines (33 loc) · 842 Bytes
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cmd
import (
"github.com/spf13/cobra"
)
var (
execCmdPrintFlag = false
execCmdConfirmFlag = false
)
var execCmd = &cobra.Command{
Use: "exec",
Short: "Execute a snippet directly from the terminal",
Long: `Execute a snippet directly from the terminal. The output of the commands will be visibile in the terminal.`,
Run: func(cmd *cobra.Command, args []string) {
app := getAppFromContext(cmd.Context())
app.LookupAndExecuteSnippet(execCmdConfirmFlag, execCmdPrintFlag)
},
}
func init() {
execCmd.PersistentFlags().BoolVarP(
&execCmdPrintFlag,
"print",
"p",
false,
"print the command before execution on stdout",
)
execCmd.PersistentFlags().BoolVar(
&execCmdConfirmFlag,
"confirm",
false,
"the command is printed on stdout before execution for confirmation",
)
rootCmd.AddCommand(execCmd)
}