@Override protected void processOptions(LinkedList<String> args) throws IOException { CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, "R", null); cf.parse(args); setRecursive(cf.getOpt("R")); String modeStr = args.removeFirst(); try { pp = new ChmodParser(modeStr); } catch (IllegalArgumentException iea) { // TODO: remove "chmod : " so it's not doubled up in output, but it's // here for backwards compatibility... throw new IllegalArgumentException( "chmod : mode '" + modeStr + "' does not match the expected pattern."); } }
private static <T> CommandFormat checkArgLimits( Class<? extends IllegalArgumentException> expectedErr, int min, int max, String ... opts) { CommandFormat cf = new CommandFormat(min, max, opts); List<String> parsedArgs = new ArrayList<String>(args); Class<?> cfError = null; try { cf.parse(parsedArgs); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); cfError = e.getClass(); } assertEquals(expectedErr, cfError); if (expectedErr == null) { assertEquals(expectedArgs, parsedArgs); assertEquals(expectedOpts, cf.getOpts()); } return cf; }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); try { quota = StringUtils.TraditionalBinaryPrefix.string2long(str); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota."); } String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } this.args = parameters.toArray(new String[parameters.size()]); }
/** Constructor */ SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String str = parameters.remove(0).trim(); try { quota = StringUtils.TraditionalBinaryPrefix.string2long(str); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota."); } String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { try { this.type = StorageType.parseStorageType(storageTypeString); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Storage type " + storageTypeString + " is not available. Available storage types are " + StorageType.getTypesSupportingQuota()); } } this.args = parameters.toArray(new String[parameters.size()]); }
@Override protected void processOptions(LinkedList<String> args) throws IOException { CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, OPTION_FOLLOW_LINK, OPTION_FOLLOW_ARG_LINK, null); cf.parse(args); if (cf.getOpt(OPTION_FOLLOW_LINK)) { getOptions().setFollowLink(true); } else if (cf.getOpt(OPTION_FOLLOW_ARG_LINK)) { getOptions().setFollowArgLink(true); } // search for first non-path argument (ie starts with a "-") and capture and // remove the remaining arguments as expressions LinkedList<String> expressionArgs = new LinkedList<String>(); Iterator<String> it = args.iterator(); boolean isPath = true; while (it.hasNext()) { String arg = it.next(); if (isPath) { if (arg.startsWith("-")) { isPath = false; } } if (!isPath) { expressionArgs.add(arg); it.remove(); } } if (args.isEmpty()) { args.add(Path.CUR_DIR); } Expression expression = parseExpression(expressionArgs); if (!expression.isAction()) { Expression and = getExpression(And.class); Deque<Expression> children = new LinkedList<Expression>(); children.add(getExpression(Print.class)); children.add(expression); and.addChildren(children); expression = and; } setRootExpression(expression); }
@Override protected void processOptions(LinkedList<String> args) throws IOException { CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, "R"); cf.parse(args); setRecursive(cf.getOpt("R")); parseOwnerGroup(args.removeFirst()); }
/** Constructor */ ClearQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); this.args = parameters.toArray(new String[parameters.size()]); }
/** Constructor */ SetQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); this.quota = Long.parseLong(parameters.remove(0)); this.args = parameters.toArray(new String[parameters.size()]); }
/** Constructor */ ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE); List<String> parameters = c.parse(args, pos); String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } this.args = parameters.toArray(new String[parameters.size()]); }
/** Constructor */ ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE); c.addOptionWithValue("storageType"); List<String> parameters = c.parse(args, pos); String storageTypeString = c.getOptValue("storageType"); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } this.args = parameters.toArray(new String[parameters.size()]); }