mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
remove blockid from the regular args, use an optional -b (#973)
This commit is contained in:
parent
9d4df934c9
commit
26fcbe0f0f
@ -11,7 +11,6 @@ import (
|
||||
var deleteBlockCmd = &cobra.Command{
|
||||
Use: "deleteblock",
|
||||
Short: "delete a block",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: deleteBlockRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
@ -21,11 +20,7 @@ func init() {
|
||||
}
|
||||
|
||||
func deleteBlockRun(cmd *cobra.Command, args []string) {
|
||||
oref := args[0]
|
||||
if oref == "" {
|
||||
WriteStderr("[error] oref is required\n")
|
||||
return
|
||||
}
|
||||
oref := blockArg
|
||||
err := validateEasyORef(oref)
|
||||
if err != nil {
|
||||
WriteStderr("[error]%v\n", err)
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
)
|
||||
|
||||
var getMetaCmd = &cobra.Command{
|
||||
Use: "getmeta {blockid|blocknum|this} [key]",
|
||||
Use: "getmeta [key]",
|
||||
Short: "get metadata for an entity",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
Run: getMetaRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
@ -24,7 +24,7 @@ func init() {
|
||||
}
|
||||
|
||||
func getMetaRun(cmd *cobra.Command, args []string) {
|
||||
oref := args[0]
|
||||
oref := blockArg
|
||||
if oref == "" {
|
||||
WriteStderr("[error] oref is required")
|
||||
return
|
||||
@ -44,8 +44,8 @@ func getMetaRun(cmd *cobra.Command, args []string) {
|
||||
WriteStderr("[error] getting metadata: %v\n", err)
|
||||
return
|
||||
}
|
||||
if len(args) > 1 {
|
||||
val, ok := resp[args[1]]
|
||||
if len(args) > 0 {
|
||||
val, ok := resp[args[0]]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
var readFileCmd = &cobra.Command{
|
||||
Use: "readfile",
|
||||
Short: "read a blockfile",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: runReadFile,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ var WrappedStdin io.Reader = os.Stdin
|
||||
var RpcClient *wshutil.WshRpc
|
||||
var RpcContext wshrpc.RpcContext
|
||||
var UsingTermWshMode bool
|
||||
var blockArg string
|
||||
|
||||
func extraShutdownFn() {
|
||||
if usingHtmlMode {
|
||||
@ -174,6 +175,7 @@ func Execute() {
|
||||
wshutil.DoShutdown("", 0, false)
|
||||
}
|
||||
}()
|
||||
rootCmd.PersistentFlags().StringVarP(&blockArg, "block", "b", "this", "for commands which require a block id")
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
wshutil.DoShutdown("", 1, true)
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
var setMetaCmd = &cobra.Command{
|
||||
Use: "setmeta {blockid|blocknum|this} key=value ...",
|
||||
Short: "set metadata for an entity",
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: setMetaRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
@ -64,8 +64,8 @@ func parseMetaSets(metaSets []string) (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
func setMetaRun(cmd *cobra.Command, args []string) {
|
||||
oref := args[0]
|
||||
metaSetsStrs := args[1:]
|
||||
oref := blockArg
|
||||
metaSetsStrs := args[:]
|
||||
if oref == "" {
|
||||
WriteStderr("[error] oref is required\n")
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user