cmd/instance.go
author Mikael Berthe <mikael@lilotux.net>
Mon, 19 Mar 2018 15:26:43 +0100
changeset 186 180e636f231c
parent 185 564d92b54b00
child 190 e058a8a15e22
permissions -rw-r--r--
Remove extended statistics using the instances.mastodon.xyz API
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
185
564d92b54b00 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 110
diff changeset
     1
// Copyright © 2017-2018 Mikael Berthe <mikael@lilotux.net>
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
//
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
// Licensed under the MIT license.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
// Please see the LICENSE file is this directory.
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
package cmd
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
import (
37
9bc03db114c3 Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
     9
	"os"
9bc03db114c3 Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    10
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
	"github.com/spf13/cobra"
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
// timelinesCmd represents the timelines command
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
var instanceCmd = &cobra.Command{
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
	Use:   "instance",
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
	Short: "Display current instance information",
38
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    18
	Long: `Display instance information
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    19
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    20
This command display the instance information returned by the server.
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    21
`,
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    22
	RunE: instanceRunE,
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
func init() {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
	RootCmd.AddCommand(instanceCmd)
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
func instanceRunE(cmd *cobra.Command, args []string) error {
186
180e636f231c Remove extended statistics using the instances.mastodon.xyz API
Mikael Berthe <mikael@lilotux.net>
parents: 185
diff changeset
    30
	if err := madonInit(false); err != nil {
180e636f231c Remove extended statistics using the instances.mastodon.xyz API
Mikael Berthe <mikael@lilotux.net>
parents: 185
diff changeset
    31
		return err
37
9bc03db114c3 Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    32
	}
9bc03db114c3 Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    33
9bc03db114c3 Add server statistics with gomif (using instances.mastodon.xyz API)
Mikael Berthe <mikael@lilotux.net>
parents: 0
diff changeset
    34
	// Get current instance data through the API
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
	i, err := gClient.GetCurrentInstance()
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
	if err != nil {
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
		errPrint("Error: %s", err.Error())
47
82d8b6074309 Set exit code to non-zero when API calls fail
Mikael Berthe <mikael@lilotux.net>
parents: 45
diff changeset
    38
		os.Exit(1)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
	}
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
38
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    41
	p, err := getPrinter()
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    42
	if err != nil {
81
b1671f83e91b Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
    43
		errPrint("Error: %s", err.Error())
b1671f83e91b Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents: 47
diff changeset
    44
		os.Exit(1)
38
891a3c46a62a Instance stats: sync with gomif update & add time range support
Mikael Berthe <mikael@lilotux.net>
parents: 37
diff changeset
    45
	}
110
57843255fd1a Refactor printers
Mikael Berthe <mikael@lilotux.net>
parents: 81
diff changeset
    46
	return p.printObj(i)
0
5abace724584 Initial public release
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
}