mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
wsh editconfig (#1243)
This commit is contained in:
parent
cd0e2949ee
commit
d5297cc5d4
58
cmd/wsh/cmd/wshcmd-editconfig.go
Normal file
58
cmd/wsh/cmd/wshcmd-editconfig.go
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -14,36 +15,59 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var versionVerbose bool
|
var versionVerbose bool
|
||||||
|
var versionJSON bool
|
||||||
|
|
||||||
// versionCmd represents the version command
|
// versionCmd represents the version command
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version [-v]",
|
Use: "version [-v] [--json]",
|
||||||
Short: "Print the version number of wsh",
|
Short: "Print the version number of wsh",
|
||||||
RunE: runVersionCmd,
|
RunE: runVersionCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
versionCmd.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "Display full version information")
|
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)
|
rootCmd.AddCommand(versionCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runVersionCmd(cmd *cobra.Command, args []string) error {
|
func runVersionCmd(cmd *cobra.Command, args []string) error {
|
||||||
if !versionVerbose {
|
if !versionVerbose && !versionJSON {
|
||||||
WriteStdout("wsh v%s\n", wavebase.WaveVersion)
|
WriteStdout("wsh v%s\n", wavebase.WaveVersion)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := preRunSetupRpcClient(cmd, args)
|
err := preRunSetupRpcClient(cmd, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := wshclient.WaveInfoCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
|
resp, err := wshclient.WaveInfoCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
updateChannel, err := wshclient.GetUpdateChannelCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000, Route: wshutil.ElectronRoute})
|
updateChannel, err := wshclient.GetUpdateChannelCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000, Route: wshutil.ElectronRoute})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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("v%s (%s)\n", resp.Version, resp.BuildTime)
|
||||||
fmt.Printf("configdir: %s\n", resp.ConfigDir)
|
fmt.Printf("configdir: %s\n", resp.ConfigDir)
|
||||||
fmt.Printf("datadir: %s\n", resp.DataDir)
|
fmt.Printf("datadir: %s\n", resp.DataDir)
|
||||||
|
Loading…
Reference in New Issue
Block a user