Skip to content

Commit

Permalink
get the keyword from args
Browse files Browse the repository at this point in the history
  • Loading branch information
Arieltk1 committed Dec 31, 2020
1 parent b18095e commit c9b91ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}",
"args": ["searchKeyword", "tillsongalloway.com"]
}
]
}
12 changes: 11 additions & 1 deletion cmd/root.go
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/spf13/viper"
"golang.org/x/crypto/ssh/terminal"

"strings"

"github.com/spf13/cobra"
"github.com/tillson/git-hound/internal/app"
)
Expand Down Expand Up @@ -55,7 +57,7 @@ var rootCmd = &cobra.Command{
}
} else {
if !terminal.IsTerminal(0) {
scanner := bufio.NewScanner(os.Stdin)
scanner := getScanner(args)
for scanner.Scan() {
bytes := scanner.Bytes()
str := string(bytes)
Expand Down Expand Up @@ -102,6 +104,14 @@ var rootCmd = &cobra.Command{
},
}

func getScanner(args []string) *bufio.Scanner {
if args[0] == "searchKeyword" {
return bufio.NewScanner(strings.NewReader(args[1]))
} else {
return bufio.NewScanner(os.Stdin)
}
}

// Execute command
func Execute() {
InitializeFlags()
Expand Down

0 comments on commit c9b91ba

Please sign in to comment.