mirror of https://github.com/perkeep/perkeep.git
Merge "camdebug moved as camtool debug"
This commit is contained in:
commit
4223b02d52
|
@ -1 +0,0 @@
|
|||
camdebug
|
|
@ -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()
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
camtool
|
|
@ -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
|
||||
}
|
|
@ -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())
|
|
@ -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)
|
|
@ -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())
|
Loading…
Reference in New Issue