diff --git a/cmd/wsh/cmd/wshcmd-edit.go b/cmd/wsh/cmd/wshcmd-editor.go similarity index 85% rename from cmd/wsh/cmd/wshcmd-edit.go rename to cmd/wsh/cmd/wshcmd-editor.go index bdb051740..4e2fb7643 100644 --- a/cmd/wsh/cmd/wshcmd-edit.go +++ b/cmd/wsh/cmd/wshcmd-editor.go @@ -16,33 +16,21 @@ import ( var editMagnified bool -var editCmd = &cobra.Command{ - Use: "edit", - Short: "edit a file", +var editorCmd = &cobra.Command{ + Use: "editor", + Short: "edit a file (blocks until editor is closed)", Args: cobra.ExactArgs(1), - Run: editRun, + Run: editorRun, PreRunE: preRunSetupRpcClient, } func init() { editCmd.Flags().BoolVarP(&editMagnified, "magnified", "m", false, "open view in magnified mode") - rootCmd.AddCommand(editCmd) + rootCmd.AddCommand(editorCmd) } -func editRun(cmd *cobra.Command, args []string) { +func editorRun(cmd *cobra.Command, args []string) { fileArg := args[0] - wshCmd := wshrpc.CommandCreateBlockData{ - BlockDef: &waveobj.BlockDef{ - Meta: map[string]any{ - waveobj.MetaKey_View: "preview", - waveobj.MetaKey_File: fileArg, - }, - }, - Magnified: editMagnified, - } - if RpcContext.Conn != "" { - wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = RpcContext.Conn - } absFile, err := filepath.Abs(fileArg) if err != nil { WriteStderr("[error] getting absolute path: %v\n", err) @@ -57,6 +45,19 @@ func editRun(cmd *cobra.Command, args []string) { WriteStderr("[error] getting file info: %v\n", err) return } + wshCmd := wshrpc.CommandCreateBlockData{ + BlockDef: &waveobj.BlockDef{ + Meta: map[string]any{ + waveobj.MetaKey_View: "preview", + waveobj.MetaKey_File: absFile, + waveobj.MetaKey_Edit: true, + }, + }, + Magnified: editMagnified, + } + if RpcContext.Conn != "" { + wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = RpcContext.Conn + } blockRef, err := wshclient.CreateBlockCommand(RpcClient, wshCmd, &wshrpc.RpcOpts{Timeout: 2000}) if err != nil { WriteStderr("[error] running view command: %v\r\n", err) diff --git a/cmd/wsh/cmd/wshcmd-view.go b/cmd/wsh/cmd/wshcmd-view.go index 40e4a82e7..2d6bdf09e 100644 --- a/cmd/wsh/cmd/wshcmd-view.go +++ b/cmd/wsh/cmd/wshcmd-view.go @@ -18,7 +18,15 @@ var viewMagnified bool var viewCmd = &cobra.Command{ Use: "view", - Short: "preview a file or directory", + Short: "preview/edit a file or directory", + Args: cobra.ExactArgs(1), + Run: viewRun, + PreRunE: preRunSetupRpcClient, +} + +var editCmd = &cobra.Command{ + Use: "edit", + Short: "preview/edit a file or directory", Args: cobra.ExactArgs(1), Run: viewRun, PreRunE: preRunSetupRpcClient, @@ -27,6 +35,7 @@ var viewCmd = &cobra.Command{ func init() { viewCmd.Flags().BoolVarP(&viewMagnified, "magnified", "m", false, "open view in magnified mode") rootCmd.AddCommand(viewCmd) + rootCmd.AddCommand(editCmd) } func viewRun(cmd *cobra.Command, args []string) { @@ -67,6 +76,9 @@ func viewRun(cmd *cobra.Command, args []string) { }, Magnified: viewMagnified, } + if cmd.Use == "edit" { + wshCmd.BlockDef.Meta[waveobj.MetaKey_Edit] = true + } if conn != "" { wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = conn }