Quick Dirty Command Line Parser Isn't working
Hi,
I made a quick command line but not sure why it's not working? It seems the for loop is wrong.
The code results in this.
1 2 3 4 5 6 7
|
$ ./AlphaToolbox --makegameassets --template test.xml --sourcepath /BuildPath/bin/GameData/Models/ --destpath /BuildPath/bin/testoutput/
AlphaToolBox Utility 1.0
Parameter - SourcePath :--makegameassets--templatetest.xml--sourcepath--destpath/BuildPath/bin/testoutput/
Parameter - DestPath :--makegameassets--templatetest.xml--sourcepath/BuildPath/bin/GameData/Models/--destpath
Parameter - TemplateFile :--makegameassets--template--sourcepath/BuildPath/bin/GameData/Models/--destpath/BuildPath/bin/testoutput/
Error: No mdl file in source path
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <Urho3D/Urho3D.h>
#include <iostream>
#include <string>
// stabdard std
using namespace std;
#include "AlphaToolBox.h"
#include "AlphaToolBoxUtil.h"
// function
int main(int argc, char* argv[])
{
// note
string command;
// show title
cout << "AlphaToolBox Utility 1.0 " << endl;
// Create toolbox
AlphaToolBoxUtil * Util = new AlphaToolBoxUtil();
for(int i=0; i<argc; i++)
{
if (i + 1 >argc) // Check that we haven't finished parsing already
{
break;
}
// use string comparison make life easier
string argument;
argument.append(argv[i]);
// Command
if (argument.find("--makegameassets"))
{
// use this command
command.append("makegameassets");
}
// use this prevent overcounting parameters
string useargument;
if(i+1<argc)
{
useargument.append(argv[i + 1]);
}
// Set Source Path
if (argument.find( "--sourcepath"))
{
Util->SetSourcePath(useargument);
}
// Set Dest Path
if (argument.find("--destpath"))
{
Util->SetDestPath(useargument);
}
// Set Template File
if (argument.find("--template"))
{
Util->SetTemplateFile(useargument);
}
}
// If command is gmake game assets
if(command.find("makegameassets")!=string::npos)
{
Util->Create_GameAssetXMLFiles();
}
// dekete
delete Util;
Util = NULL;
return 0;
}
|
Vivienne
Last edited on
The first argument (0) is always the executable (and path). So start the loop with i=1.
.append(...)
isn't a good idea especially for useargument
. When you pass useargument
like on line 53/59/65 all previous arguments are passed as well.
You might pass a string like
"test.xml/BuildPath/bin/GameData/Models//BuildPath/bin/testoutput/"
on line 59.
Topic archived. No new replies allowed.