Skip to content

Commit

Permalink
stolonctl: add clusterdata command
Browse files Browse the repository at this point in the history
Add a stolonctl command to display current clusterdata.
  • Loading branch information
sgotti committed Jul 19, 2017
1 parent b5bf7a1 commit 43a5dba
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions cmd/stolonctl/clusterdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2017 Sorint.lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"

"github.com/spf13/cobra"
)

var cmdClusterData = &cobra.Command{
Use: "clusterdata",
Run: clusterdata,
Short: "Retrieve the current cluster data",
}

type clusterdataOptions struct {
pretty bool
}

var clusterdataOpts clusterdataOptions

func init() {
cmdClusterData.PersistentFlags().BoolVar(&clusterdataOpts.pretty, "pretty", false, "pretty print")

cmdStolonCtl.AddCommand(cmdClusterData)
}

func clusterdata(cmd *cobra.Command, args []string) {
e, err := NewStore()
if err != nil {
die("cannot create store: %v", err)
}

cd, _, err := getClusterData(e)
if err != nil {
die("%v", err)
}
if cd.Cluster == nil {
die("no cluster clusterdata available")
}
var clusterdataj []byte
if clusterdataOpts.pretty {
clusterdataj, err = json.MarshalIndent(cd, "", "\t")
if err != nil {
die("failed to marshall clusterdata: %v", err)
}
} else {
clusterdataj, err = json.Marshal(cd)
if err != nil {
die("failed to marshall clusterdata: %v", err)
}
}
stdout("%s", clusterdataj)
}

0 comments on commit 43a5dba

Please sign in to comment.