From c9725bd926c2b27ddf45035272364f46d417afbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Fri, 20 Oct 2017 18:24:07 +0300 Subject: [PATCH] Use thisCommand instead of commands[0] & Change get command's error reporting --- server/server/parser.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/server/parser.go b/server/server/parser.go index 4454977..dc0df27 100644 --- a/server/server/parser.go +++ b/server/server/parser.go @@ -24,35 +24,37 @@ func ProcessInput(c net.Conn, text string) error { return nil } - switch commands[0] { + thisCommand := commands[0] + + switch thisCommand { case "get": // Check arguments err := checkArgumentsLength(commandsLen, 2) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } // Get the file _, err = SendFile(c, commands[1]) if err != nil { - return &InputError{"SendFile", err} + return &InputError{thisCommand, err} } case "ls": // Check arguments err := checkArgumentsLength(commandsLen, 1) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } err = ListFiles(c) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } case "clear": // Check arguments err := checkArgumentsLength(commandsLen, 1) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } // Ansi clear: 1b 5b 48 1b 5b 4a @@ -64,22 +66,22 @@ func ProcessInput(c net.Conn, text string) error { // Check arguments err := checkArgumentsLength(commandsLen, 1) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } err = ShowHelp(c) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } case "exit": err := checkArgumentsLength(commandsLen, 1) if err != nil { - return &InputError{commands[0], err} + return &InputError{thisCommand, err} } c.Close() default: - return &InputError{commands[0], InvalidCommand} + return &InputError{thisCommand, InvalidCommand} } return nil