Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions cmd/wsh/cmd/wshcmd-editconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"path/filepath"

"github.com/spf13/cobra"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
)

var editConfigCmd = &cobra.Command{
Use: "editconfig [configfile]",
Short: "edit Wave configuration files",
Long: "Edit Wave configuration files. Defaults to settings.json if no file specified. Common files: settings.json, presets.json, widgets.json",
Args: cobra.MaximumNArgs(1),
Run: editConfigRun,
PreRunE: preRunSetupRpcClient,
}

func init() {
rootCmd.AddCommand(editConfigCmd)
}

func editConfigRun(cmd *cobra.Command, args []string) {
// Get config directory from Wave info
resp, err := wshclient.WaveInfoCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
WriteStderr("[error] getting Wave info: %v\n", err)
return
}

configFile := "settings.json" // default
if len(args) > 0 {
configFile = args[0]
}

settingsFile := filepath.Join(resp.ConfigDir, configFile)

wshCmd := &wshrpc.CommandCreateBlockData{
BlockDef: &waveobj.BlockDef{
Meta: map[string]interface{}{
waveobj.MetaKey_View: "preview",
waveobj.MetaKey_File: settingsFile,
waveobj.MetaKey_Edit: true,
},
},
}

_, err = RpcClient.SendRpcRequest(wshrpc.Command_CreateBlock, wshCmd, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
WriteStderr("[error] opening config file: %v\n", err)
return
}
}
28 changes: 26 additions & 2 deletions cmd/wsh/cmd/wshcmd-version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"
Expand All @@ -14,36 +15,59 @@ import (
)

var versionVerbose bool
var versionJSON bool

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version [-v]",
Use: "version [-v] [--json]",
Short: "Print the version number of wsh",
RunE: runVersionCmd,
}

func init() {
versionCmd.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "Display full version information")
versionCmd.Flags().BoolVar(&versionJSON, "json", false, "Output version information in JSON format")
rootCmd.AddCommand(versionCmd)
}

func runVersionCmd(cmd *cobra.Command, args []string) error {
if !versionVerbose {
if !versionVerbose && !versionJSON {
WriteStdout("wsh v%s\n", wavebase.WaveVersion)
return nil
}

err := preRunSetupRpcClient(cmd, args)
if err != nil {
return err
}

resp, err := wshclient.WaveInfoCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
return err
}

updateChannel, err := wshclient.GetUpdateChannelCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000, Route: wshutil.ElectronRoute})
if err != nil {
return err
}

if versionJSON {
info := map[string]interface{}{
"version": resp.Version,
"buildtime": resp.BuildTime,
"configdir": resp.ConfigDir,
"datadir": resp.DataDir,
"updatechannel": updateChannel,
}
outBArr, err := json.MarshalIndent(info, "", " ")
if err != nil {
return fmt.Errorf("formatting version info: %v", err)
}
WriteStdout("%s\n", string(outBArr))
return nil
}

// Default verbose text output
fmt.Printf("v%s (%s)\n", resp.Version, resp.BuildTime)
fmt.Printf("configdir: %s\n", resp.ConfigDir)
fmt.Printf("datadir: %s\n", resp.DataDir)
Expand Down