2013-09-04 22:02:17 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
*/
|
|
|
|
|
2013-08-23 00:09:03 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-09-04 21:29:53 -04:00
|
|
|
"asink"
|
2013-08-23 00:09:03 -04:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2013-09-02 09:36:03 -04:00
|
|
|
type Command struct {
|
2013-08-23 00:09:03 -04:00
|
|
|
cmd string
|
|
|
|
fn func(args []string)
|
|
|
|
explanation string
|
|
|
|
}
|
|
|
|
|
2013-09-02 09:36:03 -04:00
|
|
|
var commands []Command = []Command{
|
|
|
|
Command{
|
|
|
|
cmd: "start",
|
|
|
|
fn: StartServer,
|
|
|
|
explanation: "Start the server daemon",
|
|
|
|
},
|
2013-09-02 23:35:48 -04:00
|
|
|
Command{
|
|
|
|
cmd: "stop",
|
|
|
|
fn: StopServer,
|
|
|
|
explanation: "Stop the server daemon",
|
|
|
|
},
|
2013-09-02 09:36:03 -04:00
|
|
|
Command{
|
2013-08-23 00:09:03 -04:00
|
|
|
cmd: "useradd",
|
|
|
|
fn: UserAdd,
|
|
|
|
explanation: "Add a user",
|
|
|
|
},
|
2013-09-02 09:36:03 -04:00
|
|
|
Command{
|
2013-08-23 00:09:03 -04:00
|
|
|
cmd: "userdel",
|
|
|
|
fn: UserDel,
|
|
|
|
explanation: "Remove a user",
|
|
|
|
},
|
2013-09-02 09:36:03 -04:00
|
|
|
Command{
|
2013-08-23 00:09:03 -04:00
|
|
|
cmd: "usermod",
|
|
|
|
fn: UserMod,
|
|
|
|
explanation: "Modify a user",
|
|
|
|
},
|
2013-09-04 21:29:53 -04:00
|
|
|
Command{
|
|
|
|
cmd: "version",
|
|
|
|
fn: PrintVersion,
|
|
|
|
explanation: "Display the current version",
|
|
|
|
},
|
2013-08-23 00:09:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) > 1 {
|
|
|
|
cmd := os.Args[1]
|
|
|
|
for _, c := range commands {
|
|
|
|
if c.cmd == cmd {
|
|
|
|
c.fn(os.Args[2:])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("Invalid subcommand specified, please pick from the following:")
|
|
|
|
} else {
|
|
|
|
fmt.Println("No subcommand specified, please pick one from the following:")
|
|
|
|
}
|
|
|
|
for _, c := range commands {
|
|
|
|
fmt.Printf("\t%s\t\t%s\n", c.cmd, c.explanation)
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 21:29:53 -04:00
|
|
|
|
|
|
|
func PrintVersion(args []string) {
|
|
|
|
fmt.Println("Asink server version " + asink.VERSION_STRING + ", using version " + asink.API_VERSION_STRING + " of the Asink API.")
|
|
|
|
}
|