Add camput 'rawobj' subcommand for debugging.

Change-Id: I7f7e70a3c757889e6f8f4f264ea7f0e797c41e7a
This commit is contained in:
Brad Fitzpatrick 2011-12-07 14:42:16 -08:00
parent d50f2323fd
commit 398e1549c6
1 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,78 @@
/*
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 (
"flag"
"os"
"strings"
"camli/schema"
)
type rawCmd struct {
vals string // pipe separated key=value "camliVersion=1|camliType=foo", etc
signed bool
}
func init() {
RegisterCommand("rawobj", func(flags *flag.FlagSet) CommandRunner {
cmd := new(rawCmd)
flags.StringVar(&cmd.vals, "vals", "", "Pipe-separated key=value properties")
flags.BoolVar(&cmd.signed, "signed", true, "whether to sign the JSON object")
return cmd
})
}
func (c *rawCmd) Usage() {
errf("Usage: camput [globalopts] rawobj [rawopts]\n")
}
func (c *rawCmd) Examples() []string {
return []string{"(debug command)"}
}
func (c *rawCmd) RunCommand(up *Uploader, args []string) os.Error {
if len(args) > 0 {
return os.NewError("Raw Object command doesn't take any additional arguments")
}
m := make(map[string]interface{})
if c.vals == "" {
return os.NewError("No values")
}
for _, kv := range strings.Split(c.vals, "|") {
kv := strings.SplitN(kv, "=", 2)
m[kv[0]] = kv[1]
}
if _, ok := m["camliVersion"]; !ok {
m["camliVersion"] = "1"
}
if c.signed {
put, err := up.UploadAndSignMap(m)
handleResult("raw-object-signed", put, err)
return err
}
cj, err := schema.MapToCamliJson(m)
if err != nil {
return err
}
put, err := up.uploadString(cj)
handleResult("raw-object-unsigned", put, err)
return err
}