mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +01:00
status: raw output subcommand
This commit is contained in:
parent
7f9eb62640
commit
9dd662df08
@ -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")
|
||||||
|
5
main.go
5
main.go
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user