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

Configure Feed

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

merge-index: handle --help flag (#1053)

Main use case is so we can sanity check the built binary.

+26 -4
+26 -4
cmd/zoekt-merge-index/main.go
··· 15 15 16 16 import ( 17 17 "bufio" 18 + "flag" 18 19 "fmt" 19 20 "log" 20 21 "os" ··· 72 73 } 73 74 74 75 func mergeCmd(paths []string) (string, error) { 76 + if len(paths) == 0 { 77 + return "", fmt.Errorf("merge requires at least one shard path") 78 + } 79 + 75 80 if paths[0] == "-" { 76 81 paths = []string{} 77 82 scanner := bufio.NewScanner(os.Stdin) ··· 82 87 return "", err 83 88 } 84 89 log.Printf("merging %d paths from stdin", len(paths)) 90 + if len(paths) == 0 { 91 + return "", fmt.Errorf("merge requires at least one shard path") 92 + } 85 93 } 86 94 87 95 return merge(filepath.Dir(paths[0]), paths) ··· 92 100 } 93 101 94 102 func main() { 95 - switch subCommand := os.Args[1]; subCommand { 103 + flag.Usage = func() { 104 + fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s <command> [args]\n\n", os.Args[0]) 105 + fmt.Fprintln(flag.CommandLine.Output(), "Commands:") 106 + fmt.Fprintln(flag.CommandLine.Output(), " merge <shard> [<shard>...]") 107 + fmt.Fprintln(flag.CommandLine.Output(), " merge -") 108 + fmt.Fprintln(flag.CommandLine.Output(), " explode <compound-shard>") 109 + } 110 + flag.Parse() 111 + 112 + switch subCommand := flag.Arg(0); subCommand { 96 113 case "merge": 97 - compoundShardPath, err := mergeCmd(os.Args[2:]) 114 + compoundShardPath, err := mergeCmd(flag.Args()[1:]) 98 115 if err != nil { 99 116 log.Fatal(err) 100 117 } 101 118 fmt.Println(compoundShardPath) 102 119 case "explode": 103 - if err := explodeCmd(os.Args[2]); err != nil { 120 + if flag.NArg() != 2 { 121 + log.Fatal("explode requires exactly one compound shard path") 122 + } 123 + if err := explodeCmd(flag.Arg(1)); err != nil { 104 124 log.Fatal(err) 105 125 } 106 126 default: 107 - log.Fatalf("unknown subcommand %s", subCommand) 127 + fmt.Fprintf(os.Stderr, "unknown subcommand %q\n", subCommand) 128 + flag.Usage() 129 + os.Exit(2) 108 130 } 109 131 }