mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-27 15:31:40 +00:00
Add a command-line interface to the WML diff functionalityNote that this is only useful for WML documents that do not require preprocessing.
This commit is contained in:
parent
27209171af
commit
d4c6f1e5f0
@ -104,6 +104,11 @@ information about command mode).
|
||||
.B --debug-lua
|
||||
enables some Lua debugging mechanisms
|
||||
.TP
|
||||
.BI -D,--diff \ left-file \ right-file
|
||||
diffs the two WML files; does not preprocess them first (to do that, run them through
|
||||
.B -p
|
||||
first). Outputs the diff as DiffWML on standard output.
|
||||
.TP
|
||||
.BI -e[ file ],\ --editor[ =file ]
|
||||
start the in-game map editor directly. If
|
||||
.I file
|
||||
@ -239,6 +244,10 @@ which defines a Wesnoth plugin. Similar to
|
||||
.BR --script ,
|
||||
but Lua file should return a function which will be run as a coroutine and periodically woken up with updates.
|
||||
.TP
|
||||
.BI -P,--patch \ base-file \ patch-file
|
||||
applies a DiffWML patch to a WML file; does not preprocess either of the files.
|
||||
Outputs the patched WML to standard output.
|
||||
.TP
|
||||
.BI -p,\ --preprocess \ source-file/folder \ target-directory
|
||||
preprocesses a specified file/folder. For each file(s) a plain .cfg file and a processed .cfg
|
||||
file will be written in specified target directory. If a folder is specified, it will
|
||||
|
@ -144,6 +144,10 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
|
||||
validate_schema(),
|
||||
validate_wml(),
|
||||
validate_with(),
|
||||
do_diff(),
|
||||
do_patch(),
|
||||
diff_left(),
|
||||
diff_right(),
|
||||
version(false),
|
||||
report(false),
|
||||
windowed(false),
|
||||
@ -282,6 +286,8 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
|
||||
("validate-addon", po::value<std::string>(), "validate the specified addon's WML against the schema")
|
||||
("validate-core", "validate the core WML against the schema")
|
||||
("validate-schema", po::value<std::string>(), "validate a specified WML schema")
|
||||
("diff,D", po::value<two_strings>()->multitoken(), "diff two preprocessed WML documents")
|
||||
("patch,P", po::value<two_strings>()->multitoken(), "apply a patch to a preprocessed WML document")
|
||||
;
|
||||
|
||||
po::options_description preprocessor_opts("Preprocessor mode options");
|
||||
@ -429,6 +435,18 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
|
||||
preprocess_path = vm["preprocess"].as<two_strings>().first;
|
||||
preprocess_target = vm["preprocess"].as<two_strings>().second;
|
||||
}
|
||||
if (vm.count("diff"))
|
||||
{
|
||||
do_diff = true;
|
||||
diff_left = vm["diff"].as<two_strings>().first;
|
||||
diff_right = vm["diff"].as<two_strings>().second;
|
||||
}
|
||||
if (vm.count("patch"))
|
||||
{
|
||||
do_patch = true;
|
||||
diff_left = vm["patch"].as<two_strings>().first;
|
||||
diff_right = vm["patch"].as<two_strings>().second;
|
||||
}
|
||||
if (vm.count("preprocess-defines"))
|
||||
preprocess_defines = utils::split(vm["preprocess-defines"].as<std::string>(), ',');
|
||||
if (vm.count("preprocess-input-macros"))
|
||||
|
@ -215,6 +215,9 @@ public:
|
||||
boost::optional<std::string> validate_wml;
|
||||
/// Non-empty if --use-schema was given on the command line. Specifies the schema for use with --validate.
|
||||
boost::optional<std::string> validate_with;
|
||||
bool do_diff, do_patch;
|
||||
/// Files for diffing or patching
|
||||
std::string diff_left, diff_right;
|
||||
/// True if --version was given on the command line. Prints version and exits.
|
||||
bool version;
|
||||
/// True if --report was given on the command line. Prints a bug report-style info dump and exits.
|
||||
|
@ -503,6 +503,29 @@ static int process_command_args(const commandline_options& cmdline_opts)
|
||||
validator.set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
|
||||
return handle_validate_command(*cmdline_opts.validate_schema, validator, {});
|
||||
}
|
||||
|
||||
if(cmdline_opts.do_diff) {
|
||||
config left, right;
|
||||
std::ifstream in_left(cmdline_opts.diff_left);
|
||||
std::ifstream in_right(cmdline_opts.diff_right);
|
||||
read(left, in_left);
|
||||
read(right, in_right);
|
||||
config_writer out(std::cout, compression::format::NONE);
|
||||
out.write(right.get_diff(left));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(cmdline_opts.do_patch) {
|
||||
config base, diff;
|
||||
std::ifstream in_base(cmdline_opts.diff_left);
|
||||
std::ifstream in_diff(cmdline_opts.diff_right);
|
||||
read(base, in_base);
|
||||
read(diff, in_diff);
|
||||
base.apply_diff(diff);
|
||||
config_writer out(std::cout, compression::format::NONE);
|
||||
out.write(base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Options changing their behavior dependent on some others should be checked below.
|
||||
|
||||
@ -1036,6 +1059,8 @@ int main(int argc, char** argv)
|
||||
args[k] == "-R" ||
|
||||
args[k] == "--screenshot" ||
|
||||
args[k] == "--data-path" ||
|
||||
args[k] == "--diff" ||
|
||||
args[k] == "--patch" ||
|
||||
args[k] == "--userdata-path" ||
|
||||
args[k] == "--userconfig-path" ||
|
||||
args[k].compare(0, 11, "--validate=") == 0 ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user