@@ -80,9 +80,11 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
|
||||
if err := cmdutil.ValidateEnum("kind", flagKind, []string{"MINOR_NONCONFORMITY", "MAJOR_NONCONFORMITY", "OBSERVATION", "EXCEPTION"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cmdutil.ValidateEnum("status", flagStatus, []string{"OPEN", "IN_PROGRESS", "CLOSED", "RISK_ACCEPTED", "MITIGATED", "FALSE_POSITIVE"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cmdutil.ValidateEnum("priority", flagPriority, []string{"LOW", "MEDIUM", "HIGH"}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -115,27 +117,35 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
|
||||
if flagOwnerID != "" {
|
||||
input["ownerId"] = flagOwnerID
|
||||
}
|
||||
|
||||
if flagDescription != "" {
|
||||
input["description"] = flagDescription
|
||||
}
|
||||
|
||||
if flagSource != "" {
|
||||
input["source"] = flagSource
|
||||
}
|
||||
|
||||
if flagIdentifiedOn != "" {
|
||||
input["identifiedOn"] = flagIdentifiedOn
|
||||
}
|
||||
|
||||
if flagRootCause != "" {
|
||||
input["rootCause"] = flagRootCause
|
||||
}
|
||||
|
||||
if flagCorrectiveAction != "" {
|
||||
input["correctiveAction"] = flagCorrectiveAction
|
||||
}
|
||||
|
||||
if flagDueDate != "" {
|
||||
input["dueDate"] = flagDueDate
|
||||
}
|
||||
|
||||
if flagRiskID != "" {
|
||||
input["riskId"] = flagRiskID
|
||||
}
|
||||
|
||||
if flagEffectivenessChk != "" {
|
||||
input["effectivenessCheck"] = flagEffectivenessChk
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
|
||||
var confirmed bool
|
||||
|
||||
err := huh.NewConfirm().
|
||||
Title(fmt.Sprintf("Delete finding %s?", args[0])).
|
||||
Value(&confirmed).
|
||||
@@ -52,6 +53,7 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !confirmed {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
if err := cmdutil.ValidateEnum("order-by", flagOrderBy, []string{"CREATED_AT", "REFERENCE_ID", "IDENTIFIED_ON", "DUE_DATE", "STATUS", "PRIORITY", "KIND"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
variables["orderBy"] = map[string]any{
|
||||
"field": flagOrderBy,
|
||||
"direction": flagOrderDir,
|
||||
@@ -117,12 +118,15 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
|
||||
filter := map[string]any{}
|
||||
|
||||
if flagKind != "" {
|
||||
if err := cmdutil.ValidateEnum("kind", flagKind, []string{"MINOR_NONCONFORMITY", "MAJOR_NONCONFORMITY", "OBSERVATION", "EXCEPTION"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filter["kind"] = flagKind
|
||||
}
|
||||
|
||||
if len(filter) > 0 {
|
||||
variables["filter"] = filter
|
||||
}
|
||||
@@ -142,12 +146,15 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
if err := json.Unmarshal(data, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Node == nil {
|
||||
return nil, fmt.Errorf("organization %s not found", flagOrganization)
|
||||
}
|
||||
|
||||
if resp.Node.Typename != "Organization" {
|
||||
return nil, fmt.Errorf("expected Organization node, got %s", resp.Node.Typename)
|
||||
}
|
||||
|
||||
return &resp.Node.Findings, nil
|
||||
},
|
||||
)
|
||||
@@ -170,6 +177,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
if fi.DueDate != nil {
|
||||
dueDate = cmdutil.FormatTime(*fi.DueDate)
|
||||
}
|
||||
|
||||
rows = append(rows, []string{
|
||||
fi.ID,
|
||||
fi.ReferenceID,
|
||||
|
||||
@@ -96,6 +96,7 @@ func NewCmdPublish(f *cmdutil.Factory) *cobra.Command {
|
||||
if flagOrg == "" {
|
||||
flagOrg = hc.Organization
|
||||
}
|
||||
|
||||
if flagOrg == "" {
|
||||
return fmt.Errorf("organization is required: pass --org or run `prb auth login`")
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["description"] = flagDescription
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("source") {
|
||||
if flagSource == "" {
|
||||
input["source"] = nil
|
||||
@@ -105,6 +106,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["source"] = flagSource
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("identified-on") {
|
||||
if flagIdentifiedOn == "" {
|
||||
input["identifiedOn"] = nil
|
||||
@@ -112,6 +114,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["identifiedOn"] = flagIdentifiedOn
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("root-cause") {
|
||||
if flagRootCause == "" {
|
||||
input["rootCause"] = nil
|
||||
@@ -119,6 +122,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["rootCause"] = flagRootCause
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("corrective-action") {
|
||||
if flagCorrectiveAction == "" {
|
||||
input["correctiveAction"] = nil
|
||||
@@ -126,9 +130,11 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["correctiveAction"] = flagCorrectiveAction
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("owner-id") {
|
||||
input["ownerId"] = flagOwnerID
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("due-date") {
|
||||
if flagDueDate == "" {
|
||||
input["dueDate"] = nil
|
||||
@@ -136,18 +142,23 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["dueDate"] = flagDueDate
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("status") {
|
||||
if err := cmdutil.ValidateEnum("status", flagStatus, []string{"OPEN", "IN_PROGRESS", "CLOSED", "RISK_ACCEPTED", "MITIGATED", "FALSE_POSITIVE"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
input["status"] = flagStatus
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("priority") {
|
||||
if err := cmdutil.ValidateEnum("priority", flagPriority, []string{"LOW", "MEDIUM", "HIGH"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
input["priority"] = flagPriority
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("risk-id") {
|
||||
if flagRiskID == "" {
|
||||
input["riskId"] = nil
|
||||
@@ -155,6 +166,7 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
input["riskId"] = flagRiskID
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("effectiveness-check") {
|
||||
if flagEffectivenessChk == "" {
|
||||
input["effectivenessCheck"] = nil
|
||||
|
||||
@@ -156,24 +156,31 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command {
|
||||
if n.Description != nil && *n.Description != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Description:"), *n.Description)
|
||||
}
|
||||
|
||||
if n.Source != nil && *n.Source != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Source:"), *n.Source)
|
||||
}
|
||||
|
||||
if n.IdentifiedOn != nil && *n.IdentifiedOn != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Identified On:"), cmdutil.FormatTime(*n.IdentifiedOn))
|
||||
}
|
||||
|
||||
if n.DueDate != nil && *n.DueDate != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Due Date:"), cmdutil.FormatTime(*n.DueDate))
|
||||
}
|
||||
|
||||
if n.RootCause != nil && *n.RootCause != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Root Cause:"), *n.RootCause)
|
||||
}
|
||||
|
||||
if n.CorrectiveAction != nil && *n.CorrectiveAction != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Corrective Action:"), *n.CorrectiveAction)
|
||||
}
|
||||
|
||||
if n.Risk != nil {
|
||||
_, _ = fmt.Fprintf(out, "%s%s (%s)\n", label.Render("Risk:"), n.Risk.Name, n.Risk.ID)
|
||||
}
|
||||
|
||||
if n.EffectivenessCheck != nil && *n.EffectivenessCheck != "" {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Effectiveness Check:"), *n.EffectivenessCheck)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user