1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: IOptsParser.java,v 1.1.1.1 2004/05/09 16:57:56 vlad_r Exp $ 8 */ 9 package com.vladium.util.args; 10 11 import java.io.PrintWriter; 12 13 // ---------------------------------------------------------------------------- 14 /** 15 * @author Vlad Roubtsov, (C) 2002 16 */ 17 public 18 interface IOptsParser 19 { 20 // public: ................................................................ 21 22 int SHORT_USAGE = 1; 23 int DETAILED_USAGE = 2; 24 25 interface IOpt 26 { getName()27 String getName (); getCanonicalName()28 String getCanonicalName (); 29 getPatternPrefix()30 String getPatternPrefix (); 31 getValueCount()32 int getValueCount (); getFirstValue()33 String getFirstValue (); getValues()34 String [] getValues (); 35 36 } // end of interface 37 38 39 interface IOpts 40 { 41 /** 42 * 0: none, 1: short, 2: detailed 43 * 44 * @return 45 */ usageRequestLevel()46 int usageRequestLevel (); error(PrintWriter out, int width)47 void error (PrintWriter out, int width); 48 getOpts()49 IOpt [] getOpts (); hasArg(String name)50 boolean hasArg (String name); 51 getOpts(String pattern)52 IOpt [] getOpts (String pattern); 53 54 /** 55 * 56 * @return [never null, could be empty] 57 */ getFreeArgs()58 String [] getFreeArgs (); 59 60 } // end of interface 61 usage(PrintWriter out, int level, int width)62 void usage (PrintWriter out, int level, int width); parse(String [] args)63 IOpts parse (String [] args); 64 65 abstract class Factory 66 { 67 // TODO: pass short/long usage opt names in? 68 create(final String metadataResourceName, final ClassLoader loader, final String msgPrefix, final String [] usageOpts)69 public static IOptsParser create (final String metadataResourceName, final ClassLoader loader, 70 final String msgPrefix, final String [] usageOpts) 71 { 72 return new OptsParser (metadataResourceName, loader, msgPrefix, usageOpts); 73 } 74 75 } // end of nested class 76 77 } // end of interface 78 // ----------------------------------------------------------------------------