forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into nasdf/refactor/logging
- Loading branch information
Showing
40 changed files
with
2,086 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.