0%

github.com-olahol-melody-websocket框架

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import (
"fmt"
"os"
"github.com/urfave/cli"
)

func main() {
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "test",
Usage: "test --uid=x --username=y",
Action: (&Command{}).Test,
Flags: []cli.Flag{
cli.IntFlag{Name: "uid",Usage:"--uid"},
cli.StringFlag{Name:"username",Usage:"--username"},
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Print("command error :" + err.Error())
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
package main

import (
"fmt"
"github.com/urfave/cli"
)
type Command struct {}

func (this *Command) Test(cli *cli.Context) {
uid := cli.Int("uid")
username := cli.String("username")
fmt.Println(uid,username)
}