Tabnine Logo
CommandLine$Model$ParserSpec.trimQuotes
Code IndexAdd Tabnine to your IDE (free)

How to use
trimQuotes
method
in
picocli.CommandLine$Model$ParserSpec

Best Java code snippets using picocli.CommandLine$Model$ParserSpec.trimQuotes (Showing top 16 results out of 315)

origin: remkop/picocli

private String unquote(String value) {
  if (!commandSpec.parser().trimQuotes()) { return value; }
  return value == null
      ? null
      : (value.length() > 1 && value.startsWith("\"") && value.endsWith("\""))
        ? value.substring(1, value.length() - 1)
        : value;
}
origin: remkop/picocli

private static String restoreQuotedValues(String part, Queue<String> quotedValues, ParserSpec parser) {
  StringBuilder result = new StringBuilder();
  boolean escaping = false, inQuote = false, skip = false;
  for (int ch = 0, i = 0; i < part.length(); i += Character.charCount(ch)) {
    ch = part.codePointAt(i);
    switch (ch) {
      case '\\': escaping = !escaping; break;
      case '\"':
        if (!escaping) {
          inQuote = !inQuote;
          if (!inQuote) { result.append(quotedValues.remove()); }
          skip = parser.trimQuotes();
        }
        break;
      default: escaping = false; break;
    }
    if (!skip) { result.appendCodePoint(ch); }
    skip = false;
  }
  return result.toString();
}
origin: remkop/picocli

@SuppressWarnings("unchecked")
@Test
public void testInterpreterApplyValueToSingleValuedField() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Class lookBehindClass = Class.forName("picocli.CommandLine$LookBehind");
  Method applyValueToSingleValuedField = c.getDeclaredMethod("applyValueToSingleValuedField",
      ArgSpec.class,
      lookBehindClass,
      Range.class,
      Stack.class, Set.class, String.class);
  applyValueToSingleValuedField.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  Method clear = c.getDeclaredMethod("clear");
  clear.setAccessible(true);
  clear.invoke(interpreter); // initializes the interpreter instance
  PositionalParamSpec arg = PositionalParamSpec.builder().arity("1").build();
  Object SEPARATE = lookBehindClass.getDeclaredField("SEPARATE").get(null);
  int value = (Integer) applyValueToSingleValuedField.invoke(interpreter,
      arg, SEPARATE, Range.valueOf("1"), new Stack<String>(), new HashSet<String>(), "");
  assertEquals(0, value);
}
origin: info.picocli/picocli

@SuppressWarnings("unchecked")
@Test
public void testInterpreterApplyValueToSingleValuedField() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Class lookBehindClass = Class.forName("picocli.CommandLine$LookBehind");
  Method applyValueToSingleValuedField = c.getDeclaredMethod("applyValueToSingleValuedField",
      ArgSpec.class,
      lookBehindClass,
      Range.class,
      Stack.class, Set.class, String.class);
  applyValueToSingleValuedField.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  Method clear = c.getDeclaredMethod("clear");
  clear.setAccessible(true);
  clear.invoke(interpreter); // initializes the interpreter instance
  PositionalParamSpec arg = PositionalParamSpec.builder().arity("1").build();
  Object SEPARATE = lookBehindClass.getDeclaredField("SEPARATE").get(null);
  int value = (Integer) applyValueToSingleValuedField.invoke(interpreter,
      arg, SEPARATE, Range.valueOf("1"), new Stack<String>(), new HashSet<String>(), "");
  assertEquals(0, value);
}
origin: hazelcast/hazelcast-jet

private String restoreQuotedValues(String part, Queue<String> quotedValues, ParserSpec parser) {
  StringBuilder result = new StringBuilder();
  boolean escaping = false, inQuote = false, skip = false;
  for (int ch = 0, i = 0; i < part.length(); i += Character.charCount(ch)) {
    ch = part.codePointAt(i);
    switch (ch) {
      case '\\': escaping = !escaping; break;
      case '\"':
        if (!escaping) {
          inQuote = !inQuote;
          if (!inQuote) { result.append(quotedValues.remove()); }
          skip = parser.trimQuotes();
        }
        break;
      default: escaping = false; break;
    }
    if (!skip) { result.appendCodePoint(ch); }
    skip = false;
  }
  return result.toString();
}
origin: hazelcast/hazelcast-jet

