forked from RoganDawes/P4wnP1_aloa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Send/wait for TriggerAction group
- Loading branch information
Showing
7 changed files
with
590 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cli_client | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"os" | ||
) | ||
|
||
|
||
|
||
const ( | ||
templateFlagTriggerGroupName = "group-name" | ||
templateFlagTriggerGroupValue = "group-value" | ||
) | ||
|
||
var ( | ||
// deploy | ||
tmpTriggerGroupName = "" | ||
tmpTriggerGroupValue = int32(0) | ||
) | ||
|
||
func TriggerCheckFlags(cmd *cobra.Command) { | ||
valDefined,nameDefined := false,false | ||
cmd.Flags().Visit(func(flag *pflag.Flag) { | ||
if flag.Name == templateFlagTriggerGroupName { | ||
nameDefined = true | ||
} | ||
if flag.Name == templateFlagTriggerGroupValue { | ||
valDefined = true | ||
} | ||
}) | ||
|
||
check := true | ||
if !nameDefined { | ||
fmt.Printf("The '%s' flag has to be set\n", templateFlagTriggerGroupName) | ||
check = false | ||
} | ||
if !valDefined { | ||
fmt.Printf("The '%s' flag has to be set\n", templateFlagTriggerGroupValue) | ||
check = false | ||
} | ||
|
||
if !check { | ||
os.Exit(-1) | ||
} | ||
} | ||
|
||
func init() { | ||
cmdTrigger := &cobra.Command{ | ||
Use: "trigger", | ||
Short: "Fire a group send action or wait for a group receive trigger", | ||
} | ||
|
||
cmdTriggerSend := &cobra.Command{ | ||
Use: "send", | ||
Short: "Fire a group send action", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
TriggerCheckFlags(cmd) | ||
fmt.Printf("Sending value %d to group '%s'...", tmpTriggerGroupValue, tmpTriggerGroupName) | ||
err := ClientTriggerGroupSend(StrRemoteHost,StrRemotePort,tmpTriggerGroupName,tmpTriggerGroupValue) | ||
if err != nil { | ||
fmt.Println("error: ", err) | ||
os.Exit(-1) | ||
} | ||
fmt.Println("success") | ||
}, | ||
|
||
} | ||
|
||
cmdTriggerWait := &cobra.Command{ | ||
Use: "wait", | ||
Short: "wait for a group receive trigger", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
TriggerCheckFlags(cmd) | ||
fmt.Printf("Waiting for value %d on group '%s'...", tmpTriggerGroupValue, tmpTriggerGroupName) | ||
err := ClientTriggerGroupWait(StrRemoteHost,StrRemotePort,tmpTriggerGroupName,tmpTriggerGroupValue) | ||
if err != nil { | ||
fmt.Println("error: ", err) | ||
os.Exit(-1) | ||
} | ||
fmt.Println("received") | ||
}, | ||
} | ||
|
||
|
||
|
||
rootCmd.AddCommand(cmdTrigger) | ||
cmdTrigger.AddCommand(cmdTriggerSend, cmdTriggerWait) | ||
|
||
cmdTriggerSend.Flags().StringVarP(&tmpTriggerGroupName, templateFlagTriggerGroupName, "n", "","Name of the group to send to") | ||
cmdTriggerSend.Flags().Int32VarP(&tmpTriggerGroupValue, templateFlagTriggerGroupValue, "v", 0,"The value to send") | ||
|
||
cmdTriggerWait.Flags().StringVarP(&tmpTriggerGroupName, templateFlagTriggerGroupName, "n", "","Name of the group to listen") | ||
cmdTriggerWait.Flags().Int32VarP(&tmpTriggerGroupValue, templateFlagTriggerGroupValue, "v", 0,"The value to wait for") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.