Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2016 Google Inc.
*
* 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.
*/
package com.google.api.tools.framework.tools;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import java.io.File;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
/**
* Class for representing options (flags) for tools.
*
*
In contrast to flags, options are instance based which makes them more suitable for calling
* tools in-process.
*
*
The class defines a set of standard options which are shared between all tools based on the
* framework. Additional options can be defined on a per-tool basis. Environment dependent helper
* classes are provided which can create tool options from program arguments.
*
*/
public class ToolOptions {
private ToolOptions() {}
/** Represents an option. */
public static class Option {
private final Key key;
private final String name;
private final String description;
private final T defaultValue;
private final boolean acceptsRemainingArgs;
private final boolean createFlag;
private ToolOptions options = ToolOptions.create();
public Option(Key key, String name, String description, T defaultValue,
boolean acceptsRemainingArgs, boolean createFlag) {
this.key = key;
this.name = name;
this.description = description;
this.defaultValue = defaultValue;
this.acceptsRemainingArgs = acceptsRemainingArgs;
this.createFlag = createFlag;
}
public Key key() {
return key;
};
public String name() {
return name;
};
public String description() {
return description;
};
@Nullable
public T defaultValue() {
return defaultValue;
};
public boolean acceptsRemainingArgs() {
return acceptsRemainingArgs;
};
public boolean createFlag() {
return createFlag;
};
public void setToolOptions(ToolOptions options) {
this.options = options;
}
public T get() {
return options.get(this);
}
public void setForTest(T value) {
options.set(this, value);
}
@VisibleForTesting
public void resetForTest() {
options.set(this, defaultValue);
}
}
/**
* Input type based on CLI options.
* TODO(user): Support Discovery doc input.
*/
public enum InputType {
DESCRIPTOR_SET,
OPEN_API,
UNKNOWN
}
private static final List