From d3b0ede8c87f257451f9dfa8d9f0ea73798d6dc0 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Wed, 20 Jul 2016 09:11:34 +0000 Subject: Command line options processing. -- MOS_MIGRATED_REVID=127924233 --- src/tools/singlejar/options.cc | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/tools/singlejar/options.cc (limited to 'src/tools/singlejar/options.cc') diff --git a/src/tools/singlejar/options.cc b/src/tools/singlejar/options.cc new file mode 100644 index 0000000000..2e33151ba8 --- /dev/null +++ b/src/tools/singlejar/options.cc @@ -0,0 +1,61 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tools/singlejar/options.h" + +#include "src/tools/singlejar/diag.h" +#include "src/tools/singlejar/token_stream.h" + +void Options::ParseCommandLine(int argc, const char *argv[]) { + ArgTokenStream tokens(argc, argv); + std::string optarg; + while (!tokens.AtEnd()) { + if (tokens.MatchAndSet("--output", &output_jar) || + tokens.MatchAndSet("--main_class", &main_class) || + tokens.MatchAndSet("--java_launcher", &java_launcher) || + tokens.MatchAndSet("--deploy_manifest_lines", &manifest_lines) || + tokens.MatchAndSet("--sources", &input_jars) || + tokens.MatchAndSet("--resources", &resources) || + tokens.MatchAndSet("--classpath_resources", &classpath_resources) || + tokens.MatchAndSet("--include_prefixes", &include_prefixes) || + tokens.MatchAndSet("--exclude_build_data", &exclude_build_data) || + tokens.MatchAndSet("--compression", &force_compression) || + tokens.MatchAndSet("--dont_change_compression", + &preserve_compression) || + tokens.MatchAndSet("--normalize", &normalize_timestamps) || + tokens.MatchAndSet("--no_duplicates", &no_duplicates) || + tokens.MatchAndSet("--verbose", &verbose) || + tokens.MatchAndSet("--warn_duplicate_resources", + &warn_duplicate_resources)) { + continue; + } else if (tokens.MatchAndSet("--build_info_file", &optarg)) { + build_info_files.push_back(optarg); + continue; + } else if (tokens.MatchAndSet("--extra_build_info", &optarg)) { + build_info_lines.push_back(optarg); + continue; + } else { + diag_errx(1, "Bad command line argument %s", tokens.token().c_str()); + } + } + + if (output_jar.empty()) { + diag_errx(1, "Use --output to specify the output file name"); + } + if (force_compression && preserve_compression) { + diag_errx( + 1, + "--compression and --dont_change_compression are mutually exclusive"); + } +} -- cgit v1.2.3