/** Sets whether the parser should trim quotes from command line arguments before processing them. The default is
 * read from the system property "picocli.trimQuotes" and will be {@code true} if the property is set and empty, or
 * if its value is "true".
 * <p>The specified setting will be registered with this {@code CommandLine} and the full hierarchy of its
 * subcommands and nested sub-subcommands <em>at the moment this method is called</em>. Subcommands added
 * later will have the default setting. To ensure a setting is applied to all
 * subcommands, call the setter last, after adding subcommands.</p>
 * <p>Calling this method will cause the "picocli.trimQuotes" property to have no effect.</p>
 * @param newValue the new setting
 * @return this {@code CommandLine} object, to allow method chaining
 * @since 3.7
 */
public CommandLine setTrimQuotes(boolean newValue) {
  getCommandSpec().parser().trimQuotes(newValue);
  for (CommandLine command : getCommandSpec().subcommands().values()) {
    command.setTrimQuotes(newValue);
  }
  return this;
}
origin: info.picocli/picocli

@SuppressWarnings("unchecked")
@Ignore
@Test
public void testInterpreterProcessClusteredShortOptions() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Method processClusteredShortOptions = c.getDeclaredMethod("processClusteredShortOptions",
      Collection.class, Set.class, String.class, Stack.class);
  processClusteredShortOptions.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.addOption(OptionSpec.builder("-x").arity("0").build());
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  Stack<String> stack = new Stack<String>();
  String arg = "-xa";
  processClusteredShortOptions.invoke(interpreter, new ArrayList<ArgSpec>(), new HashSet<String>(), arg, stack);
  // TODO
}
origin: info.picocli/picocli

@SuppressWarnings("unchecked")
@Test
public void testInterpreterUnquote() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Method unquote = c.getDeclaredMethod("unquote", String.class);
  unquote.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  assertNull(unquote.invoke(interpreter, new Object[]{null}));
  assertEquals("abc", unquote.invoke(interpreter, "\"abc\""));
  assertEquals("", unquote.invoke(interpreter, "\"\""));
  assertEquals("only balanced quotes 1", "\"abc", unquote.invoke(interpreter, "\"abc"));
  assertEquals("only balanced quotes 2", "abc\"", unquote.invoke(interpreter, "abc\""));
  assertEquals("only balanced quotes 3", "\"", unquote.invoke(interpreter, "\""));
  assertEquals("no quotes", "X", unquote.invoke(interpreter, "X"));
}
origin: info.picocli/picocli

@Test
public void testArgSpecSplitValue_MultipleQuotedValues_QuotesTrimmedIfRequested() {
  ParserSpec parser = new ParserSpec().trimQuotes(true);
  ArgSpec spec = PositionalParamSpec.builder().splitRegex(",").build();
  String[] actual = spec.splitValue("a,b,\"c,d,e\",f,\"xxx,yyy\"", parser, Range.valueOf("0"), 0);
  assertArrayEquals(new String[]{"a", "b", "c,d,e", "f", "xxx,yyy"}, actual);
}
origin: hazelcast/hazelcast-jet

private String unquote(String value) {
  if (!commandSpec.parser().trimQuotes()) { return value; }
  return value == null
      ? null
      : (value.length() > 1 && value.startsWith("\"") && value.endsWith("\""))
        ? value.substring(1, value.length() - 1)
        : value;
}
origin: hazelcast/hazelcast-jet

/** Returns whether the parser should trim quotes from command line arguments before processing them. The default is
 * read from the system property "picocli.trimQuotes" and will be {@code true} if the property is present and empty,
 * or if its value is "true".
 * @return {@code true} if the parser should trim quotes from command line arguments before processing them, {@code false} otherwise;
 * @since 3.7 */
public boolean isTrimQuotes() { return getCommandSpec().parser().trimQuotes(); }
origin: remkop/picocli

/** Sets whether the parser should trim quotes from command line arguments before processing them. The default is
 * read from the system property "picocli.trimQuotes" and will be {@code true} if the property is set and empty, or
 * if its value is "true".
 * <p>The specified setting will be registered with this {@code CommandLine} and the full hierarchy of its
 * subcommands and nested sub-subcommands <em>at the moment this method is called</em>. Subcommands added
 * later will have the default setting. To ensure a setting is applied to all
 * subcommands, call the setter last, after adding subcommands.</p>
 * <p>Calling this method will cause the "picocli.trimQuotes" property to have no effect.</p>
 * @param newValue the new setting
 * @return this {@code CommandLine} object, to allow method chaining
 * @since 3.7
 */
