Adding the help command
This commit is contained in:
parent
9757016561
commit
3e0e994e86
2 changed files with 26 additions and 2 deletions
|
@ -50,7 +50,6 @@ func SendFile(c net.Conn, path string) (int, error) {
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ListFiles list the files from path and sends them to the connection
|
// ListFiles list the files from path and sends them to the connection
|
||||||
func ListFiles(c net.Conn) error {
|
func ListFiles(c net.Conn) error {
|
||||||
files, err := ioutil.ReadDir(PATH)
|
files, err := ioutil.ReadDir(PATH)
|
||||||
|
@ -71,3 +70,16 @@ func ListFiles(c net.Conn) error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -58,7 +58,19 @@ func ProcessInput(c net.Conn, text string) error {
|
||||||
// Ansi clear: 1b 5b 48 1b 5b 4a
|
// Ansi clear: 1b 5b 48 1b 5b 4a
|
||||||
// clear | hexdump -C
|
// clear | hexdump -C
|
||||||
var b []byte = []byte{0x1b, 0x5b, 0x48, 0x1b, 0x5b, 0x4a}
|
var b []byte = []byte{0x1b, 0x5b, 0x48, 0x1b, 0x5b, 0x4a}
|
||||||
|
|
||||||
c.Write(b)
|
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":
|
case "exit":
|
||||||
err := checkArgumentsLength(commandsLen, 1)
|
err := checkArgumentsLength(commandsLen, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue