Skip to content

Commit

Permalink
Add invitation survey
Browse files Browse the repository at this point in the history
```sh
$ ./bin/flyctl orgs invite
? Select organization: paypack (paypack)
? User email: name@example.com
Org                  Email                Redeemed
----                 ----                 ----
paypack              name@example.com     false
```
  • Loading branch information
rugwirobaker committed Jun 13, 2021
1 parent 835d301 commit 9d1f45b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions cmd/input.go
Expand Up @@ -376,3 +376,14 @@ func isIntPort(val interface{}) error {

return errors.New("couldn't convert to string")
}

func inputUserEmail() (email string, err error) {
prompt := &survey.Input{
Message: "User email:",
}
if err := survey.AskOne(prompt, &email); err != nil {
return email, err
}

return email, nil
}
26 changes: 21 additions & 5 deletions cmd/orgs.go
Expand Up @@ -140,17 +140,33 @@ func runOrgsShow(ctx *cmdctx.CmdContext) error {
}

func runOrgsInvite(ctx *cmdctx.CmdContext) error {
orgslug := ctx.Args[0]
var orgSlug, userEmail string

org, err := ctx.Client.API().GetOrganizationBySlug(orgslug)
switch len(ctx.Args) {
case 0:
org, err := selectOrganization(ctx.Client.API(), "")
if err != nil {
return err
}
orgSlug = org.Slug

userEmail, err = inputUserEmail()
if err != nil {
return err
}
case 1:
// TODO: Validity check on org
orgSlug = ctx.Args[0]
case 2:
userEmail = ctx.Args[1]
}

org, err := ctx.Client.API().GetOrganizationBySlug(orgSlug)
if err != nil {
return err
}

email := ctx.Args[1]

out, err := ctx.Client.API().CreateOrganizationInvite(org.ID, email)
out, err := ctx.Client.API().CreateOrganizationInvite(org.ID, userEmail)
if err != nil {
return err
}
Expand Down

0 comments on commit 9d1f45b

Please sign in to comment.