public CommandLine setTrimQuotes(boolean newValue) {
  getCommandSpec().parser().trimQuotes(newValue);
  for (CommandLine command : getCommandSpec().subcommands().values()) {
    command.setTrimQuotes(newValue);
  }
  return this;
}
origin: remkop/picocli

@SuppressWarnings("unchecked")
@Ignore
@Test
public void testInterpreterProcessClusteredShortOptions() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Method processClusteredShortOptions = c.getDeclaredMethod("processClusteredShortOptions",
      Collection.class, Set.class, String.class, Stack.class);
  processClusteredShortOptions.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.addOption(OptionSpec.builder("-x").arity("0").build());
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  Stack<String> stack = new Stack<String>();
  String arg = "-xa";
  processClusteredShortOptions.invoke(interpreter, new ArrayList<ArgSpec>(), new HashSet<String>(), arg, stack);
  // TODO
}
origin: remkop/picocli

@SuppressWarnings("unchecked")
@Test
public void testInterpreterUnquote() throws Exception {
  Class c = Class.forName("picocli.CommandLine$Interpreter");
  Method unquote = c.getDeclaredMethod("unquote", String.class);
  unquote.setAccessible(true);
  CommandSpec spec = CommandSpec.create();
  spec.parser().trimQuotes(true);
  CommandLine cmd = new CommandLine(spec);
  Object interpreter = PicocliTestUtil.interpreter(cmd);
  assertNull(unquote.invoke(interpreter, new Object[]{null}));
  assertEquals("abc", unquote.invoke(interpreter, "\"abc\""));
  assertEquals("", unquote.invoke(interpreter, "\"\""));
  assertEquals("only balanced quotes 1", "\"abc", unquote.invoke(interpreter, "\"abc"));
  assertEquals("only balanced quotes 2", "abc\"", unquote.invoke(interpreter, "abc\""));
  assertEquals("only balanced quotes 3", "\"", unquote.invoke(interpreter, "\""));
  assertEquals("no quotes", "X", unquote.invoke(interpreter, "X"));
}
origin: remkop/picocli

@Test
public void testArgSpecSplitValue_MultipleQuotedValues_QuotesTrimmedIfRequested() {
  ParserSpec parser = new ParserSpec().trimQuotes(true);
  ArgSpec spec = PositionalParamSpec.builder().splitRegex(",").build();
  String[] actual = spec.splitValue("a,b,\"c,d,e\",f,\"xxx,yyy\"", parser, Range.valueOf("0"), 0);
  assertArrayEquals(new String[]{"a", "b", "c,d,e", "f", "xxx,yyy"}, actual);
}
origin: remkop/picocli

/** Returns whether the parser should trim quotes from command line arguments before processing them. The default is
 * read from the system property "picocli.trimQuotes" and will be {@code true} if the property is present and empty,
 * or if its value is "true".
 * @return {@code true} if the parser should trim quotes from command line arguments before processing them, {@code false} otherwise;
 * @since 3.7 */
public boolean isTrimQuotes() { return getCommandSpec().parser().trimQuotes(); }
picocliCommandLine$Model$ParserSpectrimQuotes

Popular methods of CommandLine$Model$ParserSpec

  • separator
  • aritySatisfiedByAttachedOptionParam
  • caseInsensitiveEnumValuesAllowed
  • collectErrors
  • limitSplit
  • posixClusteredShortOptionsAllowed
  • unmatchedOptionsArePositionalParams
  • splitQuotedStrings
  • useSimplifiedAtFiles
  • atFileCommentChar
  • endOfOptionsDelimiter
  • expandAtFiles
  • endOfOptionsDelimiter,
  • expandAtFiles,
  • overwrittenOptionsAllowed,
  • stopAtPositional,
  • stopAtUnmatched,
  • toggleBooleanFlags,
  • unmatchedArgumentsAllowed,
  • <init>,
  • initFrom

Popular in Java

  • Updating database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • requestLocationUpdates (LocationManager)
  • onRequestPermissionsResult (Fragment)
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • JCheckBox (javax.swing)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now