Adding the help command
This commit is contained in:
parent
9757016561
commit
3e0e994e86
2 changed files with 26 additions and 2 deletions
|
@ -22,7 +22,7 @@ func SendFile(c net.Conn, path string) (int, error) {
|
|||
lastForwardSlash := strings.LastIndex(path, "/")
|
||||
if lastForwardSlash != -1 {
|
||||
// Eliminate the last forward slash i.e ../../asdas will become asdas
|
||||
fileName = path[lastForwardSlash + 1:]
|
||||
fileName = path[lastForwardSlash+1:]
|
||||
} else {
|
||||
fileName = path
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue