diff --git a/cmd/camdebug/.gitignore b/cmd/camdebug/.gitignore deleted file mode 100644 index 3f28c2514..000000000 --- a/cmd/camdebug/.gitignore +++ /dev/null @@ -1 +0,0 @@ -camdebug diff --git a/cmd/camdebug/camdebug.go b/cmd/camdebug/camdebug.go deleted file mode 100644 index 739950ae2..000000000 --- a/cmd/camdebug/camdebug.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -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" -) - -var ( - flagSplits = flag.Bool("splits", false, "show splits of provided filename") - flagMIME = flag.Bool("mime", false, "show MIME type of provided file") - flagEXIF = flag.Bool("exif", false, "show EXIF dump of provided file") -) - -func main() { - flag.Parse() - if *flagMIME { - showMIME() - return - } - if *flagSplits { - showSplits() - return - } - if *flagEXIF { - showEXIF() - return - } - flag.Usage() -} diff --git a/cmd/camtool/.gitignore b/cmd/camtool/.gitignore new file mode 100644 index 000000000..bb08a8d55 --- /dev/null +++ b/cmd/camtool/.gitignore @@ -0,0 +1 @@ +camtool diff --git a/cmd/camtool/debug.go b/cmd/camtool/debug.go new file mode 100644 index 000000000..eca8947c4 --- /dev/null +++ b/cmd/camtool/debug.go @@ -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" + "fmt" + "os" + "strings" + + "camlistore.org/pkg/cmdmain" +) + +var debugSubModes = map[string]*debugSubMode{ + "splits": &debugSubMode{ + doc: "Show splits of provided file.", + fun: showSplits, + }, + "mime": &debugSubMode{ + doc: "Show MIME type of provided file.", + fun: showMIME, + }, + "exif": &debugSubMode{ + doc: "Show EXIF dump of provided file.", + fun: showEXIF, + }, +} + +type debugSubMode struct { + doc string + fun func(string) +} + +type debugCmd struct{} + +func init() { + cmdmain.RegisterCommand("debug", func(flags *flag.FlagSet) cmdmain.CommandRunner { + return new(debugCmd) + }) +} + +func (c *debugCmd) Usage() { + var subModes, docs string + for k, v := range debugSubModes { + subModes += k + "|" + docs += fmt.Sprintf(" %s: %s\n", k, v.doc) + } + subModes = strings.TrimRight(subModes, "|") + fmt.Fprintf(os.Stderr, + "Usage: camtool [globalopts] debug %s file\n%s", + subModes, docs) +} + +func (c *debugCmd) RunCommand(args []string) error { + if args == nil || len(args) != 2 { + return cmdmain.UsageError("Incorrect number of arguments.") + } + subMode, ok := debugSubModes[args[0]] + if !ok { + return cmdmain.UsageError(fmt.Sprintf("Invalid submode: %v", args[0])) + } + subMode.fun(args[1]) + return nil +} diff --git a/cmd/camdebug/exif.go b/cmd/camtool/exif.go similarity index 95% rename from cmd/camdebug/exif.go rename to cmd/camtool/exif.go index 07c5fd847..c66826645 100644 --- a/cmd/camdebug/exif.go +++ b/cmd/camtool/exif.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "flag" "fmt" "log" "os" @@ -25,8 +24,7 @@ import ( "camlistore.org/third_party/github.com/camlistore/goexif/exif" ) -func showEXIF() { - file := flag.Arg(0) +func showEXIF(file string) { f, err := os.Open(file) if err != nil { panic(err.Error()) diff --git a/cmd/camdebug/mime.go b/cmd/camtool/mime.go similarity index 93% rename from cmd/camdebug/mime.go rename to cmd/camtool/mime.go index c01b657c6..d4a04a97c 100644 --- a/cmd/camdebug/mime.go +++ b/cmd/camtool/mime.go @@ -17,16 +17,14 @@ limitations under the License. package main import ( - "flag" - "log" "fmt" + "log" "os" - + "camlistore.org/pkg/magic" ) -func showMIME() { - file := flag.Arg(0) +func showMIME(file string) { f, err := os.Open(file) if err != nil { log.Fatal(err) diff --git a/cmd/camdebug/splits.go b/cmd/camtool/splits.go similarity index 97% rename from cmd/camdebug/splits.go rename to cmd/camtool/splits.go index 5ac2e8993..515bf6bc3 100644 --- a/cmd/camdebug/splits.go +++ b/cmd/camtool/splits.go @@ -18,7 +18,6 @@ package main import ( "bufio" - "flag" "fmt" "io" "log" @@ -34,8 +33,7 @@ type span struct { children []span } -func showSplits() { - file := flag.Arg(0) +func showSplits(file string) { f, err := os.Open(file) if err != nil { panic(err.Error())