Examples of CmdLineParser


Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseLongShortLeftover1() throws ParseException
{
  String[] args = {"-a", "--beta", "beth", "--c", "gimel", "-", "hi", "i'm", "left",
  "over"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  p.registerOpt('b', "beta", CmdLineParser.ValueExpected.REQUIRED);
  p.registerOpt('c', null, CmdLineParser.ValueExpected.OPTIONAL);
  assertEquals(p.getNextOpt(), 'a');
  assertEquals(p.getNextOpt(), 'b');
  assertEquals(p.getValStr(), "beth");
  assertEquals(p.getNextOpt(), 'c');
  assertEquals(p.getValStr(), "gimel");
  assertEquals(p.getNextOpt(), CmdLineParser.EndOfOpts);
  String[] r = p.getRemainingArgs();
  assertEquals(r.length, 4);
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseLongShortLeftover2() throws ParseException
{
  String[] args = {"-a", "-beta", "beth", "--c", "gimel", "--", "hi", "i'm", "left",
  "over"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  p.registerOpt('b', "beta", CmdLineParser.ValueExpected.REQUIRED);
  p.registerOpt('c', null, CmdLineParser.ValueExpected.OPTIONAL);
  assertEquals(p.getNextOpt(), 'a');
  assertEquals(p.getNextOpt(), 'b');
  assertEquals(p.getValStr(), "beth");
  assertEquals(p.getNextOpt(), 'c');
  assertEquals(p.getValStr(), "gimel");
  assertEquals(p.getNextOpt(), CmdLineParser.EndOfOpts);
  String[] r = p.getRemainingArgs();
  assertEquals(r.length, 4);
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseLongShortLeftover3() throws ParseException
{
  String[] args = {"-a", "--beta", "5", "--c", "--"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  p.registerOpt('b', "beta", CmdLineParser.ValueExpected.REQUIRED);
  p.registerOpt('c', null, CmdLineParser.ValueExpected.OPTIONAL);
  assertEquals(p.getNextOpt(), 'a');
  assertEquals(p.getNextOpt(), 'b');
  Integer ii = p.getValInt();
  assertEquals(ii.intValue(), 5);
  assertEquals(p.getNextOpt(), 'c');
  assertNull(p.getValInt());
  assertEquals(p.getNextOpt(), CmdLineParser.EndOfOpts);
  String[] r = p.getRemainingArgs();
  assertNull(p.getRemainingArgs());
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseValueNotAcceptedProvided1() throws ParseException
{
  String[] args = {"-a", "aleph"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  assertEquals(p.getNextOpt(), 'a');
  String[] r = p.getRemainingArgs();
  assertEquals(r.length, 1);
  assertEquals(r[0], "aleph");
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseValueNotAcceptedProvided2() throws ParseException
{
  String[] args = {"-alpha", "aleph"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  assertEquals(p.getNextOpt(), 'a');
  String[] r = p.getRemainingArgs();
  assertEquals(r.length, 1);
  assertEquals(r[0], "aleph");
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseValueRequiredNotProvided1()
{
  String[] args = {"-a"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.REQUIRED);
  try {
    p.getNextOpt();
    fail("Should have thrown a ParseException");
  } catch (ParseException e) {
    assertEquals(e.getMessage(),
      "Option -a requires a value but you did not provide one.");
  }
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseValueRequiredNotProvided2()
{
  String[] args = {"--alpha", "-b"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.REQUIRED);
  p.registerOpt('b', "beta", CmdLineParser.ValueExpected.NOT_ACCEPTED);
  try {
    p.getNextOpt();
    fail("Should have thrown a ParseException");
  } catch (ParseException e) {
    assertEquals(e.getMessage(),
      "Option --alpha requires a value but you did not provide one.");
  }
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseValueStrForInt() throws ParseException
{
  String[] args = {"-alpha", "b"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.REQUIRED);
  try {
    p.getNextOpt();
    Integer ii = p.getValInt();
    fail("Should have thrown a NumberFormatException");
  } catch (NumberFormatException e) {
  }
}
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseUnknownShort()
{
  String[] args = {"-alpha", "b", "-z"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.REQUIRED);
  try {
    p.getNextOpt();
    assertEquals(p.getValStr(), "b");
    p.getNextOpt();
    fail("Should have thrown a ParseException");
  } catch (ParseException e) {
    assertEquals(e.getMessage(),
      "Found unknown option (-z) at position 3");
  }
View Full Code Here

Examples of org.apache.pig.tools.cmdline.CmdLineParser

@Test
public void testParseUnknownLong()
{
  String[] args = {"--zeta"};
  CmdLineParser p = new CmdLineParser(args);
  p.registerOpt('a', "alpha", CmdLineParser.ValueExpected.REQUIRED);
  try {
    p.getNextOpt();
    fail("Should have thrown a ParseException");
  } catch (ParseException e) {
    assertEquals(e.getMessage(),
      "Found unknown option (--zeta) at position 1");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.