Total Pageviews

Monday, 20 June 2016

基于go的personal toolkit,

ptk wercker status

Build your personal toolkit, write more, run in one tool!

Why and How

  • Write multiple tools, build all in one binary, stop toolA, toolB, toolC...!
  • Parse plugins list, generate import and register code atomaticlly.
You can also use it as a library to build your own application with multiple options like "go build/instal/tool ..."

Ability

  • Prefix match, one letter, one command
  • Fully custom color

Concepts

All is plugin, put all your plugins under plugins directory.
Plugins are independent, doesn't depends on ptk, just like a normal go application, no complains here.
/main.go
/list.go # automatic generated
/plugins
/plugins/plugin1.go # Plugin2 (main function)
/plugins/plugin2
/plugins/plugin2/plugin2.go # Main (main function)

Example

main.go
package main

import (
    "github.com/cosiner/ptk"
)

func main() {
    ptk.App.Name = "mtk" // optional
    ptk.App.Description = "personal toolkit!" // optional

    ptk.Run()
}
plugins/hello.go
// put your plugin description here, only first line will be used.
package plugins

import (
    "flag"
    "fmt"
)

func Hello() {
    s := flag.String("s", "Hello World", "your string")
    flag.Parse()
    fmt.Println(*s)
}
plugins/rand/rand.go
// Package rand generate random string
package rand

import (
    "flag"
    "fmt"

    "github.com/cosiner/gohper/crypto/rand"
    "github.com/cosiner/gohper/errors"
)

func Main() {
    n := flag.Int("n", 32, "bits number to generate")
    flag.Parse()

    s, err := rand.S.Alphabet(*n)
    errors.Fatalln(err)
    fmt.Println(s)
}
$ go build -o t
$ t build # if on windows, go build again
$ t hello -s "Hello guys"
$ t rand -n 64


from https://github.com/cosiner/ptk