Skip to content

Commit

Permalink
Merge branch 'develop' into nasdf/refactor/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdf authored Mar 18, 2024
2 parents ee68bc9 + c74a6f7 commit b525ef1
Show file tree
Hide file tree
Showing 40 changed files with 2,086 additions and 354 deletions.
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func NewDefraCommand() *cobra.Command {
MakeCollectionUpdateCommand(),
MakeCollectionCreateCommand(),
MakeCollectionDescribeCommand(),
MakeCollectionPatchCommand(),
)

client := MakeClientCommand()
Expand Down
69 changes: 69 additions & 0 deletions cli/collection_patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cli

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
)

func MakeCollectionPatchCommand() *cobra.Command {
var patchFile string
var cmd = &cobra.Command{
Use: "patch [patch]",
Short: "Patch existing collection descriptions",
Long: `Patch existing collection descriptions.
Uses JSON Patch to modify collection descriptions.
Example: patch from an argument string:
defradb client collection patch '[{ "op": "add", "path": "...", "value": {...} }]'
Example: patch from file:
defradb client collection patch -p patch.json
Example: patch from stdin:
cat patch.json | defradb client collection patch -
To learn more about the DefraDB GraphQL Schema Language, refer to https://docs.source.network.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
store := mustGetContextStore(cmd)

var patch string
switch {
case patchFile != "":
data, err := os.ReadFile(patchFile)
if err != nil {
return err
}
patch = string(data)
case len(args) > 0 && args[0] == "-":
data, err := io.ReadAll(cmd.InOrStdin())
if err != nil {
return err
}
patch = string(data)
case len(args) == 1:
patch = args[0]
default:
return fmt.Errorf("patch cannot be empty")
}

return store.PatchCollection(cmd.Context(), patch)
},
}
cmd.Flags().StringVarP(&patchFile, "patch-file", "p", "", "File to load a patch from")
return cmd
}
2 changes: 1 addition & 1 deletion cli/schema_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Example: patch from an argument string:
defradb client schema patch '[{ "op": "add", "path": "...", "value": {...} }]' '{"lenses": [...'
Example: patch from file:
defradb client schema patch -f patch.json
defradb client schema patch -p patch.json
Example: patch from stdin:
cat patch.json | defradb client schema patch -
Expand Down
Loading

0 comments on commit b525ef1

Please sign in to comment.