Merge "camdebug moved as camtool debug"

This commit is contained in:
mpl 2013-02-25 14:47:48 +00:00 committed by Gerrit Code Review
commit 4223b02d52
7 changed files with 84 additions and 56 deletions

View File

@ -1 +0,0 @@
camdebug

View File

@ -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()
}

1
cmd/camtool/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
camtool

78
cmd/camtool/debug.go Normal file
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"
"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
}

View File

@ -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())

View File

@ -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)

View File

@ -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())