status: raw output subcommand

This commit is contained in:
Christian Schwarz 2018-09-23 14:44:53 +02:00
parent 7f9eb62640
commit 9dd662df08
2 changed files with 29 additions and 2 deletions

View File

@ -12,6 +12,9 @@ import (
"sort" "sort"
"sync" "sync"
"time" "time"
"io"
"os"
"net/http"
) )
type tui struct { type tui struct {
@ -62,12 +65,33 @@ func (t *tui) addIndent(indent int) {
t.moveLine(0, 0) t.moveLine(0, 0)
} }
func RunStatus(config *config.Config, args []string) error { type StatusFlags struct {
Raw bool
}
func RunStatus(flags StatusFlags, config *config.Config, args []string) error {
httpc, err := controlHttpClient(config.Global.Control.SockPath) httpc, err := controlHttpClient(config.Global.Control.SockPath)
if err != nil { if err != nil {
return err return err
} }
if flags.Raw {
resp, err := httpc.Get("http://unix"+daemon.ControlJobEndpointStatus)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintf(os.Stderr, "Received error response:\n")
io.CopyN(os.Stderr, resp.Body, 4096)
return errors.Errorf("exit")
}
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
return err
}
return nil
}
t := newTui() t := newTui()
t.lock.Lock() t.lock.Lock()
t.err = errors.New("Got no report yet") t.err = errors.New("Got no report yet")

View File

@ -47,6 +47,8 @@ var wakeupCmd = &cobra.Command{
}, },
} }
var statusCmdFlags client.StatusFlags
var statusCmd = &cobra.Command{ var statusCmd = &cobra.Command{
Use: "status", Use: "status",
Short: "status", Short: "status",
@ -55,7 +57,7 @@ var statusCmd = &cobra.Command{
if err != nil { if err != nil {
return err return err
} }
return client.RunStatus(conf, args) return client.RunStatus(statusCmdFlags, conf, args)
}, },
} }
@ -158,6 +160,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path") rootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path")
rootCmd.AddCommand(daemonCmd) rootCmd.AddCommand(daemonCmd)
rootCmd.AddCommand(wakeupCmd) rootCmd.AddCommand(wakeupCmd)
statusCmd.Flags().BoolVar(&statusCmdFlags.Raw, "raw", false, "dump raw response from zrepl daemon")
rootCmd.AddCommand(statusCmd) rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(stdinserverCmd) rootCmd.AddCommand(stdinserverCmd)
rootCmd.AddCommand(bashcompCmd) rootCmd.AddCommand(bashcompCmd)