From 9022c2c975b91f761aa5493f35512422383d84d9 Mon Sep 17 00:00:00 2001 From: electricbubble Date: Wed, 28 Apr 2021 23:20:14 +0800 Subject: [PATCH] feat: [XCTest] add cli argument `--contains` --- README.md | 2 ++ cmd/xctest.go | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d0651e1..a646d8c 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ $ gidevice forward -l=9100 -r=9100 -u=39xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7 ```shell $ gidevice xctest com.leixipaopao.WebDriverAgentRunner.xctrunner +# Only the logs contained in the text are displayed +$ gidevice xctest com.leixipaopao.WebDriverAgentRunner.xctrunner --contains="ServerURLHere->" --contains="Running tests..." --contains="Built at" ``` #### Syslog diff --git a/cmd/xctest.go b/cmd/xctest.go index 4932e65..d0bb942 100644 --- a/cmd/xctest.go +++ b/cmd/xctest.go @@ -8,6 +8,7 @@ import ( "log" "os" "os/signal" + "strings" ) // xctestCmd represents the xctest command @@ -20,6 +21,7 @@ var xctestCmd = &cobra.Command{ } bundleID := args[0] udid, _ := cmd.Flags().GetString("udid") + contains, _ := cmd.Flags().GetStringArray("contains") d, err := internal.GetDeviceFromCommand(udid) internal.ErrorExit(err) @@ -33,7 +35,17 @@ var xctestCmd = &cobra.Command{ go func() { for s := range out { - fmt.Print(s) + // show all + if len(contains) == 0 { + fmt.Print(s) + continue + } + + for _, sub := range contains { + if strings.Contains(s, sub) { + fmt.Print(s) + } + } } done <- os.Interrupt }() @@ -48,5 +60,7 @@ var xctestCmd = &cobra.Command{ func init() { rootCmd.AddCommand(xctestCmd) + xctestCmd.Flags().StringArrayP("contains", "c", []string{}, "Only the logs contained in the text are displayed") + xctestCmd.Flags().StringP("udid", "u", "", "Device uuid") }