github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/cmd/ots/organization_new.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/leg100/go-tfe"
     7  	"github.com/leg100/ots"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  func OrganizationNewCommand(config ClientConfig) *cobra.Command {
    12  	opts := tfe.OrganizationCreateOptions{}
    13  
    14  	cmd := &cobra.Command{
    15  		Use:   "new [name]",
    16  		Short: "Create a new organization",
    17  		Args:  cobra.ExactArgs(1),
    18  		RunE: func(cmd *cobra.Command, args []string) error {
    19  			opts.Name = ots.String(args[0])
    20  
    21  			client, err := config.NewClient()
    22  			if err != nil {
    23  				return err
    24  			}
    25  
    26  			org, err := client.Organizations().Create(cmd.Context(), opts)
    27  			if err != nil {
    28  				return err
    29  			}
    30  
    31  			fmt.Printf("Successfully created organization %s\n", org.Name)
    32  
    33  			return nil
    34  		},
    35  	}
    36  
    37  	opts.Email = cmd.Flags().String("email", "", "Email of the owner of the organization")
    38  	cmd.MarkFlagRequired("email")
    39  
    40  	return cmd
    41  }