-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (49 loc) · 1.24 KB
/
Copy pathmain.go
File metadata and controls
61 lines (49 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"os"
"shell/internal/command"
"shell/internal/parser"
"shell/internal/prompt"
)
func main() {
executor := command.NewExecutor()
reader := prompt.NewReader()
for {
input, err := reader.ReadLine()
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
cmd, arguments := parser.ParseInput(input)
if cmd == "" {
continue
}
args, outputPath, createOutput, errorPath, createError := parser.ProcessArgs(arguments)
var outputFile *os.File
var outputFileError error
var errorFile *os.File
var errorFileError error
if outputPath != "" {
if createOutput {
outputFile, outputFileError = os.Create(outputPath)
} else {
outputFile, outputFileError = os.OpenFile(outputPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
}
if outputFileError != nil {
fmt.Println("File does not exists or cannot be created")
}
}
if errorPath != "" {
if createError {
errorFile, errorFileError = os.Create(errorPath)
} else {
errorFile, errorFileError = os.OpenFile(errorPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
}
if errorFileError != nil {
fmt.Println("File does not exists or cannot be created")
}
}
executor.Execute(cmd, args, outputFile, errorFile)
}
}