用纯Ant来实现,如果其他条件(检查命令行输入) [英] Use pure Ant to implement if else condition (check command line input)
问题描述
我在蚂蚁一个新手。我的Ant脚本接收一个名为用户输入变量 ENV 命令行:
I am a newbie in Ant. My ant script receives a user input variable named "env" from command line:
例如。 蚂蚁的doIt -Denv =测试
用户输入值可以是的测试,开发的或刺的。
The user input value could be "test","dev" or "prod".
我也有 doIt方法
的目标:
<target name="doIt">
//What to do here?
</target>
在我的目标,我想创建以下如果别人条件我Ant脚本:
In my target, I would like to create the following if else condition for my ant script:
if(env == "test")
echo "test"
else if(env == "prod")
echo "prod"
else if(env == "dev")
echo "dev"
else
echo "You have to input env"
这是要检查的价值用户在命令行输入,则相应地打印一条消息。
That's to check which value user has inputted from command line, then, print a message accordingly.
我知道是蚂蚁的Contrib ,我可以写与Ant脚本&LT;如果&GT; &LT;否则&GT;
。 但是我的项目,我想用纯Ant来实施如果别人的条件。也许,我应该使用&lt;条件&GT;
??但我不知道如何使用&lt;条件&GT;
我的逻辑。可能有人帮助我吗?
I know with ant-Contrib, I can write ant script with <if> <else>
. But for my project, I would like to use pure Ant to implement if else condition. Probably, I should use <condition>
?? But I am not sure how to use <condition>
for my logic. Could some one help me please?
推荐答案
您可以创建几个目标,并使用如果
/ 除非
标记。
You can create few targets and use if
/unless
tags.
<project name="if.test" default="doIt">
<target name="doIt" depends="-doIt.init, -test, -prod, -dev, -else"></target>
<target name="-doIt.init">
<condition property="do.test">
<equals arg1="${env}" arg2="test" />
</condition>
<condition property="do.prod">
<equals arg1="${env}" arg2="prod" />
</condition>
<condition property="do.dev">
<equals arg1="${env}" arg2="dev" />
</condition>
<condition property="do.else">
<not>
<or>
<equals arg1="${env}" arg2="test" />
<equals arg1="${env}" arg2="prod" />
<equals arg1="${env}" arg2="dev" />
</or>
</not>
</condition>
</target>
<target name="-test" if="do.test">
<echo>this target will be called only when property $${do.test} is set</echo>
</target>
<target name="-prod" if="do.prod">
<echo>this target will be called only when property $${do.prod} is set</echo>
</target>
<target name="-dev" if="do.dev">
<echo>this target will be called only when property $${do.dev} is set</echo>
</target>
<target name="-else" if="do.else">
<echo>this target will be called only when property $${env} does not equal test/prod/dev</echo>
</target>
</project>
与目标 -
preFIX是私人所以用户将无法从命令行中运行它们。
Targets with -
prefix are private so user won't be able to run them from command line.
这篇关于用纯Ant来实现,如果其他条件(检查命令行输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!