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
No related branches found
No related tags found
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.`, ...@@ -55,7 +55,7 @@ Change UUID must be specified as positional argument.`,
pterm.Error.Println(err) pterm.Error.Println(err)
} }
for _, r := range resp.GetResponses() { 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`, ...@@ -56,7 +56,7 @@ Change UUID must be specified as positional argument`,
pterm.Error.Println(err) pterm.Error.Println(err)
} }
for _, r := range resp.GetResponses() { 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 ( ...@@ -39,6 +39,7 @@ import (
) )
var replace bool var replace bool
var forcePush bool
// deviceSetCmd represents the set command // deviceSetCmd represents the set command
var deviceSetCmd = &cobra.Command{ var deviceSetCmd = &cobra.Command{
...@@ -73,15 +74,16 @@ To enable replacing behaviour (destructive!), set the --replace flag."`, ...@@ -73,15 +74,16 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
args[1], args[1],
args[2], args[2],
) )
if err != nil { if err != nil {
spinner.Fail(err) spinner.Fail(err)
} }
for _, r := range resp.GetResponses() { 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())
spinner.Success("A change for Device: ", did.String(), "has been created -> Change ID: ", r.GetId()) if forcePush {
} else { executeFunc("change commit " + r.GetId())
spinner.Fail("An error occured while creating a path set request for Device with ID: ", r.GetId(), r.GetStatus()) executeFunc("change confirm " + r.GetId())
} }
} }
}, },
...@@ -90,4 +92,5 @@ To enable replacing behaviour (destructive!), set the --replace flag."`, ...@@ -90,4 +92,5 @@ To enable replacing behaviour (destructive!), set the --replace flag."`,
func init() { func init() {
deviceCmd.AddCommand(deviceSetCmd) deviceCmd.AddCommand(deviceSetCmd)
deviceSetCmd.Flags().BoolVarP(&replace, "replace", "r", false, "enables replace behaviour") 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. ...@@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"fmt"
"os" "os"
"strings" "strings"
...@@ -104,7 +103,7 @@ func executeFunc(s string) { ...@@ -104,7 +103,7 @@ func executeFunc(s string) {
err := rootCmd.Execute() err := rootCmd.Execute()
if err != nil { 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 ...@@ -541,7 +541,9 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
return nil, handleRPCError(labels, err) 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) cuid, err := uuid.Parse(r.Cuid)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -563,15 +565,16 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList ...@@ -563,15 +565,16 @@ func (p pndServer) SetChangeList(ctx context.Context, request *ppb.SetChangeList
Param: r.Op, Param: r.Op,
} }
} }
responses[i] = &ppb.SetResponse{
Id: cuid.String(),
Status: ppb.Status_STATUS_OK,
}
} }
return &ppb.SetChangeListResponse{ return &ppb.SetChangeListResponse{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK, Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{ Responses: responses,
{
Status: ppb.Status_STATUS_OK,
},
},
}, nil }, nil
} }
...@@ -589,27 +592,29 @@ func (p pndServer) SetPathList(ctx context.Context, request *ppb.SetPathListRequ ...@@ -589,27 +592,29 @@ func (p pndServer) SetPathList(ctx context.Context, request *ppb.SetPathListRequ
return nil, handleRPCError(labels, err) 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) did, err := uuid.Parse(r.Did)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err) return nil, status.Errorf(codes.Aborted, "%v", err)
} }
// TODO: Return CUID in API cid, err := pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
_, err = pnd.ChangeOND(did, r.ApiOp, r.Path, r.Value)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return nil, status.Errorf(codes.Aborted, "%v", err) return nil, status.Errorf(codes.Aborted, "%v", err)
} }
responses[i] = &ppb.SetResponse{
Status: ppb.Status_STATUS_OK,
Id: cid.String(),
}
} }
return &ppb.SetPathListResponse{ return &ppb.SetPathListResponse{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Status: ppb.Status_STATUS_OK, Status: ppb.Status_STATUS_OK,
Responses: []*ppb.SetResponse{ Responses: responses,
{
Status: ppb.Status_STATUS_OK,
},
},
}, nil }, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment