mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-07-13 05:09:09 +00:00
Add Json Output to Create Commands
This commit is contained in:
parent
46ceb8176d
commit
a2257bc011
4 changed files with 73 additions and 4 deletions
|
@ -2,6 +2,7 @@ package resource
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/passbolt/go-passbolt-cli/util"
|
||||
|
@ -54,6 +55,10 @@ func ResourceCreate(cmd *cobra.Command, args []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput, err := cmd.Flags().GetBool("json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := util.GetContext()
|
||||
|
||||
|
@ -78,6 +83,18 @@ func ResourceCreate(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("Creating Resource: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("ResourceID: %v\n", id)
|
||||
if jsonOutput {
|
||||
jsonId, err := json.MarshalIndent(
|
||||
map[string]string{"id": id},
|
||||
"",
|
||||
" ",
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Marshalling Json: %w", err)
|
||||
}
|
||||
fmt.Println(string(jsonId))
|
||||
} else {
|
||||
fmt.Printf("ResourceID: %v\n", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue