Skip to content

Commit

Permalink
feat: ✨ support reading from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
Equationzhao committed Jun 1, 2024
1 parent 36683cc commit 5eddc45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/cli/g.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"bufio"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -400,6 +401,7 @@ VIEW
--size-unit value, --block-size value size unit: bit, b, k, m, g, t, auto
--smart-group only show group if it has a different name from owner
--statistic show statistic info
--stdin read path from stdin, split by newline
--time show time
--time-style TIME_TYPE time/date format with -l,
valid TIME_TYPE are :
Expand Down Expand Up @@ -679,6 +681,21 @@ var logic = func(context *cli.Context) error {
contents.Pool = pool
}

if len(path) != 0 && context.Bool("stdin") {
scanner := bufio.NewScanner(os.Stdin)
var args []string
for scanner.Scan() {
line := scanner.Text()
if len(line) > 0 {
args = append(args, line)
}
}
if err := scanner.Err(); err != nil {
return err
}
path = args
}

for i := 0; i < len(path); i++ {
start := time.Now()

Expand Down
6 changes: 6 additions & 0 deletions internal/cli/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,12 @@ var viewFlag = []cli.Flag{
},
Category: "VIEW",
},
&cli.BoolFlag{
Name: "stdin",
Usage: "read path from stdin, split by newline",
DisableDefaultText: true,
Category: "VIEW",
},
}

func setLimit(context *cli.Context) error {
Expand Down

0 comments on commit 5eddc45

Please sign in to comment.