From 6f9795e9bac44da3a922e1b33fab9dc9cc97e45f Mon Sep 17 00:00:00 2001 From: David Howden Date: Wed, 7 Feb 2018 14:06:06 +1100 Subject: [PATCH] client: added docconv-client cli tool --- client/cmd/docconv-client/main.go | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 client/cmd/docconv-client/main.go diff --git a/client/cmd/docconv-client/main.go b/client/cmd/docconv-client/main.go new file mode 100644 index 0000000..ed79677 --- /dev/null +++ b/client/cmd/docconv-client/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" + + "code.sajari.com/docconv/client" +) + +var ( + path = flag.String("path", "", "`path` to file to convert") + endpoint = flag.String("endpoint", "", "docconv HTTP server to use for conversion") +) + +func main() { + flag.Parse() + + if *path == "" { + fmt.Println("must set -path") + os.Exit(1) + } + + var opts []client.Opt + if *endpoint != "" { + opts = append(opts, client.WithEndpoint(*endpoint)) + } + + c := client.New(opts...) + resp, err := client.ConvertPath(c, *path) + if err != nil { + fmt.Printf("Could not convert: %v", err) + os.Exit(1) + } + + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + if err := enc.Encode(resp); err != nil { + fmt.Printf("Could not encode response: %v", err) + } +}