Skip to content

Commit 4999024

Browse files
committed
record: accept json input over stdin
when argument file path is `-`, json data is read from stdin instead of a file on disk. Signed-off-by: oppiliappan <[email protected]>
1 parent 91924ad commit 4999024

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

record.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"os"
89

910
"github.com/bluesky-social/indigo/api/agnostic"
@@ -26,7 +27,7 @@ var cmdRecord = &cli.Command{
2627
&cli.Command{
2728
Name: "create",
2829
Usage: "create record from JSON",
29-
ArgsUsage: `<file>`,
30+
ArgsUsage: `<file|->`,
3031
Flags: []cli.Flag{
3132
&cli.StringFlag{
3233
Name: "rkey",
@@ -204,7 +205,7 @@ func runRecordList(ctx context.Context, cmd *cli.Command) error {
204205
func runRecordCreate(ctx context.Context, cmd *cli.Command) error {
205206
recordPath := cmd.Args().First()
206207
if recordPath == "" {
207-
return fmt.Errorf("need to provide file path as an argument")
208+
return fmt.Errorf("need to provide file path or '-' for stdin as an argument")
208209
}
209210

210211
xrpcc, err := loadAuthClient(ctx)
@@ -214,7 +215,12 @@ func runRecordCreate(ctx context.Context, cmd *cli.Command) error {
214215
return err
215216
}
216217

217-
recordBytes, err := os.ReadFile(recordPath)
218+
var recordBytes []byte
219+
if recordPath == "-" {
220+
recordBytes, err = io.ReadAll(os.Stdin)
221+
} else {
222+
recordBytes, err = os.ReadFile(recordPath)
223+
}
218224
if err != nil {
219225
return err
220226
}

0 commit comments

Comments
 (0)