From b4582fcaffa1cf95c1effb77971cd00d8bf641d5 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Fri, 4 Oct 2024 12:35:15 -0700 Subject: [PATCH] implement wsh createblock (#961) --- cmd/wsh/cmd/wshcmd-createblock.go | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 cmd/wsh/cmd/wshcmd-createblock.go diff --git a/cmd/wsh/cmd/wshcmd-createblock.go b/cmd/wsh/cmd/wshcmd-createblock.go new file mode 100644 index 000000000..bef912b9b --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-createblock.go @@ -0,0 +1,54 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" +) + +var createBlockMagnified bool + +var createBlockCmd = &cobra.Command{ + Use: "createblock viewname key=value ...", + Short: "create a new block", + Args: cobra.MinimumNArgs(1), + RunE: createBlockRun, + PreRunE: preRunSetupRpcClient, + Hidden: true, +} + +func init() { + createBlockCmd.Flags().BoolVarP(&createBlockMagnified, "magnified", "m", false, "create block in magnified mode") + rootCmd.AddCommand(createBlockCmd) +} + +func createBlockRun(cmd *cobra.Command, args []string) error { + viewName := args[0] + var metaSetStrs []string + if len(args) > 1 { + metaSetStrs = args[1:] + } + meta, err := parseMetaSets(metaSetStrs) + if err != nil { + return err + } + meta["view"] = viewName + data := wshrpc.CommandCreateBlockData{ + BlockDef: &waveobj.BlockDef{ + Meta: meta, + }, + Magnified: createBlockMagnified, + } + oref, err := wshclient.CreateBlockCommand(RpcClient, data, nil) + if err != nil { + return fmt.Errorf("create block failed: %v", err) + } + fmt.Printf("created block %s\n", oref.OID) + return nil +}