MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / fileListRun

Function fileListRun

cmd/wsh/cmd/wshcmd-file.go:494–535  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

492}
493
494func fileListRun(cmd *cobra.Command, args []string) error {
495 longForm, _ := cmd.Flags().GetBool("long")
496 onePerLine, _ := cmd.Flags().GetBool("one")
497
498 // Check if we're in a pipe
499 stat, _ := os.Stdout.Stat()
500 isPipe := (stat.Mode() & os.ModeCharDevice) == 0
501 if isPipe {
502 onePerLine = true
503 }
504
505 if len(args) == 0 {
506 args = []string{"."}
507 }
508
509 path, err := fixRelativePaths(args[0])
510 if err != nil {
511 return err
512 }
513
514 filesChan := wshclient.FileListStreamCommand(RpcClient, wshrpc.FileListData{Path: path, Opts: &wshrpc.FileListOpts{All: false}}, &wshrpc.RpcOpts{Timeout: 2000})
515 // Drain the channel when done
516 defer utilfn.DrainChannelSafe(filesChan, "fileListRun")
517 if longForm {
518 return filePrintLong(filesChan)
519 }
520
521 if onePerLine {
522 for respUnion := range filesChan {
523 if respUnion.Error != nil {
524 log.Printf("error: %v", respUnion.Error)
525 return respUnion.Error
526 }
527 for _, f := range respUnion.Response.FileInfo {
528 fmt.Fprintln(os.Stdout, f.Name)
529 }
530 }
531 return nil
532 }
533
534 return filePrintColumns(filesChan)
535}

Callers

nothing calls this directly

Calls 8

FileListStreamCommandFunction · 0.92
DrainChannelSafeFunction · 0.92
fixRelativePathsFunction · 0.85
filePrintLongFunction · 0.85
filePrintColumnsFunction · 0.85
GetBoolMethod · 0.80
StatMethod · 0.80
ModeMethod · 0.80

Tested by

no test coverage detected