cmd/instance.go
changeset 186 180e636f231c
parent 185 564d92b54b00
child 190 e058a8a15e22
--- a/cmd/instance.go	Mon Mar 19 15:06:17 2018 +0100
+++ b/cmd/instance.go	Mon Mar 19 15:26:43 2018 +0100
@@ -6,21 +6,11 @@
 package cmd
 
 import (
-	"context"
 	"os"
-	"strings"
 
-	"github.com/m0t0k1ch1/gomif"
-	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 )
 
-var instanceOpts struct {
-	stats      bool
-	server     string
-	start, end int64
-}
-
 // timelinesCmd represents the timelines command
 var instanceCmd = &cobra.Command{
 	Use:   "instance",
@@ -28,40 +18,20 @@
 	Long: `Display instance information
 
 This command display the instance information returned by the server.
-
-With '--stats', the instances.mastodon.xyz API is queried and instance
-statistics will be returned (the instance server can be specified).
-To get a range of statistics, both '--start' and '--end' should be provided
-with UNIX timestamps (e.g. "date +%s").
 `,
 	RunE: instanceRunE,
-	Example: `  madonctl instance
-  madonctl instance -i mastodon.social
-  madonctl instance --stats
-  madonctl instance --stats --start 1493565000 --end 1493566000
-  madonctl instance --stats --server mastodon.social --template '{{.Users}}'`,
 }
 
 func init() {
 	RootCmd.AddCommand(instanceCmd)
-
-	instanceCmd.Flags().BoolVar(&instanceOpts.stats, "stats", false, "Display server statistics (from instances.mastodon.xyz)")
-	instanceCmd.Flags().StringVar(&instanceOpts.server, "server", "", "Display statistics for a specific server (for --stats)")
-	instanceCmd.Flags().Int64Var(&instanceOpts.start, "start", 0, "Start timestamp (for --stats)")
-	instanceCmd.Flags().Int64Var(&instanceOpts.end, "end", 0, "End timestamp (for --stats)")
 }
 
 func instanceRunE(cmd *cobra.Command, args []string) error {
-	opt := instanceOpts
-
-	if opt.stats {
-		return instanceStats()
+	if err := madonInit(false); err != nil {
+		return err
 	}
 
 	// Get current instance data through the API
-	if err := madonInit(false); err != nil {
-		return err
-	}
 	i, err := gClient.GetCurrentInstance()
 	if err != nil {
 		errPrint("Error: %s", err.Error())
@@ -75,56 +45,3 @@
 	}
 	return p.printObj(i)
 }
-
-func instanceStats() error {
-	opt := instanceOpts
-
-	// Get instance statistics using gomif
-	if opt.server == "" {
-		if err := madonInit(false); err != nil {
-			return err
-		}
-		opt.server = strings.TrimLeft(gClient.InstanceURL, "https://")
-	}
-
-	if opt.server == "" {
-		return errors.New("no instance server name")
-	}
-
-	client := gomif.NewClient()
-	var obj interface{}
-	var err error
-
-	if opt.start > 0 && opt.end > 0 {
-		var isl []*gomif.InstanceStatus
-		isl, err = client.FetchInstanceStatuses(
-			context.Background(),
-			opt.server, opt.start, opt.end,
-		)
-		obj = isl
-	} else if opt.start > 0 || opt.end > 0 {
-		return errors.New("invalid parameters: missing timestamp")
-	} else {
-		var is *gomif.InstanceStatus
-		is, err = client.FetchLastInstanceStatus(
-			context.Background(),
-			opt.server,
-			3600, // span (sec)
-		)
-		obj = is
-	}
-	if err != nil {
-		errPrint("Error: %s", err.Error())
-		os.Exit(1)
-	}
-	if obj == nil {
-		return nil
-	}
-
-	p, err := getPrinter()
-	if err != nil {
-		errPrint("Error: %s", err.Error())
-		os.Exit(1)
-	}
-	return p.printObj(obj)
-}