-
Notifications
You must be signed in to change notification settings - Fork 0
/
usermgr.go
34 lines (29 loc) · 868 Bytes
/
usermgr.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
package main
import (
"fmt"
"os"
"strings"
"github.com/crewjam/usermgr/cmd"
)
type ErrorWithExitCode interface {
error
ExitCode() int
}
func main() {
// A small hack to deal with cases where the we must be invoked with no
// arguments, such as when we are invoked as an AuthorizedKeysCommand or
// a login shell. If the name of the program contains dots, then everything
// after the first '.' becomes an argument. For for example,
// `usermgr.sshkeys bob` is equivalent to `usermgr sshkeys bob`. (Of course
// you need a symlink from usermgr to usermgr.sshkeys to make this work).
args := strings.Split(os.Args[0], ".")
args = append(args, os.Args[1:]...)
if err := cmd.Main(args, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
if e, ok := err.(ErrorWithExitCode); ok {
os.Exit(e.ExitCode())
} else {
os.Exit(1)
}
}
}