Skip to content

Commit 26fcbe0

Browse files
authored
remove blockid from the regular args, use an optional -b (#973)
1 parent 9d4df93 commit 26fcbe0

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

cmd/wsh/cmd/wshcmd-deleteblock.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
var deleteBlockCmd = &cobra.Command{
1212
Use: "deleteblock",
1313
Short: "delete a block",
14-
Args: cobra.ExactArgs(1),
1514
Run: deleteBlockRun,
1615
PreRunE: preRunSetupRpcClient,
1716
}
@@ -21,11 +20,7 @@ func init() {
2120
}
2221

2322
func deleteBlockRun(cmd *cobra.Command, args []string) {
24-
oref := args[0]
25-
if oref == "" {
26-
WriteStderr("[error] oref is required\n")
27-
return
28-
}
23+
oref := blockArg
2924
err := validateEasyORef(oref)
3025
if err != nil {
3126
WriteStderr("[error]%v\n", err)

cmd/wsh/cmd/wshcmd-getmeta.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
)
1313

1414
var getMetaCmd = &cobra.Command{
15-
Use: "getmeta {blockid|blocknum|this} [key]",
15+
Use: "getmeta [key]",
1616
Short: "get metadata for an entity",
17-
Args: cobra.RangeArgs(1, 2),
17+
Args: cobra.RangeArgs(0, 1),
1818
Run: getMetaRun,
1919
PreRunE: preRunSetupRpcClient,
2020
}
@@ -24,7 +24,7 @@ func init() {
2424
}
2525

2626
func getMetaRun(cmd *cobra.Command, args []string) {
27-
oref := args[0]
27+
oref := blockArg
2828
if oref == "" {
2929
WriteStderr("[error] oref is required")
3030
return
@@ -44,8 +44,8 @@ func getMetaRun(cmd *cobra.Command, args []string) {
4444
WriteStderr("[error] getting metadata: %v\n", err)
4545
return
4646
}
47-
if len(args) > 1 {
48-
val, ok := resp[args[1]]
47+
if len(args) > 0 {
48+
val, ok := resp[args[0]]
4949
if !ok {
5050
return
5151
}

cmd/wsh/cmd/wshcmd-readfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var readFileCmd = &cobra.Command{
1515
Use: "readfile",
1616
Short: "read a blockfile",
17-
Args: cobra.ExactArgs(2),
17+
Args: cobra.ExactArgs(1),
1818
Run: runReadFile,
1919
PreRunE: preRunSetupRpcClient,
2020
}

cmd/wsh/cmd/wshcmd-root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var WrappedStdin io.Reader = os.Stdin
3535
var RpcClient *wshutil.WshRpc
3636
var RpcContext wshrpc.RpcContext
3737
var UsingTermWshMode bool
38+
var blockArg string
3839

3940
func extraShutdownFn() {
4041
if usingHtmlMode {
@@ -174,6 +175,7 @@ func Execute() {
174175
wshutil.DoShutdown("", 0, false)
175176
}
176177
}()
178+
rootCmd.PersistentFlags().StringVarP(&blockArg, "block", "b", "this", "for commands which require a block id")
177179
err := rootCmd.Execute()
178180
if err != nil {
179181
wshutil.DoShutdown("", 1, true)

cmd/wsh/cmd/wshcmd-setmeta.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var setMetaCmd = &cobra.Command{
1717
Use: "setmeta {blockid|blocknum|this} key=value ...",
1818
Short: "set metadata for an entity",
19-
Args: cobra.MinimumNArgs(2),
19+
Args: cobra.MinimumNArgs(1),
2020
Run: setMetaRun,
2121
PreRunE: preRunSetupRpcClient,
2222
}
@@ -64,8 +64,8 @@ func parseMetaSets(metaSets []string) (map[string]interface{}, error) {
6464
}
6565

6666
func setMetaRun(cmd *cobra.Command, args []string) {
67-
oref := args[0]
68-
metaSetsStrs := args[1:]
67+
oref := blockArg
68+
metaSetsStrs := args[:]
6969
if oref == "" {
7070
WriteStderr("[error] oref is required\n")
7171
return

0 commit comments

Comments
 (0)