-
Notifications
You must be signed in to change notification settings - Fork 23
/
base.go
37 lines (29 loc) · 908 Bytes
/
base.go
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
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"flag"
"fmt"
"os"
"strings"
)
// A Command is an implementation of a gohack command.
type Command struct {
// Run runs the command and returns its exit status.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string) int
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
UsageLine string
// Short is the short description shown in the 'gohack help' output.
Short string
// Long is the long message shown in the 'gohack help <this-command>' output.
Long string
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
}
func (c *Command) Name() string {
return strings.SplitN(c.UsageLine, " ", 2)[0]
}
func (c *Command) Usage() {
fmt.Fprintf(os.Stderr, "usage: %s\n", c.UsageLine)
fmt.Fprintf(os.Stderr, "Run 'gohack help %s' for details.\n", c.Name())
}