All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.facebook.tools.parser.CliParameter Maven / Gradle / Ivy

There is a newer version: 0.1.32
Show newest version
/*
 * Copyright (C) 2014 Facebook, 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.facebook.tools.parser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class CliParameter {
  private final String name;
  private final List description;
  private final List examples;
  private final String defaultValue;
  private final boolean required;

  private CliParameter(
    String name,
    List description,
    List examples,
    String defaultValue,
    boolean required
  ) {
    this.name = name;
    this.description = new ArrayList<>(description);
    this.examples = new ArrayList<>(examples);
    this.defaultValue = defaultValue;
    this.required = required;
  }

  public String getName() {
    return name;
  }

  public List getDescription() {
    return description;
  }

  public List getExamples() {
    return examples;
  }

  public String getDefaultValue() {
    return defaultValue;
  }

  public boolean isRequired() {
    return required;
  }

  public static class Builder {
    private final String name;

    private List description = Collections.emptyList();
    private List examples = Collections.emptyList();
    private String defaultValue;
    private boolean required = true;

    private Builder(String name) {
      this.name = name;
    }

    public static Builder withName(String name) {
      return new Builder(name);
    }

    public Builder withDescription(String description, String... additionalLines) {
      this.description = new ArrayList<>();
      this.description.add(description);
      this.description.addAll(Arrays.asList(additionalLines));

      return this;
    }

    public Builder withExample(String example, String... additionalLines) {
      this.examples = new ArrayList<>();
      this.examples.add(example);
      this.examples.addAll(Arrays.asList(additionalLines));

      return this;
    }

    public Builder withDefault(String defaultValue) {
      this.defaultValue = defaultValue;
      this.required = false;

      return this;
    }

    CliParameter build() {
      return new CliParameter(name, description, examples, defaultValue, required);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy