我正在使用 Perforce(又名 Helix Core、C++ API)以编程方式运行 Perforce 命令。如何为命令指定全局选项?
例如,我想以编程方式运行clients
带有多个全局选项的命令。如果从命令 shell 运行,它将如下所示。
p4 -z tag -F %client% clients -u mikef
据我所知,我想要的全局选项-z
和-F
不是您可以通过环境变量指定的选项。但即使你可以,我也不能依赖用户来设置它们。
在云雀中,我将全局选项添加到提供给ClientApi
对象的参数数组中。例如:
#include <p4/clientapi.h>
#include "CustomClientUser.h" // A class I derived from ClientUser
// Connect to server.
StrBuf msg;
Error e;
ClientApi client;
client.SetProtocol( "tag", "" );
client.Init( &e );
if ( e.Test() )
{
e.Fmt( &msg );
fprintf( "%s\n", msg.Text() );
return;
}
// Use my own client user.
CustomClientUser cu;
// Run the command. Try adding global options at the beginning of the arg array.
char * argv[] = { "-z", "tag", "-u", "td27117" };
int argc = sizeof( argv ) / sizeof( char * );
client.SetArgv( argc, argv );
client.Run( "clients", &cu );
但是,那没有用。当您给它一个它不理解的命令选项时,错误输出是您所期望的。
Usage: clients [ -t ] [ -u user ] [ -U ] [ [-e|-E] query -m max ] [ -a | -s serverID ] [ -S stream ]
Invalid option: -z.