| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "flag" | 9 "flag" |
| 10 "fmt" | 10 "fmt" |
| 11 "log" |
| 11 "os" | 12 "os" |
| 12 ) | 13 ) |
| 13 | 14 |
| 14 // This file contains the main() for the mojom tool binary. | 15 // This file contains the main() for the mojom tool binary. |
| 15 // The mojom tool is used to process .mojom files. | 16 // The mojom tool is used to process .mojom files. |
| 16 // | 17 // |
| 17 // The tool is invoked as follows: | 18 // The tool is invoked as follows: |
| 18 // | 19 // |
| 19 // mojom <command> [<arguments>] | 20 // mojom <command> [<arguments>] |
| 20 // | 21 // |
| 21 // where <commands> is one of: | 22 // where <commands> is one of: |
| 22 // - parse | 23 // - parse |
| 23 // - fmt | 24 // - fmt |
| 24 // | 25 // |
| 25 // For further information about each command, see the file named | 26 // For further information about each command, see the file named |
| 26 // <command>_cmd.go for example "parse_cmd.go" and "fmt_cmd.go". | 27 // <command>_cmd.go for example "parse_cmd.go" and "fmt_cmd.go". |
| 27 func main() { | 28 func main() { |
| 29 log.SetFlags(0) |
| 28 checkVersion(os.Args) | 30 checkVersion(os.Args) |
| 29 commands := NewCommandSet() | 31 commands := NewCommandSet() |
| 30 commands.AddCommand("parse", parseCmd, "Parses mojom files.") | 32 commands.AddCommand("parse", parseCmd, "Parses mojom files.") |
| 31 commands.AddCommand("fmt", fmtCmd, "Formats a mojom file.") | 33 commands.AddCommand("fmt", fmtCmd, "Formats a mojom file.") |
| 32 commands.AddHelpCommand() | 34 commands.AddHelpCommand() |
| 33 commands.RunCommand(os.Args) | 35 commands.RunCommand(os.Args) |
| 34 } | 36 } |
| 35 | 37 |
| 36 func ErrorExit(message string) { | |
| 37 fmt.Fprintf(os.Stderr, "%s\n", message) | |
| 38 os.Exit(1) | |
| 39 } | |
| 40 | |
| 41 type command struct { | 38 type command struct { |
| 42 Name string | 39 Name string |
| 43 Func func([]string) | 40 Func func([]string) |
| 44 Desc string | 41 Desc string |
| 45 } | 42 } |
| 46 | 43 |
| 47 type commandSet struct { | 44 type commandSet struct { |
| 48 commandNames []string | 45 commandNames []string |
| 49 commandMap map[string]command | 46 commandMap map[string]command |
| 50 } | 47 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 s += "\n \t" | 125 s += "\n \t" |
| 129 s += f.Usage | 126 s += f.Usage |
| 130 if !isZeroValue(f.DefValue) { | 127 if !isZeroValue(f.DefValue) { |
| 131 s += fmt.Sprintf(" (default %q)", f.DefValue) | 128 s += fmt.Sprintf(" (default %q)", f.DefValue) |
| 132 } | 129 } |
| 133 b.WriteString(fmt.Sprint(s, "\n")) | 130 b.WriteString(fmt.Sprint(s, "\n")) |
| 134 }) | 131 }) |
| 135 | 132 |
| 136 return b.String() | 133 return b.String() |
| 137 } | 134 } |
| OLD | NEW |