Chromium Code Reviews| Index: tools/gn/command_format.cc |
| diff --git a/tools/gn/command_format.cc b/tools/gn/command_format.cc |
| index 7b8f2f34201f2758783e7a7e1a34816fb8be4bc0..99378b3cd678c7142582d7d0b68dd38e30d27d46 100644 |
| --- a/tools/gn/command_format.cc |
| +++ b/tools/gn/command_format.cc |
| @@ -24,14 +24,13 @@ namespace commands { |
| const char kSwitchDryRun[] = "dry-run"; |
| const char kSwitchDumpTree[] = "dump-tree"; |
| -const char kSwitchInPlace[] = "in-place"; |
| const char kSwitchStdin[] = "stdin"; |
| const char kFormat[] = "format"; |
| const char kFormat_HelpShort[] = |
| "format: Format .gn file."; |
| const char kFormat_Help[] = |
| - "gn format [--dump-tree] [--in-place] [--stdin] BUILD.gn\n" |
| + "gn format [--dump-tree] [--stdin | <build_file> ]\n" |
|
scottmg
2016/08/05 17:31:48
no space between file> and ]. Or probably better t
|
| "\n" |
| " Formats .gn file to a standard format.\n" |
| "\n" |
| @@ -46,6 +45,7 @@ const char kFormat_Help[] = |
| " ]\n" |
| "\n" |
| "Arguments\n" |
| + "\n" |
| " --dry-run\n" |
| " Does not change or output anything, but sets the process exit code\n" |
| " based on whether output would be different than what's on disk.\n" |
| @@ -57,14 +57,9 @@ const char kFormat_Help[] = |
| " --dump-tree\n" |
| " For debugging only, dumps the parse tree.\n" |
| "\n" |
| - " --in-place\n" |
| - " Instead of writing the formatted file to stdout, replace the input\n" |
| - " file with the formatted output. If no reformatting is required,\n" |
| - " the input file will not be touched, and nothing printed.\n" |
| - "\n" |
| " --stdin\n" |
| - " Read input from stdin (and write to stdout). Not compatible with\n" |
| - " --in-place of course.\n" |
| + " Read input from stdin and write to stdout rather than update\n" |
| + " a file in-place.\n" |
| "\n" |
| "Examples\n" |
| " gn format //some/BUILD.gn\n" |
| @@ -1002,13 +997,10 @@ int RunFormat(const std::vector<std::string>& args) { |
| base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchDumpTree); |
| bool from_stdin = |
| base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchStdin); |
| - bool in_place = |
| - base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchInPlace); |
| if (dry_run) { |
| // --dry-run only works with an actual file to compare to. |
| from_stdin = false; |
| - in_place = true; |
| } |
| if (from_stdin) { |
| @@ -1047,7 +1039,13 @@ int RunFormat(const std::vector<std::string>& args) { |
| std::string output_string; |
| if (FormatFileToString(&setup, file, dump_tree, &output_string)) { |
| - if (in_place) { |
| + if (dump_tree) { |
|
scottmg
2016/08/05 17:31:48
It's a bit weird that dump_tree means that it does
|
| + // Print nothing else (the tree was already printed). |
| + } else if (from_stdin) { |
|
scottmg
2016/08/05 17:31:48
I don't think this is ever reached. If it's from_s
|
| + // Write formatted output to stdout. |
| + printf("%s", output_string.c_str()); |
| + } else { |
| + // Update the file in-place. |
| base::FilePath to_write = setup.build_settings().GetFullPath(file); |
| std::string original_contents; |
| if (!base::ReadFileToString(to_write, &original_contents)) { |
| @@ -1069,8 +1067,6 @@ int RunFormat(const std::vector<std::string>& args) { |
| } |
| printf("Wrote formatted to '%s'.\n", to_write.AsUTF8Unsafe().c_str()); |
| } |
| - } else { |
| - printf("%s", output_string.c_str()); |
| } |
| } |