Unverified Commit 5bb2ae00 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Initial help implementation

parent e21eb5b0
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ type Commands map[string]*Command
func (c Commands) ParseAndRun(line string) error {
	// TODO: this doesn't handle a DCL command line completely.
	words := strings.Fields(line)
	fmt.Printf("TODO ParseAndRun need to parse flags: %s\n", words)
	cmd, ok := c[strings.ToUpper(words[0])]
	if !ok {
		fmt.Printf("ERROR: Unknown command '%s'\n", words[0])
@@ -52,6 +51,7 @@ func (c Commands) ParseAndRun(line string) error {
	if len(words) == 1 {
		return cmd.Action(cmd)
	}
	// TODO: need to clean this up.
	for i := range words[1:] {
		if strings.HasPrefix(words[i], "/") {
			flag, val, assigned := strings.Cut(words[i], "=")
@@ -63,7 +63,6 @@ func (c Commands) ParseAndRun(line string) error {
				}
				flg.Value = val
			} else {
				// TODO: handle toggle flag.
				wordup := strings.ToUpper(words[i])
				value := "true"
				if strings.HasPrefix(wordup, "/NO") {
@@ -76,6 +75,8 @@ func (c Commands) ParseAndRun(line string) error {
				}
				flg.Value = value
			}
		} else {
			cmd.Args = append(cmd.Args, words[i])
		}
	}
	return cmd.Action(cmd)
+220 −438

File changed.

Preview size limit exceeded, changes collapsed.

+18 −1
Original line number Diff line number Diff line
@@ -2,10 +2,27 @@
package repl

import (
	"fmt"
	"strings"

	"git.lyda.ie/kevin/bulletin/dclish"
)

var helpmap map[string]string

// 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
}