(11)-ICommandOptions
最后更新于:2022-04-01 06:54:44
命令行选项就是你在敲run cts --plan UI命令时可以再跟一个参数,比如在debug配置参数时加入--help看一下效果。
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-09_56911dcf52061.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-09_56911dcf742e3.jpg)
所以这里面定义的类一般是可以在命令行上加参数的形更改的。先来看一下里面有哪些参数
# 接口
~~~
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.tradefed.command;
/**
* Container for execution options for commands.
*/
public interface ICommandOptions {
public boolean isNeedPrepare();
public void setNeedPrepare(boolean needPrepare);
public boolean isNeedTearDown();
public void setNeedTearDown(boolean needTearDown);
/**
* Returns <code>true</code> if abbreviated help mode has been requested
*/
public boolean isHelpMode();
/**
* Returns <code>true</code> if full detailed help mode has been requested
*/
public boolean isFullHelpMode();
/**
* Return <code>true</code> if we should <emph>skip</emph> adding this command to the queue.
*/
public boolean isDryRunMode();
/**
* Return <code>true</code> if we should print the command out to the console before we
* <emph>skip</emph> adding it to the queue.
*/
public boolean isNoisyDryRunMode();
/**
* Return the loop mode for the config.
*/
public boolean isLoopMode();
/**
* Get the min loop time for the config.
*/
public long getMinLoopTime();
/**
* Sets the loop mode for the command
*
* @param loopMode
*/
public void setLoopMode(boolean loopMode);
/**
* Creates a copy of the {@link ICommandOptions} object.
* @return
*/
public ICommandOptions clone();
/**
* Return true if command should run on all devices.
*/
public boolean runOnAllDevices();
}
~~~
# 实现类
~~~
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.tradefed.command;
import com.android.tradefed.config.ConfigurationException;
import com.android.tradefed.config.Option;
import com.android.tradefed.config.Option.Importance;
import com.android.tradefed.config.OptionCopier;
import com.android.tradefed.log.LogUtil.CLog;
/**
* Implementation of {@link ICommandOptions}.
*/
public class CommandOptions implements ICommandOptions {
@Option(name = "help", description =
"display the help text for the most important/critical options.",
importance = Importance.ALWAYS)
private boolean mHelpMode = false;
@Option(name = "help-all", description = "display the full help text for all options.",
importance = Importance.ALWAYS)
private boolean mFullHelpMode = false;
@Option(name = "dry-run",
description = "build but don't actually run the command. Intended as a quick check " +
"to ensure that a command is runnable.",
importance = Importance.ALWAYS)
private boolean mDryRunMode = false;
@Option(name = "noisy-dry-run",
description = "build but don't actually run the command. This version prints the " +
"command to the console. Intended for cmdfile debugging.",
importance = Importance.ALWAYS)
private boolean mNoisyDryRunMode = false;
@Option(name = "min-loop-time", description =
"the minimum invocation time in ms when in loop mode.")
private long mMinLoopTime = 10 * 60 * 1000;
@Option(name = "loop", description = "keep running continuously.")
private boolean mLoopMode = true;
@Option(name = "all-devices", description =
"fork this command to run on all connected devices.")
private boolean mAllDevices = true;
@Option(name = "need-prepare", description = "is needed to prepare device")
private boolean mNeedPrepare = true;
// @Option(name = "need-flash", description = "is needed to fastboot device")
// private boolean mNeedFlash = true;
@Option(name = "need-tearDown", description = "is needed to clean device")
private boolean mNeedTearDown = true;
public boolean isNeedPrepare() {
return mNeedPrepare;
}
public void setNeedPrepare(boolean needPrepare) {
mNeedPrepare = needPrepare;
}
public boolean isNeedTearDown() {
return mNeedTearDown;
}
public void setNeedTearDown(boolean needTearDown) {
mNeedTearDown = needTearDown;
}
/**
* Set the help mode for the config.
* <p/>
* Exposed for testing.
*/
void setHelpMode(boolean helpMode) {
mHelpMode = helpMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isHelpMode() {
return mHelpMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFullHelpMode() {
return mFullHelpMode;
}
/**
* Set the dry run mode for the config.
* <p/>
* Exposed for testing.
*/
void setDryRunMode(boolean dryRunMode) {
mDryRunMode = dryRunMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isDryRunMode() {
return mDryRunMode || mNoisyDryRunMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isNoisyDryRunMode() {
return mNoisyDryRunMode;
}
/**
* Set the loop mode for the config.
*/
@Override
public void setLoopMode(boolean loopMode) {
mLoopMode = loopMode;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isLoopMode() {
return mLoopMode;
}
/**
* Set the min loop time for the config.
* <p/>
* Exposed for testing.
*/
void setMinLoopTime(long loopTime) {
mMinLoopTime = loopTime;
}
/**
* {@inheritDoc}
*/
@Override
public long getMinLoopTime() {
return mMinLoopTime;
}
@Override
public ICommandOptions clone() {
CommandOptions clone = new CommandOptions();
try {
OptionCopier.copyOptions(this, clone);
} catch (ConfigurationException e) {
CLog.e("failed to clone command options", e);
}
return clone;
}
/**
* {@inheritDoc}
*/
@Override
public boolean runOnAllDevices() {
return mAllDevices;
}
}
~~~
实现类里定义了接口中的方法对应的属性分别是:
help就是你要在命令行后的参数,就如文章一开头我添加的--help模式。如果你添加了就等于mHelpMode = true;打印帮助信息,但是只有注解中importance属性的才打印
~~~
@Option(name = "help", description =
"display the help text for the most important/critical options.",
importance = Importance.ALWAYS)
private boolean mHelpMode = false;
~~~
和上面一样,但是会打印所有option注解的信息,不管有没有importance选项
~~~
@Option(name = "help-all", description = "display the full help text for all options.",
importance = Importance.ALWAYS)
private boolean mFullHelpMode = false;
~~~
测试命令是否可行。
~~~
@Option(name = "dry-run",
description = "build but don't actually run the command. Intended as a quick check " +
"to ensure that a command is runnable.",
importance = Importance.ALWAYS)
private boolean mDryRunMode = false;
@Option(name = "noisy-dry-run",
description = "build but don't actually run the command. This version prints the " +
"command to the console. Intended for cmdfile debugging.",
importance = Importance.ALWAYS)
private boolean mNoisyDryRunMode = false;
~~~
是否循环执行命令以及循环的时间
~~~
@Option(name = "min-loop-time", description =
"the minimum invocation time in ms when in loop mode.")
private long mMinLoopTime = 10 * 60 * 1000;
@Option(name = "loop", description = "keep running continuously.")
private boolean mLoopMode = true;
~~~
是否全设备测试
~~~
@Option(name = "all-devices", description =
"fork this command to run on all connected devices.")
private boolean mAllDevices = true;
~~~
测试前的准备工作和测试后的还原工作
~~~
@Option(name = "need-prepare", description = "is needed to prepare device")
private boolean mNeedPrepare = true;
@Option(name = "need-tearDown", description = "is needed to clean device")
private boolean mNeedTearDown = true;
~~~