diff --git a/client/status.go b/client/status.go index 2b94f35..bd743d7 100644 --- a/client/status.go +++ b/client/status.go @@ -12,6 +12,9 @@ import ( "sort" "sync" "time" + "io" + "os" + "net/http" ) type tui struct { @@ -62,12 +65,33 @@ func (t *tui) addIndent(indent int) { 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) if err != nil { 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.lock.Lock() t.err = errors.New("Got no report yet") diff --git a/main.go b/main.go index f6e35aa..b2985c9 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,8 @@ var wakeupCmd = &cobra.Command{ }, } +var statusCmdFlags client.StatusFlags + var statusCmd = &cobra.Command{ Use: "status", Short: "status", @@ -55,7 +57,7 @@ var statusCmd = &cobra.Command{ if err != nil { 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.AddCommand(daemonCmd) rootCmd.AddCommand(wakeupCmd) + statusCmd.Flags().BoolVar(&statusCmdFlags.Raw, "raw", false, "dump raw response from zrepl daemon") rootCmd.AddCommand(statusCmd) rootCmd.AddCommand(stdinserverCmd) rootCmd.AddCommand(bashcompCmd)