Skip to content

Implement Variants and pattern matching to make it easy to add new commands. #2

Description

@ProCode2

Right now because there is no defined set of commands, I didn't do this right away.

Create variants

type command =
  | CreateDir(option<string>)
  | CreateCurrentDir
  | Help
  | Something;

Then while parsing the command

// in command parser
switch command {
  | "help" => Help
  |  "recognisable" => Something
  }

// actual actions
switch cmnd {
| Help => printHelp()
| CreateDir(dir) => // create a directory
| Something => // do something
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions