Git Product home page Git Product logo

cmd's Introduction

Introduction

This package is used to handle text command in Go program.

Basic usage:

import "github.com/funny/cmd"

cmd.Register("hello", "say hello", func() {
	fmt.Println("Hello!")
})

var command string
fmt.Scanln(&command)

cmd.Process(command)

The first argument of Register() function, is a regular expression.

When a command match the regular expression the handler function will be invoked.

A command handler function can be any kind of these types:

func()

func() interface{}

func(args []string)

func(args []string) interface{}

When a command handler receive []string argument, the command will be splited by Regexp.FindStringSubmatch() and pass to handler.

For example:

import "github.com/funny/cmd"

cmd.Register("cmd (abc|def) ([0-9]) ([0-9])", "test", func(args []string){
	fmt.Println(args[0]) // cmd abc 1 2
	fmt.Println(args[1]) // abc
	fmt.Println(args[2]) // 1
	fmt.Println(args[3]) // 2
})

cmd.Process("cmd abc 1 2")

Document: http://godoc.org/github.com/funny/cmd

cmd's People

Contributors

bg5sbk avatar

Watchers

James Cloos avatar 超级罗大文 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.