本文整理汇总了Golang中github.com/ipfs/go-ipfs/commands.BoolOption函数的典型用法代码示例。如果您正苦于以下问题:Golang BoolOption函数的具体用法?Golang BoolOption怎么用?Golang BoolOption使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BoolOption函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CommandsCmd
// CommandsCmd takes in a root command,
// and returns a command that lists the subcommands in that root
func CommandsCmd(root *cmds.Command) *cmds.Command {
return &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List all available commands.",
ShortDescription: `Lists all available commands (and subcommands) and exits.`,
},
Options: []cmds.Option{
cmds.BoolOption(flagsOptionName, "f", "Show command flags"),
},
Run: func(req cmds.Request, res cmds.Response) {
showOptions, _, _ := req.Option(flagsOptionName).Bool()
rootCmd := cmd2outputCmd("ipfs", root, showOptions)
res.SetOutput(&rootCmd)
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
v := res.Output().(*Command)
buf := new(bytes.Buffer)
for _, s := range cmdPathStrings(v) {
buf.Write([]byte(s + "\n"))
}
return buf, nil
},
},
Type: Command{},
}
}
开发者ID:musha68k,项目名称:go-ipfs,代码行数:29,代码来源:commands.go
示例2: TestOptionParsing
func TestOptionParsing(t *testing.T) {
subCmd := &commands.Command{}
cmd := &commands.Command{
Options: []commands.Option{
commands.StringOption("string", "s", "a string"),
commands.BoolOption("bool", "b", "a bool"),
},
Subcommands: map[string]*commands.Command{
"test": subCmd,
},
}
testHelper := func(args string, expectedOpts kvs, expectedWords words, expectErr bool) {
_, opts, input, _, err := parseOpts(strings.Split(args, " "), cmd)
if expectErr {
if err == nil {
t.Errorf("Command line '%v' parsing should have failed", args)
}
} else if err != nil {
t.Errorf("Command line '%v' failed to parse: %v", args, err)
} else if !sameWords(input, expectedWords) || !sameKVs(opts, expectedOpts) {
t.Errorf("Command line '%v':\n parsed as %v %v\n instead of %v %v",
args, opts, input, expectedOpts, expectedWords)
}
}
testFail := func(args string) {
testHelper(args, kvs{}, words{}, true)
}
test := func(args string, expectedOpts kvs, expectedWords words) {
testHelper(args, expectedOpts, expectedWords, false)
}
test("-", kvs{}, words{"-"})
testFail("-b -b")
test("beep boop", kvs{}, words{"beep", "boop"})
test("test beep boop", kvs{}, words{"beep", "boop"})
testFail("-s")
test("-s foo", kvs{"s": "foo"}, words{})
test("-sfoo", kvs{"s": "foo"}, words{})
test("-s=foo", kvs{"s": "foo"}, words{})
test("-b", kvs{"b": ""}, words{})
test("-bs foo", kvs{"b": "", "s": "foo"}, words{})
test("-sb", kvs{"s": "b"}, words{})
test("-b foo", kvs{"b": ""}, words{"foo"})
test("--bool foo", kvs{"bool": ""}, words{"foo"})
testFail("--bool=foo")
testFail("--string")
test("--string foo", kvs{"string": "foo"}, words{})
test("--string=foo", kvs{"string": "foo"}, words{})
test("-- -b", kvs{}, words{"-b"})
test("foo -b", kvs{"b": ""}, words{"foo"})
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:54,代码来源:parse_test.go
示例3:
$ OBJ_A=QmegHcnrPgMwC7tBiMxChD54fgQMBUecNw9nE9UUU4x1bz
$ echo "different content" > foo/bar
$ ipfs add -r foo
...
added QmcmRptkSPWhptCttgHg27QNDmnV33wAJyUkCnAvqD3eCD foo
$ OBJ_B=QmcmRptkSPWhptCttgHg27QNDmnV33wAJyUkCnAvqD3eCD
$ ipfs object diff -v $OBJ_A $OBJ_B
changed "bar" from QmNgd5cz2jNftnAHBhcRUGdtiaMzb5Rhjqd4etondHHST8 to QmRfFVsjSXkhFxrfWnLpMae2M4GBVsry6VAuYYcji5MiZb
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("obj_a", true, false, "object to diff against"),
cmds.StringArg("obj_b", true, false, "object to diff"),
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Produce verbose output"),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
a := req.Arguments()[0]
b := req.Arguments()[1]
pa, err := path.ParsePath(a)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
开发者ID:Kubuxu,项目名称:go-ipfs,代码行数:31,代码来源:diff.go
示例4:
$ EMPTY_DIR=$(ipfs object new unixfs-dir)
$ BAR=$(echo "bar" | ipfs add -q)
$ ipfs object patch $EMPTY_DIR add-link foo $BAR
This takes an empty directory, and adds a link named 'foo' under it, pointing
to a file containing 'bar', and returns the hash of the new object.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("root", true, false, "The hash of the node to modify."),
cmds.StringArg("name", true, false, "Name of link to create."),
cmds.StringArg("ref", true, false, "IPFS object to add link to."),
},
Options: []cmds.Option{
cmds.BoolOption("create", "p", "Create intermediary nodes.").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
rootp, err := path.ParsePath(req.Arguments()[0])
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
root, err := core.Resolve(req.Context(), nd, rootp)
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:30,代码来源:patch.go
示例5:
> ipfs resolve -r /ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
Resolve the value of an IPFS DAG path:
> ipfs resolve /ipfs/QmeZy1fGbwgVSrqbfh9fKQrAWgeyRnj7h8fsHS1oy3k99x/beep/boop
/ipfs/QmYRMjyvAiHKN9UTi8Bzt1HUspmSRD8T8DwxfSMzLgBon1
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "The name to resolve.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if !n.OnlineMode() {
err := n.SetupOfflineRouting()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
开发者ID:thomas-gardner,项目名称:go-ipfs,代码行数:31,代码来源:resolve.go
示例6:
}
var addPinCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Pins objects to local storage.",
ShortDescription: `
Retrieves the object named by <ipfs-path> and stores it locally
on disk.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be pinned.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Recursively pin the object linked to by the specified object(s)."),
},
Type: PinOutput{},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
unlock := n.Blockstore.PinLock()
defer unlock()
// set recursive flag
recursive, found, err := req.Option("recursive").Bool()
if err != nil {
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:31,代码来源:pin.go
示例7:
}
return buf, nil
},
},
Type: addrMap{},
}
var swarmAddrsLocalCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List local addresses.",
ShortDescription: `
ipfs swarm addrs local lists all local addresses the node is listening on.
`,
},
Options: []cmds.Option{
cmds.BoolOption("id", "Show peer ID in addresses."),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if n.PeerHost == nil {
res.SetError(errNotOnline, cmds.ErrClient)
return
}
showid, _, _ := req.Option("id").Bool()
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:31,代码来源:swarm.go
示例8:
"gc": repoGcCmd,
},
}
var repoGcCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Perform a garbage collection sweep on the repo",
ShortDescription: `
'ipfs repo gc' is a plumbing command that will sweep the local
set of stored objects and remove ones that are not pinned in
order to reclaim hard disk space.
`,
},
Options: []cmds.Option{
cmds.BoolOption("quiet", "q", "Write minimal output"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
gcOutChan, err := corerepo.GarbageCollectAsync(n, req.Context())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
outChan := make(chan interface{})
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:31,代码来源:repo.go
示例9:
}
var bootstrapAddCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Add peers to the bootstrap list",
ShortDescription: `Outputs a list of peers that were added (that weren't already
in the bootstrap list).
` + bootstrapSecurityWarning,
},
Arguments: []cmds.Argument{
cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("default", "add default bootstrap nodes"),
},
Run: func(req cmds.Request, res cmds.Response) {
inputPeers, err := config.ParseBootstrapPeers(req.Arguments())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
defer r.Close()
开发者ID:rht,项目名称:ipget,代码行数:31,代码来源:bootstrap.go
示例10:
By default, the output will be stored at ./<ipfs-path>, but an alternate path
can be specified with '--output=<path>' or '-o=<path>'.
To output a TAR archive instead of unpacked files, use '--archive' or '-a'.
To compress the output with GZIP compression, use '--compress' or '-C'. You
may also specify the level of compression by specifying '-l=<1-9>'.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption("output", "o", "The path where output should be stored"),
cmds.BoolOption("archive", "a", "Output a TAR archive"),
cmds.BoolOption("compress", "C", "Compress the output with GZIP compression"),
cmds.IntOption("compression-level", "l", "The level of compression (1-9)"),
},
PreRun: func(req cmds.Request) error {
_, err := getCompressOptions(req)
return err
},
Run: func(req cmds.Request, res cmds.Response) {
cmplvl, err := getCompressOptions(req)
if err != nil {
res.SetError(err, cmds.ErrClient)
return
}
node, err := req.InvocContext().GetNode()
开发者ID:riversparks,项目名称:go-ipfs,代码行数:31,代码来源:get.go
示例11:
/ipfs/QmRzTuh2Lpuz7Gr39stNr6mTFdqAghsZec1JoUnfySUzcy
The resolver can recursively resolve:
> dig +short TXT recursive.ipfs.io
dnslink=/ipns/ipfs.io
> ipfs dns -r recursive.ipfs.io
/ipfs/QmRzTuh2Lpuz7Gr39stNr6mTFdqAghsZec1JoUnfySUzcy
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("domain-name", true, false, "The domain-name name to resolve.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
recursive, _, _ := req.Option("recursive").Bool()
name := req.Arguments()[0]
resolver := namesys.NewDNSResolver()
depth := 1
if recursive {
depth = namesys.DefaultDepthLimit
}
output, err := resolver.ResolveN(req.Context(), name, depth)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:31,代码来源:dns.go
示例12:
> OBJ_A=QmegHcnrPgMwC7tBiMxChD54fgQMBUecNw9nE9UUU4x1bz
> echo "different content" > foo/bar
> ipfs add -r foo
...
Added QmcmRptkSPWhptCttgHg27QNDmnV33wAJyUkCnAvqD3eCD foo
> OBJ_B=QmcmRptkSPWhptCttgHg27QNDmnV33wAJyUkCnAvqD3eCD
> ipfs object diff -v $OBJ_A $OBJ_B
Changed "bar" from QmNgd5cz2jNftnAHBhcRUGdtiaMzb5Rhjqd4etondHHST8 to QmRfFVsjSXkhFxrfWnLpMae2M4GBVsry6VAuYYcji5MiZb.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("obj_a", true, false, "Object to diff against."),
cmds.StringArg("obj_b", true, false, "Object to diff."),
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Print extra information."),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
a := req.Arguments()[0]
b := req.Arguments()[1]
pa, err := path.ParsePath(a)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
开发者ID:qnib,项目名称:go-ipfs,代码行数:31,代码来源:diff.go
示例13:
"stat": repoStatCmd,
},
}
var repoGcCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Perform a garbage collection sweep on the repo.",
ShortDescription: `
'ipfs repo gc' is a plumbing command that will sweep the local
set of stored objects and remove ones that are not pinned in
order to reclaim hard disk space.
`,
},
Options: []cmds.Option{
cmds.BoolOption("quiet", "q", "Write minimal output."),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
gcOutChan, err := corerepo.GarbageCollectAsync(n, req.Context())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
outChan := make(chan interface{})
开发者ID:kalmi,项目名称:go-ipfs,代码行数:31,代码来源:repo.go
示例14:
"get": getValueDhtCmd,
"put": putValueDhtCmd,
},
}
var queryDhtCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Run a 'findClosestPeers' query through the DHT",
ShortDescription: ``,
},
Arguments: []cmds.Argument{
cmds.StringArg("peerID", true, true, "The peerID to run the query against"),
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Write extra information"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
dht, ok := n.Routing.(*ipdht.IpfsDHT)
if !ok {
res.SetError(ErrNotDHT, cmds.ErrNormal)
return
}
events := make(chan *notif.QueryEvent)
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:31,代码来源:dht.go
示例15:
var LsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List links from an object.",
ShortDescription: `
Retrieves the object named by <ipfs-or-ipns-path> and displays the links
it contains, with the following format:
<link base58 hash> <link size in bytes> <link name>
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Name, Size)"),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
// get options early -> exit early in case of error
if _, _, err := req.Option("headers").Bool(); err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
paths := req.Arguments()
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:31,代码来源:ls.go
示例16:
cmds "github.com/ipfs/go-ipfs/commands"
)
var ActiveReqsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List commands run on this ipfs node",
ShortDescription: `
Lists running and recently run commands.
`,
},
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(req.InvocContext().ReqLog.Report())
},
Options: []cmds.Option{
cmds.BoolOption("v", "verbose", "print more verbose output"),
},
Subcommands: map[string]*cmds.Command{
"clear": clearInactiveCmd,
},
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
if !ok {
log.Errorf("%#v", res.Output())
return nil, cmds.ErrIncorrectType
}
buf := new(bytes.Buffer)
verbose, _, _ := res.Request().Option("v").Bool()
开发者ID:musha68k,项目名称:go-ipfs,代码行数:29,代码来源:active.go
示例17:
}
var bootstrapAddCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Add peers to the bootstrap list.",
ShortDescription: `Outputs a list of peers that were added (that weren't already
in the bootstrap list).
` + bootstrapSecurityWarning,
},
Arguments: []cmds.Argument{
cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("default", "Add default bootstrap nodes.").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
inputPeers, err := config.ParseBootstrapPeers(req.Arguments())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
defer r.Close()
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:31,代码来源:bootstrap.go
示例18:
$ ipfs resolve -r /ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj
Resolve the value of an IPFS DAG path:
$ ipfs resolve /ipfs/QmeZy1fGbwgVSrqbfh9fKQrAWgeyRnj7h8fsHS1oy3k99x/beep/boop
/ipfs/QmYRMjyvAiHKN9UTi8Bzt1HUspmSRD8T8DwxfSMzLgBon1
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "The name to resolve.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if !n.OnlineMode() {
err := n.SetupOfflineRouting()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:31,代码来源:resolve.go
示例19:
},
Subcommands: map[string]*cmds.Command{
"bw": statBwCmd,
},
}
var statBwCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Print ipfs bandwidth information.",
ShortDescription: ``,
},
Options: []cmds.Option{
cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for."),
cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for."),
cmds.BoolOption("poll", "Print bandwidth at an interval."),
cmds.StringOption("interval", "i", "Time interval to wait between updating output."),
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
// Must be online!
if !nd.OnlineMode() {
res.SetError(errNotOnline, cmds.ErrClient)
return
}
开发者ID:peckjerry,项目名称:go-ipfs,代码行数:31,代码来源:stat.go
示例20:
hashes it contains, with the following format:
<link base58 hash>
Note: list all refs recursively with -r.
`,
},
Subcommands: map[string]*cmds.Command{
"local": RefsLocalCmd,
},
Arguments: []cmds.Argument{
cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from.").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption("format", "Emit edges with given format. tokens: <src> <dst> <linkname>."),
cmds.BoolOption("edges", "e", "Emit edge format: `<from> -> <to>`."),
cmds.BoolOption("unique", "u", "Omit duplicate refs from output."),
cmds.BoolOption("recursive", "r", "Recursively list links of child nodes."),
},
Run: func(req cmds.Request, res cmds.Response) {
ctx := req.Context()
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
unique, _, err := req.Option("unique").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:31,代码来源:refs.go
注:本文中的github.com/ipfs/go-ipfs/commands.BoolOption函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论