2011-09-26 00:40:01 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2011-09-26 09:27:21 +00:00
|
|
|
"flag"
|
2011-09-26 00:40:01 +00:00
|
|
|
"os"
|
2011-09-26 09:27:21 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"camli/client"
|
|
|
|
"camli/schema"
|
2011-09-26 00:40:01 +00:00
|
|
|
)
|
|
|
|
|
2011-09-26 09:27:21 +00:00
|
|
|
type permanodeCmd struct {
|
|
|
|
name string
|
|
|
|
tag string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2011-09-27 03:02:35 +00:00
|
|
|
RegisterCommand("permanode", func(flags *flag.FlagSet) CommandRunner {
|
|
|
|
cmd := new(permanodeCmd)
|
|
|
|
flags.StringVar(&cmd.name, "name", "", "Optional name attribute to set on new permanode")
|
|
|
|
flags.StringVar(&cmd.tag, "tag", "", "Optional tag(s) to set on new permanode; comma separated.")
|
|
|
|
return cmd
|
|
|
|
})
|
2011-09-26 09:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *permanodeCmd) Usage() {
|
2011-09-27 03:02:35 +00:00
|
|
|
errf("Usage: camput [globalopts] permanode [permanodeopts]\n")
|
2011-09-26 09:27:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 03:02:35 +00:00
|
|
|
func (c *permanodeCmd) Examples() []string {
|
|
|
|
return []string{
|
|
|
|
" (create a new permanode)",
|
|
|
|
`-name="Some Name" -tag=foo,bar (with attributes added)`,
|
2011-09-26 09:27:21 +00:00
|
|
|
}
|
2011-09-27 03:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *permanodeCmd) RunCommand(up *Uploader, args []string) os.Error {
|
2011-09-26 09:27:21 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
return os.NewError("Permanode command doesn't take any additional arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
permaNode *client.PutResult
|
|
|
|
err os.Error
|
|
|
|
)
|
|
|
|
permaNode, err = up.UploadNewPermanode()
|
|
|
|
handleResult("permanode", permaNode, err)
|
2011-09-26 00:40:01 +00:00
|
|
|
|
2011-09-26 09:27:21 +00:00
|
|
|
if c.name != "" {
|
|
|
|
put, err := up.UploadAndSignMap(schema.NewSetAttributeClaim(permaNode.BlobRef, "name", c.name))
|
|
|
|
handleResult("claim-permanode-name", put, err)
|
|
|
|
}
|
|
|
|
if c.tag != "" {
|
|
|
|
tags := strings.Split(c.tag, ",")
|
|
|
|
m := schema.NewSetAttributeClaim(permaNode.BlobRef, "tag", tags[0])
|
|
|
|
for _, tag := range tags {
|
|
|
|
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
|
|
|
|
put, err := up.UploadAndSignMap(m)
|
|
|
|
handleResult("claim-permanode-tag", put, err)
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 00:40:01 +00:00
|
|
|
return nil
|
|
|
|
}
|