/*
* px *
Copyright (c) 2008 Shawn Hladky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "pxheaders.h"
#include "setcommand.h"
#include "strops2.h"
ErrorId set_usage = { ErrorOf( ES_CLIENT, 0, E_INFO, EV_USAGE, 0 ),
"\n"
" set -- Set variables in the registry (Windows only)\n"
"\n"
" px set [ -s -S service ] [ var=[value] ]\n"
"\n"
" 'px set' sets the registry variables used by Perforce on Windows\n"
" platforms. Normally, the variable 'var' is set to 'value'.\n"
" If 'value' is missing, the variable 'var' is unset. Without\n"
" any arguments at all, 'p4 set' list variable settings.\n"
"\n"
" The -s flag causes 'p4 set' to set variables for the whole system\n"
" rather than for the user. You must have NT administrator powers\n"
" to use this.\n"
"\n"
" The -S service flag causes 'p4 set' to set variables for the named\n"
" service. You must have NT administrator powers to use this.\n"
"\n"
" Currently, registry variable entries may be overridden by environment\n"
" variables and (in some cases) flags on the command line.\n"
" See 'p4 help environment' for a list of environment/registry variables.\n"
"\n"};
void setCommand::Help(Error *e)
{
e->Set(set_usage);
}
void setCommand::Run(ClientUser* cu, ClientApi* api, char *const *argv, int argc)
{
Options opts;
Error e;
StrPtr * s = 0;
StrPtr * xfile = 0;
int iargc = argc;
char** iargv = (char**) argv;
//ErrorLog log;
//log.SetTag("Perforce client");
ErrorId usage = {E_INFO , "Usage: parse optionstring flag args" };
opts.Parse( iargc, iargv, "S:s", OPT_ANY, usage, &e);
if (e.Test())
{
cu->Message(&e);
return;
}
//log.Abort( &e );
// get the environment info
HostEnv host;
Enviro env;
StrBuf cwd;
host.GetCwd(cwd);
env.Config(cwd);
#ifdef OS_NT
if(opts['s']) env.BeServer();
if(opts['S']) env.BeServer(opts['S']);
#endif
if(iargc == 0)
{
env.List();
}
else
{
for (int i = 0; i < iargc; i++)
{
StrRef arg(iargv[i]);
StrBuf var, val;
if(!StrOps2::SplitVarVal(arg, var, val))
{
env.Print(arg.Text());
}
else
{
env.Set(var.Text(), val.Text(), &e);
cu->Message(&e);
//log.Report( &e );
}
}
}
}