Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // cli.go implements logic to create a generator config object from command | 5 // cli.go implements logic to create a generator config object from command |
| 6 // line arguments. | 6 // line arguments. |
| 7 | 7 |
| 8 package common | 8 package common |
| 9 | 9 |
| 10 import ( | 10 import ( |
| 11 "flag" | 11 "flag" |
| 12 "io" | 12 "io" |
| 13 "io/ioutil" | 13 "io/ioutil" |
| 14 "log" | 14 "log" |
| 15 "os" | 15 "os" |
| 16 "path/filepath" | 16 "path/filepath" |
| 17 | 17 |
| 18 "mojo/public/go/bindings" | 18 "mojo/public/go/bindings" |
| 19 "mojom/generated/mojom_files" | 19 "mojom/generated/mojom_files" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 // GetConfig provides the primary interface for generators. | 22 // GetCliConfig provides the primary interface for generators. |
| 23 // By calling GetConfig, a generator implements the command line interface | 23 // By calling GetCliConfig, a generator implements the command line interface |
| 24 // that is used by all generators. | 24 // that is used by all generators. |
| 25 func GetCliConfig(args []string) GeneratorConfig { | 25 func GetCliConfig(args []string) GeneratorConfig { |
| 26 flagSet := flag.NewFlagSet("Generator Common Flag Set", flag.ExitOnError ) | |
| 27 return GetCustomCliConfig(args, flagSet) | |
| 28 } | |
| 29 | |
| 30 func GetCustomCliConfig(args []string, flagSet *flag.FlagSet) GeneratorConfig { | |
|
vardhan
2016/06/24 01:36:07
suggestion: maybe GetCliConfigWithFlagSet?
azani
2016/06/24 19:21:21
Done.
| |
| 26 config := new(generatorCliConfig) | 31 config := new(generatorCliConfig) |
| 27 flagSet := flag.NewFlagSet("Generator Common Flag Set", flag.ExitOnError ) | |
| 28 | 32 |
| 29 var fileGraphFile string | 33 var fileGraphFile string |
| 30 flagSet.StringVar(&fileGraphFile, "file-graph", "-", | 34 flagSet.StringVar(&fileGraphFile, "file-graph", "-", |
| 31 "Location of the parser output. \"-\" for stdin. (default \"-\") ") | 35 "Location of the parser output. \"-\" for stdin. (default \"-\") ") |
| 32 flagSet.StringVar(&config.outputDir, "output-dir", ".", | 36 flagSet.StringVar(&config.outputDir, "output-dir", ".", |
| 33 "output directory for generated files.") | 37 "output directory for generated files.") |
| 34 flagSet.StringVar(&config.srcRootPath, "src-root-path", ".", | 38 flagSet.StringVar(&config.srcRootPath, "src-root-path", ".", |
| 35 "relative path to the root of the source tree.") | 39 "relative path to the root of the source tree.") |
| 36 flagSet.BoolVar(&config.noGenImports, "no-gen-imports", false, | 40 flagSet.BoolVar(&config.noGenImports, "no-gen-imports", false, |
| 37 "Generate code only for the files that are specified on the comm and line. "+ | 41 "Generate code only for the files that are specified on the comm and line. "+ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 114 |
| 111 // See GeneratorConfig. | 115 // See GeneratorConfig. |
| 112 func (c *generatorCliConfig) GenImports() bool { | 116 func (c *generatorCliConfig) GenImports() bool { |
| 113 return !c.noGenImports | 117 return !c.noGenImports |
| 114 } | 118 } |
| 115 | 119 |
| 116 // See GeneratorConfig. | 120 // See GeneratorConfig. |
| 117 func (c *generatorCliConfig) GenTypeInfo() bool { | 121 func (c *generatorCliConfig) GenTypeInfo() bool { |
| 118 return c.genTypeInfo | 122 return c.genTypeInfo |
| 119 } | 123 } |
| OLD | NEW |