github.com/section/sectionctl@v1.12.3/commands/accounts.go (about)

     1  package commands
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  
     7  	"github.com/alecthomas/kong"
     8  	"github.com/section/sectionctl/api"
     9  )
    10  
    11  // AccountsCmd manages accounts on Section
    12  type AccountsCmd struct {
    13  	List AccountsListCmd `cmd help:"List accounts on Section." default:"1"`
    14  }
    15  
    16  // AccountsListCmd handles listing accounts on Section
    17  type AccountsListCmd struct{}
    18  
    19  // Run executes the command
    20  func (c *AccountsListCmd) Run(cli *CLI, ctx *kong.Context,logWriters *LogWriters) (err error) {
    21  	s := NewSpinner("Looking up accounts", logWriters)
    22  	s.Start()
    23  
    24  	accounts, err := api.Accounts()
    25  	s.Stop()
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	table := NewTable(cli, os.Stdout)
    31  	table.SetHeader([]string{"Account ID", "Account Name"})
    32  
    33  	for _, a := range accounts {
    34  		r := []string{strconv.Itoa(a.ID), a.AccountName}
    35  		table.Append(r)
    36  	}
    37  
    38  	table.Render()
    39  	return err
    40  }
    41  
    42  // AccountsCreateCmd handles creating apps on Section
    43  type AccountsCreateCmd struct{}