implmentation of help method in command interface

Former-commit-id: 655be5abcefa1cbf066197f850929f3a71c732a6
botanswer
AnisB 3 years ago
parent 7d07dc91f9
commit b988fb5a19

@ -87,44 +87,64 @@ type config struct {
type Command interface {
Run(args []string) (string, error)
Help(args []string) (string, error)
}
type HelpCmd struct {
type DefaultCmd struct {
}
func (*HelpCmd) Run(args []string) (string, error) {
helpText := " this is help"
return helpText, nil
type HelloCmd struct {
}
type DefaultCmd struct {
type HelpCmd struct {
}
func (*DefaultCmd) Run(args []string) (string, error) {
return "Type help to get available commands", nil
}
type HelloCmd struct {
func (*DefaultCmd) Help(args []string) (string, error) {
return "Help of Default", nil
}
func (*HelpCmd) Run(args []string) (string, error) {
helpText := " this is help"
return helpText, nil
}
func (*HelpCmd) Help(args []string) (string, error) {
return "this is help of help", nil
}
func (*HelloCmd) Run(args []string) (string, error) {
/*for _, result := range args {
if result == "help" {
return "help of hello", nil
}
}*/
return "Hi, My name is Skynet 1.0. \n How can I help you ? ", nil
}
func (*HelloCmd) Help(args []string) (string, error) {
return "Help of Hello", nil
}
func handleCommand(command Command, args []string) string {
if len(args) != 0 && args[0] == "help" {
fmt.Println("Inside 1")
return "help of hello", nil
result, err := command.Help(args)
if err != nil {
return "error"
}
return result
} else if len(args) != 0 && args[0] != "help" {
return "unkown command", nil
return "Unkown command"
}
return "Hi, My name is Skynet 1.0. \n How can I help you ? ", nil
}
func handleCommand(command Command, args []string) string {
result, err := command.Run(args)
if err != nil {
return "error"

Loading…
Cancel
Save