本文整理汇总了Golang中github.com/jbenet/commander.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: blobCmd
// Handles arguments and dispatches subcommand.
func blobCmd(c *commander.Command, args []string) (blobPaths, error) {
blobs := blobPaths{}
// Use all blobs in the manifest if --all is passed in.
all := c.Flag.Lookup("all").Value.Get().(bool)
if all {
mf := NewDefaultManifest()
blobs = validBlobHashes(mf.Files)
if len(blobs) < 1 {
return nil, fmt.Errorf("%v: no blobs tracked in manifest.", c.FullName())
}
} else {
switch len(args) {
case 2:
blobs[args[1]] = args[0]
case 1:
blobs[""] = args[0]
case 0:
return nil,
fmt.Errorf("%v: requires <hash> argument (or --all)", c.FullName())
}
}
return blobs, nil
}
开发者ID:jbenet,项目名称:data,代码行数:27,代码来源:data_blob.go
示例2: configCmd
func configCmd(c *commander.Command, args []string) error {
if c.Flag.Lookup("show").Value.Get().(bool) {
return printConfig(&Config)
}
if c.Flag.Lookup("edit").Value.Get().(bool) {
return configEditor()
}
if len(args) == 0 {
return fmt.Errorf("%s: requires <key> argument.", c.Name())
}
if len(args) == 1 {
value := ConfigGet(args[0])
if value == nil {
return fmt.Errorf("") // empty string prints out nothing.
}
m, err := Marshal(value)
if err != nil {
return err
}
io.Copy(os.Stdout, m)
return nil
}
return ConfigSet(args[0], args[1])
}
开发者ID:jbenet,项目名称:data,代码行数:29,代码来源:data_config.go
示例3: blobCheckCmd
func blobCheckCmd(c *commander.Command, args []string) error {
blobs, err := blobCmd(c, args)
if err != nil {
return err
}
if len(args) == 1 {
return fmt.Errorf("%v: requires <path> argument", c.FullName())
}
return checkBlobs(blobs)
}
开发者ID:jbenet,项目名称:data,代码行数:10,代码来源:data_blob.go
示例4: commandsCmd
func commandsCmd(c *commander.Command, args []string) error {
var listCmds func(c *commander.Command)
listCmds = func(c *commander.Command) {
pOut("%s\n", c.FullSpacedName())
for _, sc := range c.Subcommands {
listCmds(sc)
}
}
listCmds(c.Parent)
return nil
}
开发者ID:jbenet,项目名称:data,代码行数:12,代码来源:commands.go
示例5: blobHashCmd
func blobHashCmd(c *commander.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("%v: requires <path> argument", c.FullName())
}
hash, err := hashFile(args[0])
if err != nil {
return err
}
pOut("%s\n", hash)
return nil
}
开发者ID:jbenet,项目名称:data,代码行数:12,代码来源:data_blob.go
示例6: blobShowCmd
func blobShowCmd(c *commander.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("%v: requires <hash> argument", c.FullName())
}
hash := args[0]
if !IsHash(hash) {
return fmt.Errorf("%v: invalid hash '%s'", c.FullName(), hash)
}
dataIndex, err := NewMainDataIndex()
if err != nil {
return err
}
return dataIndex.copyBlob(hash, os.Stdout)
}
开发者ID:jbenet,项目名称:data,代码行数:17,代码来源:data_blob.go
示例7: getCmd
func getCmd(c *commander.Command, args []string) error {
var datasets []string
if len(args) > 0 {
// if args, get those datasets.
datasets = args
} else {
// if no args, use Datafile dependencies
df, _ := NewDefaultDatafile()
for _, dep := range df.Dependencies {
if NewHandle(dep).Valid() {
datasets = append(datasets, dep)
}
}
}
if len(datasets) == 0 {
return fmt.Errorf("%v: no datasets specified.\nEither enter a <dataset> "+
"argument, or add dependencies in a Datafile.", c.FullName())
}
installed_datasets := []string{}
for _, ds := range datasets {
ds, err := GetDataset(ds)
if err != nil {
return err
}
installed_datasets = append(installed_datasets, ds)
}
if len(datasets) == 0 {
return nil
}
// If many, Installation Summary
pErr("---------\n")
for _, ds := range installed_datasets {
err := installedDatasetMessage(ds)
if err != nil {
pErr("%v\n", err)
}
}
return nil
}
开发者ID:jbenet,项目名称:data,代码行数:44,代码来源:data_get.go
示例8: manifestCmdPaths
func manifestCmdPaths(c *commander.Command, args []string) ([]string, error) {
mf := NewDefaultManifest()
paths := args
// Use all files available if --all is passed in.
all := c.Flag.Lookup("all").Value.Get().(bool)
if all {
paths = []string{}
for path, _ := range mf.Files {
paths = append(paths, path)
}
}
if len(paths) < 1 {
return nil, fmt.Errorf("%v: no files specified.", c.FullName())
}
return paths, nil
}
开发者ID:jbenet,项目名称:data,代码行数:19,代码来源:data_manifest.go
示例9: commandsHelpCmd
func commandsHelpCmd(c *commander.Command, args []string) error {
pOut(referenceHeaderMsg)
pOut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))
var printCmds func(*commander.Command, int)
printCmds = func(c *commander.Command, level int) {
pOut("%s ", strings.Repeat("#", level))
pOut("%s\n\n", c.FullSpacedName())
pOut("```\n")
pOut("%s\n", c.Long)
pOut("```\n\n")
for _, sc := range c.Subcommands {
printCmds(sc, level+1)
}
}
printCmds(c.Parent.Parent, 1)
return nil
}
开发者ID:jbenet,项目名称:data,代码行数:20,代码来源:commands.go
示例10: manifestAddCmd
func manifestAddCmd(c *commander.Command, args []string) error {
mf := NewDefaultManifest()
paths := args
// Use all files available if --all is passed in.
all := c.Flag.Lookup("all").Value.Get().(bool)
if all {
paths = listAllFiles(".")
}
if len(paths) < 1 {
return fmt.Errorf("%v: no files specified.", c.FullName())
}
// add files to manifest file
for _, f := range paths {
err := mf.Add(f)
if err != nil {
return err
}
}
return nil
}
开发者ID:jbenet,项目名称:data,代码行数:24,代码来源:data_manifest.go
示例11: ex_run_cmd_subcmd2_cmd2
func ex_run_cmd_subcmd2_cmd2(cmd *commander.Command, args []string) error {
name := "my-cmd-subcmd2-" + cmd.Name()
quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
fmt.Printf("%s: hello from subcmd2-cmd2 (quiet=%v)\n", name, quiet)
return nil
}
开发者ID:whyrusleeping,项目名称:commander,代码行数:6,代码来源:cmd_subcmd2_cmd2.go
注:本文中的github.com/jbenet/commander.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论