modify user/create.go to display only ID when created

This commit is contained in:
Alekzus 2022-03-17 16:50:44 +01:00
parent 6a4fc45132
commit b5905cf88b

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"github.com/passbolt/go-passbolt-cli/util" "github.com/passbolt/go-passbolt-cli/util"
"github.com/passbolt/go-passbolt/api" "github.com/passbolt/go-passbolt/helper"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -60,31 +60,30 @@ func UserCreate(cmd *cobra.Command, args []string) error {
defer client.Logout(context.TODO()) defer client.Logout(context.TODO())
cmd.SilenceUsage = true cmd.SilenceUsage = true
user, err := client.CreateUser( id, err := helper.CreateUser(
ctx, ctx,
api.User{ client,
Username: username, role,
Profile: &api.Profile{ username,
FirstName: firstname, firstname,
LastName: lastname, lastname,
},
Role: &api.Role{
Name: role,
},
},
) )
if err != nil { if err != nil {
return fmt.Errorf("Creating User: %w", err) return fmt.Errorf("Creating User: %w", err)
} }
if jsonOutput { if jsonOutput {
jsonUser, err := json.MarshalIndent(user, "", " ") jsonId, err := json.MarshalIndent(
map[string]string{"id": id},
"",
" ",
)
if err != nil { if err != nil {
return err return err
} }
fmt.Println(string(jsonUser)) fmt.Println(string(jsonId))
} else { } else {
fmt.Printf("UserID: %v\n", user.ID) fmt.Printf("UserID: %v\n", id)
} }
return nil return nil
} }