MCPcopy Create free account
hub / github.com/bracesdev/errtrace / readFile

Method readFile

cmd/errtrace/main.go:640–665  ·  view source on GitHub ↗
(r fileRequest)

Source from the content-addressed store, hash-verified

638}
639
640func (cmd *mainCmd) readFile(r fileRequest) ([]byte, error) {
641 if r.Filepath != "-" {
642 return errtrace.Wrap2(os.ReadFile(r.Filename))
643 }
644
645 if r.Write {
646 return nil, errtrace.Wrap(fmt.Errorf("can't use -w with stdin"))
647 }
648
649 if r.ImplicitStdin {
650 // Running with no args reads from stdin, but this is not obvious
651 // so print a usage hint to stderr, if we think stdin is a TTY.
652 // Best-effort check for a TTY by looking for a character device.
653 type statter interface {
654 Stat() (os.FileInfo, error)
655 }
656 if st, ok := cmd.Stdin.(statter); ok {
657 if fi, err := st.Stat(); err == nil &&
658 fi.Mode()&os.ModeCharDevice == os.ModeCharDevice {
659 cmd.log.Println("reading from stdin; use '-h' for help")
660 }
661 }
662 }
663
664 return errtrace.Wrap2(io.ReadAll(cmd.Stdin))
665}
666
667type walker struct {
668 // Inputs

Callers 1

processFileMethod · 0.95

Calls 4

Wrap2Function · 0.92
WrapFunction · 0.92
ModeMethod · 0.80
StatMethod · 0.65

Tested by

no test coverage detected