github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/dgraph/cmd/conv/run.go (about) 1 /* 2 * Copyright 2018 Dgraph Labs, Inc. and Contributors 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 conv 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/dgraph-io/dgraph/x" 24 "github.com/spf13/cobra" 25 ) 26 27 // Conv is the sub-command invoked when running "dgraph conv". 28 var Conv x.SubCommand 29 30 var opt struct { 31 geo string 32 out string 33 geopred string 34 } 35 36 func init() { 37 Conv.Cmd = &cobra.Command{ 38 Use: "conv", 39 Short: "Dgraph Geo file converter", 40 Args: cobra.NoArgs, 41 Run: func(cmd *cobra.Command, args []string) { 42 defer x.StartProfile(Conv.Conf).Stop() 43 if err := run(); err != nil { 44 fmt.Println(err) 45 os.Exit(1) 46 } 47 }, 48 } 49 50 flag := Conv.Cmd.Flags() 51 flag.StringVar(&opt.geo, "geo", "", "Location of geo file to convert") 52 flag.StringVar(&opt.out, "out", "output.rdf.gz", "Location of output rdf.gz file") 53 flag.StringVar(&opt.geopred, "geopred", "loc", "Predicate to use to store geometries") 54 x.Check(Conv.Cmd.MarkFlagRequired("geo")) 55 } 56 57 func run() error { 58 return convertGeoFile(opt.geo, opt.out) 59 }