AuHau / allot

Parse placeholder and wildcard text commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

allot MIT License GoDoc Go Report Card allot - Coverage Status Build Status

allot is a small Golang library to match and parse commands with pre-defined strings. For example use allot to define a list of commands your CLI application or Slackbot supports and check if incoming requests are matching your commands.

The allot library supports placeholders and regular expressions for parameter matching and parsing.

Usage

cmd := allot.New("revert <commits:integer> commits on <project:string> at (stage|prod)")
match, err := cmd.Match("revert 12 commits on example at prod")

if (err != nil)
  commits, _ = match.Integer("commits")
  project, _ = match.String("project")
  env, _ = match.Match(2)

  fmt.Printf("Revert \"%d\" on \"%s\" at \"%s\"", commits, project, env)
} else {
  fmt.Println("Request did not match command.")
}

Regex escaping

If you want to support regex escaping and hence characters like []() in your commands than use allot.NewWithEscaping() instead of allot.New().

Examples

See the hanu Slackbot framework for a usecase for allot:

Credits

About

Parse placeholder and wildcard text commands

License:MIT License


Languages

Language:Go 92.7%Language:Shell 6.4%Language:Makefile 0.9%