Created
June 1, 2010 03:48
-
-
Save osima/420544 to your computer and use it in GitHub Desktop.
ファイルの入出力指定に限定したコマンドラインパーサ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CmdParser { | |
def args | |
def cli | |
def CmdParser( def args ){ | |
this.args = args | |
cli = new CliBuilder() | |
cli.i(argName:'input', required:true ,args:1 , 'input file') | |
cli.o(argName:'output', required:true ,args:1 , 'output file') | |
} | |
void usage(){ | |
cli.usage() | |
} | |
private def inputf = null | |
def getInputFile() throws CmdProcException{ | |
parse() | |
inputf | |
} | |
private def outputf = null | |
def getOutputFile() throws CmdProcException{ | |
parse() | |
outputf | |
} | |
private boolean 処理済み | |
private void parse() throws CmdProcException{ | |
if( 処理済み ) | |
return | |
def options = null | |
try{ | |
options=cli.parse(args) | |
if( options.i ) | |
inputf = new File(options.i) | |
if( options.o ) | |
outputf = new File(options.o) | |
} | |
catch(Exception ex){ | |
throw new CmdProcException() | |
} | |
処理済み = true | |
} | |
} | |
class CmdProcException extends Exception{ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment