Skip to content

Instantly share code, notes, and snippets.

@osima
Created June 1, 2010 03:48
Show Gist options
  • Save osima/420544 to your computer and use it in GitHub Desktop.
Save osima/420544 to your computer and use it in GitHub Desktop.
ファイルの入出力指定に限定したコマンドラインパーサ
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