Adding the help command

This commit is contained in:
Denis-Cosmin Nutiu 2017-10-20 18:20:11 +03:00
parent 9757016561
commit 3e0e994e86
2 changed files with 26 additions and 2 deletions

View file

@ -50,7 +50,6 @@ func SendFile(c net.Conn, path string) (int, error) {
return n, nil
}
// ListFiles list the files from path and sends them to the connection
func ListFiles(c net.Conn) error {
files, err := ioutil.ReadDir(PATH)
@ -71,3 +70,16 @@ func ListFiles(c net.Conn) error {
return nil
}
func ShowHelp(c net.Conn) error {
var helpText string = `
The available commands are:
get <filename> - Download the requested filename.
ls - List the files in the current directory.
clear - Clear the screen.
exit - Close the connection with the server.
`
_, err := c.Write([]byte(helpText))
return err
}

View file

@ -58,7 +58,19 @@ func ProcessInput(c net.Conn, text string) error {
// Ansi clear: 1b 5b 48 1b 5b 4a
// clear | hexdump -C
var b []byte = []byte{0x1b, 0x5b, 0x48, 0x1b, 0x5b, 0x4a}
c.Write(b)
case "help":
// Check arguments
err := checkArgumentsLength(commandsLen, 1)
if err != nil {
return &InputError{commands[0], err}
}
err = ShowHelp(c)
if err != nil {
return &InputError{commands[0], err}
}
case "exit":
err := checkArgumentsLength(commandsLen, 1)
if err != nil {