Skip to content
Snippets Groups Projects
Commit 3df61a46 authored by Malte Bauch's avatar Malte Bauch Committed by Fabian Seidl
Browse files

Resolve "Allow to force push a SET from within the CLI"


See merge request !310

Co-authored-by: default avatarMalte Bauch <malte.bauch@extern.h-da.de>
parent 124c62ec
Branches
Tags
2 merge requests!310Resolve "Allow to force push a SET from within the CLI",!264WIP: Develop
Pipeline #101055 passed
......@@ -55,7 +55,7 @@ Change UUID must be specified as positional argument.`,
pterm.Error.Println(err)
}
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
pterm.Info.Printfln("Change with ID: %s has been committed.", r.GetId())
}
},
}
......
......@@ -56,7 +56,7 @@ Change UUID must be specified as positional argument`,
pterm.Error.Println(err)
}
for _, r := range resp.GetResponses() {
pterm.Info.Println(r.String())
pterm.Info.Printfln("Change with ID: %s has been confirmed.", r.GetId())
}
},
}
......
......@@ -39,6 +39,7 @@ import (
)
var replace bool
var forcePush bool
// deviceSetCmd represents the set command
var deviceSetCmd = &cobra.Command{
......@@ -73,15 +74,16 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
args[1],
args[2],
)
if err != nil {
spinner.Fail(err)
}
for _, r := range resp.GetResponses() {
if r.Status == ppb.Status_STATUS_OK {
spinner.Success("A change for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
} else {
spinner.Fail("An error occured while creating a path set request for Device with ID: ", r.GetId(), r.GetStatus())
spinner.Success("A change for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
if forcePush {
executeFunc("change commit " + r.GetId())
executeFunc("change confirm " + r.GetId())
}
}
},
......@@ -90,4 +92,5 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
func init() {
deviceCmd.AddCommand(deviceSetCmd)
deviceSetCmd.Flags().BoolVarP(&replace, "replace", "r", false, "enables replace behaviour")
deviceSetCmd.Flags().BoolVarP(&forcePush, "force-push", "f", false, "enables the possibility to instantly push the set without commit/confirm")
}
......@@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd
import (
"fmt"
"os"
"strings"
......@@ -104,7 +103,7 @@ func executeFunc(s string) {
err := rootCmd.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not execute:", err)
pterm.Error.Println("Could not execute:", err)
}
}
......
......@@ -541,7 +541,9 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
return nil, handleRPCError(labels, err)
}
for _, r := range request.Change {
responses := make([]*ppb.SetResponse, len(request.Change))
for i, r := range request.Change {
cuid, err := uuid.Parse(r.Cuid)
if err != nil {
log.Error(err)
......@@ -563,15 +565,16 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
Param: r.Op,
}
}
responses[i] = &ppb.SetResponse{
Id: cuid.String(),
Status: ppb.Status_STATUS_OK,
}
}
return &ppb.SetChangeListResponse{
Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{
{
Status: ppb.Status_STATUS_OK,
},
},
Responses: responses,
}, nil
}
......@@ -589,27 +592,29 @@ func (p pndServer) SetPathList(ctx context.Context, request *ppb.SetPathListRequ
return nil, handleRPCError(labels, err)
}
for _, r := range request.ChangeRequest {
responses := make([]*ppb.SetResponse, len(request.ChangeRequest))
for i, r := range request.ChangeRequest {
did, err := uuid.Parse(r.Did)
if err != nil {
log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err)
}
// TODO: Return CUID in API
_, err = pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
cid, err := pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
if err != nil {
log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err)
}
responses[i] = &ppb.SetResponse{
Status: ppb.Status_STATUS_OK,
Id: cid.String(),
}
}
return &ppb.SetPathListResponse{
Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{
{
Status: ppb.Status_STATUS_OK,
},
},
Responses: responses,
}, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment