MCPcopy
hub / github.com/google/git-appraise / FromFile

Function FromFile

commands/input/input.go:79–109  ·  view source on GitHub ↗

FromFile loads and returns the contents of a given file. If - is passed through, much like git, it will read from stdin. This can be piped data, unless there is a tty in which case the user will be prompted to enter a message.

(fileName string)

Source from the content-addressed store, hash-verified

77// unless there is a tty in which case the user will be prompted to enter a
78// message.
79func FromFile(fileName string) (string, error) {
80 if fileName == "-" {
81 stat, err := os.Stdin.Stat()
82 if err != nil {
83 return "", fmt.Errorf("Error reading from stdin: %v\n", err)
84 }
85 if (stat.Mode() & os.ModeCharDevice) == 0 {
86 // There is no tty. This will allow us to read piped data instead.
87 output, err := ioutil.ReadAll(os.Stdin)
88 if err != nil {
89 return "", fmt.Errorf("Error reading from stdin: %v\n", err)
90 }
91 return string(output), err
92 }
93
94 fmt.Printf("(reading comment from standard input)\n")
95 var output bytes.Buffer
96 s := bufio.NewScanner(os.Stdin)
97 for s.Scan() {
98 output.Write(s.Bytes())
99 output.WriteRune('\n')
100 }
101 return output.String(), nil
102 }
103
104 output, err := ioutil.ReadFile(fileName)
105 if err != nil {
106 return "", fmt.Errorf("Error reading file: %v\n", err)
107 }
108 return string(output), err
109}
110
111func startInlineCommand(command string, args ...string) (*exec.Cmd, error) {
112 cmd := exec.Command(command, args...)

Callers

nothing calls this directly

Calls 2

StringMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected