Add 'info' command

This commit is contained in:
Manfred Touron 2017-11-01 17:00:34 +01:00
parent 6d28cd6358
commit e9a4ddb1ce
2 changed files with 22 additions and 5 deletions

View file

@ -73,7 +73,7 @@ func server(c *cli.Context) error {
switch s.User() {
case "config":
if err := shell(s, s.Command(), db); err != nil {
if err := shell(c, s, s.Command(), db); err != nil {
io.WriteString(s, fmt.Sprintf("error: %v\n", err))
}
default:

View file

@ -4,7 +4,9 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"regexp"
"runtime"
shlex "github.com/anmitsu/go-shlex"
"github.com/gliderlabs/ssh"
@ -26,7 +28,7 @@ var banner = `
`
var isNameValid = regexp.MustCompile(`^[A-Za-z0-9_-]+$`).MatchString
func shell(s ssh.Session, sshCommand []string, db *gorm.DB) error {
func shell(globalContext *cli.Context, s ssh.Session, sshCommand []string, db *gorm.DB) error {
if len(sshCommand) == 0 {
io.WriteString(s, banner)
}
@ -165,7 +167,22 @@ GLOBAL OPTIONS:
}, {
Name: "info",
Usage: "Display system-wide information",
Action: func(c *cli.Context) error { return nil },
Action: func(c *cli.Context) error {
fmt.Fprintf(s, "Debug mode (server): %v\n", globalContext.Bool("debug"))
hostname, _ := os.Hostname()
fmt.Fprintf(s, "Hostname: %s\n", hostname)
fmt.Fprintf(s, "CPUs: %d\n", runtime.NumCPU())
fmt.Fprintf(s, "Demo mode: %v\n", globalContext.Bool("demo"))
fmt.Fprintf(s, "DB Driver: %s\n", globalContext.String("db-driver"))
fmt.Fprintf(s, "DB Conn: %s\n", globalContext.String("db-conn"))
fmt.Fprintf(s, "Bind Address: %s\n", globalContext.String("bind-address"))
// FIXME: add version
// FIXME: add info about current server (network, cpu, ram, OS)
// FIXME: add info about current user
// FIXME: add active connections
// FIXME: stats
return nil
},
}, {
Name: "key",
Usage: "Manage keys",