Files
cunicu/cmd/status.go
Steffen Vogel f38032fb7c refactor cmd directory structure
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-07-27 13:39:18 +02:00

47 lines
939 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"context"
"os"
"github.com/spf13/cobra"
"go.uber.org/zap"
"google.golang.org/protobuf/encoding/protojson"
"riasc.eu/wice/pkg/pb"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Show current status of ɯice daemon",
Run: status,
Args: cobra.NoArgs,
}
func init() {
addClientCommand(RootCmd, statusCmd)
}
func status(cmd *cobra.Command, args []string) {
sts, err := client.GetStatus(context.Background(), &pb.Void{})
if err != nil {
logger.Fatal("Failed to retrieve status from daemon", zap.Error(err))
}
mo := protojson.MarshalOptions{
Multiline: true,
Indent: " ",
AllowPartial: true,
UseProtoNames: true,
EmitUnpopulated: false,
}
buf, err := mo.Marshal(sts)
if err != nil {
logger.Fatal("Failed to marshal", zap.Error(err))
}
if _, err = os.Stdout.Write(buf); err != nil {
logger.Fatal("Failed to write to stdout", zap.Error(err))
}
}