github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/cmd/camtool/dumpconfig.go (about) 1 /* 2 Copyright 2013 Google Inc. 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 package main 18 19 import ( 20 "encoding/json" 21 "errors" 22 "flag" 23 "os" 24 25 "camlistore.org/pkg/cmdmain" 26 "camlistore.org/pkg/osutil" 27 "camlistore.org/pkg/serverconfig" 28 ) 29 30 type dumpconfigCmd struct{} 31 32 func init() { 33 cmdmain.RegisterCommand("dumpconfig", func(flags *flag.FlagSet) cmdmain.CommandRunner { 34 return new(dumpconfigCmd) 35 }) 36 } 37 38 func (c *dumpconfigCmd) Describe() string { 39 return "Dump the low-level server config from its simple config." 40 } 41 42 func (c *dumpconfigCmd) Usage() { 43 } 44 45 func (c *dumpconfigCmd) RunCommand(args []string) error { 46 var file string 47 switch { 48 case len(args) == 0: 49 file = osutil.UserServerConfigPath() 50 case len(args) == 1: 51 file = args[0] 52 default: 53 return errors.New("More than 1 argument not allowed") 54 } 55 cfg, err := serverconfig.Load(file) 56 if err != nil { 57 return err 58 } 59 cfg.Obj["handlerConfig"] = true 60 ll, err := json.MarshalIndent(cfg.Obj, "", " ") 61 if err != nil { 62 return err 63 } 64 _, err = os.Stdout.Write(ll) 65 return err 66 }