-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.go
40 lines (34 loc) · 820 Bytes
/
command.go
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
package main
import (
"strings"
)
const (
LIST_FILES_COMMAND = "list"
GET_FILE_COMMAND = "get"
HELP_COMMAND = "help"
EXIT_COMMAND = "exit"
)
type Command interface {
Do() string
isExitCommand() bool
}
func makeCommand(input string, config *Config) Command {
normalizedInput := strings.TrimSpace(input)
inputParts := strings.Split(normalizedInput, " ")
switch inputParts[0] {
case HELP_COMMAND:
return NewHelpCommand(DEFAULT_HELP_TEXT)
case LIST_FILES_COMMAND:
return NewListFilesCommand(config)
case GET_FILE_COMMAND:
if len(inputParts) > 1 {
return NewGetFileCommand(strings.TrimSpace(inputParts[1]), config)
} else {
return NewHelpCommand(NO_FILE_ARGUMENT_MESSAGE)
}
case EXIT_COMMAND:
return NewExitCommand()
default:
return NewUnknowCommand(inputParts[0])
}
}