github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/dev/devcam/camtool.go (about) 1 /* 2 Copyright 2013 The Camlistore Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // This file adds the "tool" subcommand to devcam, to run camtool against 18 // the dev server. 19 20 package main 21 22 import ( 23 "flag" 24 "fmt" 25 "path/filepath" 26 27 "camlistore.org/pkg/cmdmain" 28 ) 29 30 type toolCmd struct { 31 // start of flag vars 32 altkey bool 33 // end of flag vars 34 35 env *Env 36 } 37 38 func init() { 39 cmdmain.RegisterCommand("tool", func(flags *flag.FlagSet) cmdmain.CommandRunner { 40 cmd := &toolCmd{ 41 env: NewCopyEnv(), 42 } 43 flags.BoolVar(&cmd.altkey, "altkey", false, "Use different gpg key and password from the server's.") 44 return cmd 45 }) 46 } 47 48 func (c *toolCmd) Usage() { 49 fmt.Fprintf(cmdmain.Stderr, "Usage: devcam tool [globalopts] <mode> [commandopts] [commandargs]\n") 50 } 51 52 func (c *toolCmd) Examples() []string { 53 return []string{ 54 "sync --all", 55 } 56 } 57 58 func (c *toolCmd) Describe() string { 59 return "run camtool in dev mode." 60 } 61 62 func (c *toolCmd) RunCommand(args []string) error { 63 if !*noBuild { 64 if err := build(filepath.Join("cmd", "camtool")); err != nil { 65 return fmt.Errorf("Could not build camtool: %v", err) 66 } 67 } 68 c.env.SetCamdevVars(c.altkey) 69 70 cmdBin := filepath.Join("bin", "camtool") 71 return runExec(cmdBin, args, c.env) 72 }