本文整理匯總了Golang中github.com/jwaldrip/odin/cli.Command.Arg方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.Arg方法的具體用法?Golang Command.Arg怎麽用?Golang Command.Arg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jwaldrip/odin/cli.Command
的用法示例。
在下文中一共展示了Command.Arg方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: list
func list(c cli.Command) {
var (
arglen = len(c.Args())
table = tablewriter.NewWriter(os.Stdout)
)
if arglen == 0 && (blank(container) || c.Flag("type").String() == "storage") {
containers, err := api.ContainersInfo()
if err != nil {
log.Fatal(err)
}
table.SetHeader([]string{"Name", "Objects", "Type"})
for _, cont := range containers {
v := []string{cont.Name, fmt.Sprint(cont.ObjectCount), cont.Type}
table.Append(v)
}
table.Render()
return
}
if arglen == 1 {
container = c.Arg(0).String()
}
if blank(container) {
log.Fatal(errorNotEnough)
}
objects, err := api.Container(container).ObjectsInfo()
if err != nil {
log.Fatal(err)
}
table.SetHeader([]string{"Name", "Size", "Downloaded"})
for _, object := range objects {
v := []string{object.Name, fmt.Sprint(object.Size), fmt.Sprint(object.Downloaded)}
table.Append(v)
}
table.Render()
}
示例2: create
func create(c cli.Command) {
if len(c.Args()) == 0 {
log.Fatal(errorNotEnough)
}
var name = c.Arg(0).String()
if _, err := api.CreateContainer(name, false); err != nil {
log.Fatal(err)
}
fmt.Printf("created container %s\n", name)
}
示例3: info
// info prints information about storage
func info(c cli.Command) {
var (
containerName = container
objectName string
data interface{}
err error
arglen = len(c.Args())
command = c.Flag("type").String()
)
defer func() {
if err != nil {
log.Fatal(err)
}
if blank(containerName) || command == "storage" {
data = api.Info()
} else {
containerApi := api.Container(containerName)
if blank(objectName) {
data, err = containerApi.Info()
} else {
data, err = containerApi.Object(objectName).Info()
}
}
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", data)
}()
if arglen > 0 {
if command == "container" {
containerName = c.Arg(0).String()
return
}
command = "object"
if !blank(containerName) && arglen == 1 {
objectName = c.Arg(0).String()
return
}
if arglen == 2 {
containerName = c.Arg(0).String()
objectName = c.Arg(1).String()
return
}
}
if command == "container" && !blank(containerName) {
return
}
if command == "storage" {
return
}
err = errorNotEnough
}
示例4: remove
func remove(c cli.Command) {
var (
arglen = len(c.Args())
object string
err error
message string
objects []storage.ObjectAPI
)
if arglen == 2 {
container = c.Arg(0).String()
object = c.Arg(1).String()
}
if arglen == 1 {
if c.Flag("type").String() == "container" {
container = c.Arg(0).String()
} else {
object = c.Arg(0).String()
}
}
if blank(container) {
log.Fatal(errorNotEnough)
}
if blank(object) {
containerApi := api.Container(container)
err = containerApi.Remove()
// forced removal of container
if err == storage.ErrorConianerNotEmpty && c.Flag("force").Get().(bool) {
fmt.Println("removing all objects of", container)
objects, err = containerApi.Objects()
if err != nil {
log.Fatal(err)
}
for _, object := range objects {
err = object.Remove()
// skipping NotFound errors as non-critical
if err != nil && err != storage.ErrorObjectNotFound {
log.Fatal(err)
}
}
err = containerApi.Remove()
}
message = fmt.Sprintf("container %s removed", container)
} else {
err = api.Container(container).Object(object).Remove()
message = fmt.Sprintf("object %s removed in container %s", object, container)
}
if err != nil {
log.Fatal(err)
}
fmt.Println(message)
}
示例5: cmSingle
func cmSingle(c cli.Command) {
client, _ := api.NewClient(api.DefaultConfig())
catalog := client.Catalog()
node, _, err := catalog.Node(c.Arg(0).String(), nil)
if err != nil {
log.Fatalln("err: ", err)
}
if node == nil {
log.Fatalln("node not found")
}
if node.Services["cascade"] == nil {
log.Fatalln("node not managed by cascade")
}
cmRunRoll("", c.Arg(0).String())
}
示例6: download
func download(c cli.Command) {
var (
arglen = len(c.Args())
objectName string
path = c.Flag("path").String()
)
switch arglen {
case 1:
objectName = c.Arg(0).String()
case 2:
objectName = c.Arg(1).String()
container = c.Arg(0).String()
}
if blank(container) || blank(objectName) {
log.Fatal(errorNotEnough)
}
if blank(path) {
path = objectName
}
reader, err := api.Container(container).Object(objectName).GetReader()
if err != nil {
log.Fatal(err)
}
defer reader.Close()
fmt.Printf("downloading %s->%s from %s\n", objectName, path, container)
f, err := os.Create(path)
if err != nil {
log.Fatal(err)
}
n, err := io.Copy(f, reader)
if err != nil {
log.Fatal(err)
}
fmt.Printf("downloaded %s, %d bytes\n", objectName, n)
}
示例7: upload
func upload(c cli.Command) {
var path string
switch len(c.Args()) {
case 1:
path = c.Arg(0).String()
case 2:
container = c.Arg(0).String()
path = c.Arg(1).String()
}
if blank(container) || blank(path) {
log.Fatal(errorNotEnough)
}
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
stat, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
ext := filepath.Ext(path)
mimetype := mime.TypeByExtension(ext)
bar := pb.New64(stat.Size()).SetUnits(pb.U_BYTES)
bar.Start()
reader := io.TeeReader(f, bar)
if err := api.Container(container).Upload(reader, stat.Name(), mimetype); err != nil {
log.Fatal(err)
}
fmt.Printf("uploaded to %s\n", container)
}
示例8: serviceFind
func serviceFind(c cli.Command) {
client, _ := api.NewClient(api.DefaultConfig())
catalog := client.Catalog()
if len(c.Args().GetAll()) == 0 {
log.Fatalln("err: missing <servicename> argument")
}
nodes, _, err := catalog.Service(c.Arg(0).String(), c.Flag("type").String(), nil)
if err != nil {
log.Fatalln("err: ", err)
}
fmt.Println(c.Arg(0).String() + ":")
for _, node := range nodes {
fmt.Println(" - host:", node.Node)
fmt.Println(" address:", node.Address)
fmt.Println(" port:", node.ServicePort)
fmt.Println(" tags:", strings.Join(node.ServiceTags, ", "))
}
}