Skip to content

Commit

Permalink
implemented PipeArgs, TODO tests
Browse files Browse the repository at this point in the history
  • Loading branch information
osteensco committed Dec 18, 2024
1 parent 05906c2 commit 2cb82bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ft/helpers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ft

import (
"bufio"
"errors"
"fmt"
"os"
"sort"
"strings"
)
Expand Down Expand Up @@ -38,3 +40,20 @@ func printMap(hashmap map[string]string) {
fmt.Println("")

}

func PipeArgs(args *[]string) error {

// read from stdin
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
// append to args
*args = append(*args, scanner.Text())
}
if err := scanner.Err(); err != nil {
return err
}

return nil

}
5 changes: 5 additions & 0 deletions ft/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ func TestVerifyInput(t *testing.T) {
}

}

func TestPipeArgs(t *testing.T) {
// TODO

}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ func main() {
return
}

// handle piped args
err = ft.PipeArgs(&os.Args)
if err != nil {
fmt.Println("Error: ", err)
return
}

// sanitize user input
inputCommand, err := ft.PassCmd(os.Args)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func TestMainFunc(t *testing.T) {
expected: fmt.Sprintf("%v\n", cdpathtest),
wantErr: false,
},

// TODO
// - add test where args are piped to ft
// - this requires mocking stdin

// {
// []string{"ft", "rn", "key", "key2"},
// "key renamed to key2",
Expand Down

0 comments on commit 2cb82bc

Please sign in to comment.