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