fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

build: factor out build flags

We currently have all flags related to build options defined in the cmd
package. These flags are as a side-effect to the CommandLine
flagset. This commit factors it out into the build package and allows
setting it on a different flagset.

This is working towards creating command line arguments from a
BuildOptions struct. This can be used by indexserver.

Change-Id: Ibb711b3620d68571325d52f5507f99b7fab234e3

+27 -31
+24
build/builder.go
··· 18 18 19 19 import ( 20 20 "crypto/sha1" 21 + "flag" 21 22 "fmt" 22 23 "io" 23 24 "io/ioutil" ··· 93 94 hasher.Write([]byte(fmt.Sprintf("%q", o.LargeFiles))) 94 95 95 96 return fmt.Sprintf("%x", hasher.Sum(nil)) 97 + } 98 + 99 + type largeFilesFlag struct{ *Options } 100 + 101 + func (f largeFilesFlag) String() string { 102 + s := append([]string{""}, f.LargeFiles...) 103 + return strings.Join(s, "-large_file ") 104 + } 105 + 106 + func (f largeFilesFlag) Set(value string) error { 107 + f.LargeFiles = append(f.LargeFiles, value) 108 + return nil 109 + } 110 + 111 + // Flags adds flags for build options to fs. 112 + func (o *Options) Flags(fs *flag.FlagSet) { 113 + fs.IntVar(&o.SizeMax, "file_limit", 2<<20, "maximum file size") 114 + fs.IntVar(&o.TrigramMax, "max_trigram_count", 20000, "maximum number of trigrams per document") 115 + fs.IntVar(&o.ShardMax, "shard_limit", 100<<20, "maximum corpus size for a shard") 116 + fs.IntVar(&o.Parallelism, "parallelism", 4, "maximum number of parallel indexing processes.") 117 + fs.StringVar(&o.IndexDir, "index", DefaultDir, "directory for search indices") 118 + fs.BoolVar(&o.CTagsMustSucceed, "require_ctags", false, "If set, ctags calls must succeed.") 119 + fs.Var(largeFilesFlag{o}, "large_file", "A glob pattern where matching files are to be index regardless of their size. You can add multiple patterns by setting this more than once.") 96 120 } 97 121 98 122 // Builder manages (parallel) creation of uniformly sized shards. The
+3 -31
cmd/flags.go
··· 19 19 "fmt" 20 20 "os" 21 21 "path/filepath" 22 - "strings" 23 22 24 23 "github.com/google/zoekt" 25 24 "github.com/google/zoekt/build" 26 25 ) 27 26 28 - type largeFilesFlag []string 29 - 30 - func (f *largeFilesFlag) String() string { 31 - s := append([]string{""}, *f...) 32 - return strings.Join(s, "-large_file ") 33 - } 34 - 35 - func (f *largeFilesFlag) Set(value string) error { 36 - *f = append(*f, value) 37 - return nil 38 - } 39 - 40 27 var ( 41 - sizeMax = flag.Int("file_limit", 2<<20, "maximum file size") 42 - trigramMax = flag.Int("max_trigram_count", 20000, "maximum number of trigrams per document") 43 - shardLimit = flag.Int("shard_limit", 100<<20, "maximum corpus size for a shard") 44 - parallelism = flag.Int("parallelism", 4, "maximum number of parallel indexing processes.") 45 - indexDir = flag.String("index", build.DefaultDir, "directory for search indices") 46 - version = flag.Bool("version", false, "Print version number") 47 - ctags = flag.Bool("require_ctags", false, "If set, ctags calls must succeed.") 48 - largeFiles = largeFilesFlag{} 28 + version = flag.Bool("version", false, "Print version number") 29 + opts = &build.Options{} 49 30 ) 50 31 51 32 func init() { 52 - flag.Var(&largeFiles, "large_file", "A glob pattern where matching files are to be index regardless of their size. You can add multiple patterns by setting this more than once.") 33 + opts.Flags(flag.CommandLine) 53 34 } 54 35 55 36 func OptionsFromFlags() *build.Options { ··· 59 40 os.Exit(0) 60 41 } 61 42 62 - opts := &build.Options{ 63 - Parallelism: *parallelism, 64 - SizeMax: *sizeMax, 65 - ShardMax: *shardLimit, 66 - IndexDir: *indexDir, 67 - CTagsMustSucceed: *ctags, 68 - LargeFiles: largeFiles, 69 - TrigramMax: *trigramMax, 70 - } 71 43 opts.SetDefaults() 72 44 return opts 73 45 }