github.com/mhlo/force@v0.22.28-0.20150915022417-6d05ecfb0b47/limits.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"sort"
     6  )
     7  
     8  var cmdLimits = &Command{
     9  	Usage: "limits",
    10  	Short: "Display current limits",
    11  	Long: `
    12  	Use the limits command to display limits information for your organization.
    13  
    14  	 -- Max is the limit total for the organization.
    15  
    16  	 -- Remaining is the total number of calls or events left for the organization.`,
    17  }
    18  
    19  func init() {
    20  	cmdLimits.Run = runLimits
    21  }
    22  
    23  func runLimits(cmd *Command, args []string) {
    24  
    25  	force, _ := ActiveForce()
    26  
    27  	var result ForceLimits
    28  	result, err := force.GetLimits()
    29  
    30  	if err != nil {
    31  		ErrorAndExit(err.Error())
    32  	} else {
    33  		printLimits(result)
    34  	}
    35  }
    36  
    37  func printLimits(result map[string]ForceLimit) {
    38  
    39  	//sort keys
    40  	var keys []string
    41  	for k := range result {
    42  		keys = append(keys, k)
    43  	}
    44  	sort.Strings(keys)
    45  
    46  	//print map
    47  	for _, k := range keys {
    48  		fmt.Println(k, "\n", result[k].Max, "maximum\n", result[k].Remaining, "remaining\n")
    49  	}
    50  
    51  }