core/commands2: Use Option constructors in commands
Matt Bell committed
Nov 10, 2014 at 17:10 UTC
8ee3e996ccfcdc4741fa737738ea692e18e1c4c0
7 files changed
+16
-34
cmd/ipfs2/init.go
+4
-8
@@ -20,14 +20,10 @@ var initCmd = &cmds.Command{
20
`,
21
22
Options: []cmds.Option{
23
- cmds.Option{[]string{"bits", "b"}, cmds.Int,
24
- "Number of bits to use in the generated RSA private key (defaults to 4096)"},
25
- cmds.Option{[]string{"passphrase", "p"}, cmds.String,
26
- "Passphrase for encrypting the private key"},
27
- cmds.Option{[]string{"force", "f"}, cmds.Bool,
28
- "Overwrite existing config (if it exists)"},
29
- cmds.Option{[]string{"datastore", "d"}, cmds.String,
30
- "Location for the IPFS data store"},
23
+ cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key (defaults to 4096)"),
24
+ cmds.StringOption("passphrase", "p", "Passphrase for encrypting the private key"),
25
+ cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
26
+ cmds.StringOption("datastore", "d", "Location for the IPFS data store"),
27
},
28
Run: func(req cmds.Request) (interface{}, error) {
29
core/commands2/add.go
+1
-1
@@ -23,7 +23,7 @@ type AddOutput struct {
23
24
var addCmd = &cmds.Command{
25
Options: []cmds.Option{
26
- cmds.Option{[]string{"recursive", "r"}, cmds.Bool, "Must be specified when adding directories"},
26
+ cmds.BoolOption("recursive", "r", "Must be specified when adding directories"),
27
},
28
Arguments: []cmds.Argument{
29
cmds.Argument{"file", cmds.ArgFile, true, true, "The path to a file to be added to IPFS"},
core/commands2/mount_unix.go
+2
-7
@@ -24,16 +24,11 @@ not be listable, as it is virtual. Accessing known paths directly.
24
`,
25
26
Options: []cmds.Option{
27
-
28
- // TODO text: specify a mountpoint for ipfs
27
// TODO longform
30
- cmds.Option{[]string{"f"}, cmds.String,
31
- "The path where IPFS should be mounted\n(default is '/ipfs')"},
28
+ cmds.StringOption("f", "The path where IPFS should be mounted\n(default is '/ipfs')"),
29
33
- // TODO text: specify a mountpoint for ipns
30
// TODO longform
35
- cmds.Option{[]string{"n"}, cmds.String,
36
- "The path where IPNS should be mounted\n(default is '/ipns')"},
31
+ cmds.StringOption("n", "The path where IPNS should be mounted\n(default is '/ipns')"),
32
},
33
Run: func(req cmds.Request) (interface{}, error) {
34
ctx := req.Context()
core/commands2/pin.go
+2
-4
@@ -29,8 +29,7 @@ on disk.
29
"Path to object(s) to be pinned"},
30
},
31
Options: []cmds.Option{
32
- cmds.Option{[]string{"recursive", "r"}, cmds.Bool,
33
- "Recursively pin the object linked to by the specified object(s)"},
32
+ cmds.BoolOption("recursive", "r", "Recursively pin the object linked to by the specified object(s)"),
33
},
34
Run: func(req cmds.Request) (interface{}, error) {
35
n := req.Context().Node
@@ -65,8 +64,7 @@ collected if needed.
64
"Path to object(s) to be unpinned"},
65
},
66
Options: []cmds.Option{
68
- cmds.Option{[]string{"recursive", "r"}, cmds.Bool,
69
- "Recursively unpin the object linked to by the specified object(s)"},
67
+ cmds.BoolOption("recursive", "r", "Recursively unpin the object linked to by the specified object(s)"),
68
},
69
Run: func(req cmds.Request) (interface{}, error) {
70
n := req.Context().Node
core/commands2/refs.go
+2
-4
@@ -29,10 +29,8 @@ Note: list all refs recursively with -r.`,
29
"Path to the object(s) to list refs from"},
30
},
31
Options: []cmds.Option{
32
- cmds.Option{[]string{"unique", "u"}, cmds.Bool,
33
- "Omit duplicate refs from output"},
34
- cmds.Option{[]string{"recursive", "r"}, cmds.Bool,
35
- "Recursively list links of child nodes"},
32
+ cmds.BoolOption("unique", "u", "Omit duplicate refs from output"),
33
+ cmds.BoolOption("recursive", "r", "Recursively list links of child nodes"),
34
},
35
Run: func(req cmds.Request) (interface{}, error) {
36
n := req.Context().Node
core/commands2/root.go
+4
-8
@@ -44,14 +44,10 @@ Use "ipfs <command> --help" for more information about a command.
44
`,
45
46
Options: []cmds.Option{
47
- cmds.Option{[]string{"config", "c"}, cmds.String,
48
- "Path to the configuration file to use"},
49
- cmds.Option{[]string{"debug", "D"}, cmds.Bool,
50
- "Operate in debug mode"},
51
- cmds.Option{[]string{"help", "h"}, cmds.Bool,
52
- "Show the command help text"},
53
- cmds.Option{[]string{"local", "L"}, cmds.Bool,
54
- "Run the command locally, instead of using the daemon"},
47
+ cmds.StringOption("config", "c", "Path to the configuration file to use"),
48
+ cmds.BoolOption("debug", "D", "Operate in debug mode"),
49
+ cmds.BoolOption("help", "h", "Show the command help text"),
50
+ cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
51
},
52
}
53
core/commands2/version.go
+1
-2
@@ -17,8 +17,7 @@ var versionCmd = &cmds.Command{
17
`,
18
19
Options: []cmds.Option{
20
- cmds.Option{[]string{"number", "n"}, cmds.Bool,
21
- "Only output the version number"},
20
+ cmds.BoolOption("number", "n", "Only output the version number"),
21
},
22
Run: func(req cmds.Request) (interface{}, error) {
23
return &VersionOutput{