Skip to content
Snippets Groups Projects
Unverified Commit 5bb2ae00 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Initial help implementation

parent e21eb5b0
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,6 @@ type Commands map[string]*Command ...@@ -35,7 +35,6 @@ type Commands map[string]*Command
func (c Commands) ParseAndRun(line string) error { func (c Commands) ParseAndRun(line string) error {
// TODO: this doesn't handle a DCL command line completely. // TODO: this doesn't handle a DCL command line completely.
words := strings.Fields(line) words := strings.Fields(line)
fmt.Printf("TODO ParseAndRun need to parse flags: %s\n", words)
cmd, ok := c[strings.ToUpper(words[0])] cmd, ok := c[strings.ToUpper(words[0])]
if !ok { if !ok {
fmt.Printf("ERROR: Unknown command '%s'\n", words[0]) fmt.Printf("ERROR: Unknown command '%s'\n", words[0])
...@@ -52,6 +51,7 @@ func (c Commands) ParseAndRun(line string) error { ...@@ -52,6 +51,7 @@ func (c Commands) ParseAndRun(line string) error {
if len(words) == 1 { if len(words) == 1 {
return cmd.Action(cmd) return cmd.Action(cmd)
} }
// TODO: need to clean this up.
for i := range words[1:] { for i := range words[1:] {
if strings.HasPrefix(words[i], "/") { if strings.HasPrefix(words[i], "/") {
flag, val, assigned := strings.Cut(words[i], "=") flag, val, assigned := strings.Cut(words[i], "=")
...@@ -63,7 +63,6 @@ func (c Commands) ParseAndRun(line string) error { ...@@ -63,7 +63,6 @@ func (c Commands) ParseAndRun(line string) error {
} }
flg.Value = val flg.Value = val
} else { } else {
// TODO: handle toggle flag.
wordup := strings.ToUpper(words[i]) wordup := strings.ToUpper(words[i])
value := "true" value := "true"
if strings.HasPrefix(wordup, "/NO") { if strings.HasPrefix(wordup, "/NO") {
...@@ -76,6 +75,8 @@ func (c Commands) ParseAndRun(line string) error { ...@@ -76,6 +75,8 @@ func (c Commands) ParseAndRun(line string) error {
} }
flg.Value = value flg.Value = value
} }
} else {
cmd.Args = append(cmd.Args, words[i])
} }
} }
return cmd.Action(cmd) return cmd.Action(cmd)
......
This diff is collapsed.
...@@ -2,10 +2,27 @@ ...@@ -2,10 +2,27 @@
package repl package repl
import ( import (
"fmt"
"strings"
"git.lyda.ie/kevin/bulletin/dclish" "git.lyda.ie/kevin/bulletin/dclish"
) )
var helpmap map[string]string
// ActionHelp handles the `HELP` command. // ActionHelp handles the `HELP` command.
func ActionHelp(_ *dclish.Command) error { func ActionHelp(cmd *dclish.Command) error {
if len(cmd.Args) == 0 {
fmt.Printf("%s\n", cmd.Description)
return nil
}
wordup := strings.ToUpper(cmd.Args[0])
helptext, ok := helpmap[wordup]
if !ok {
// TODO: add a help structure for topics that are not command.
fmt.Printf("ERROR: Topic not found: '%s'.\n", cmd.Args[0])
return nil
}
fmt.Printf("%s\n", helptext)
return nil return nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment