tclap looks really nice. I've written a small test to see if our
current cmd line options could replaced with it. It looks and works
good, but I've used UnlabeledMultiArg to add the option of adding some
songs that should be loaded at start. Unfortunately because of this
tcalp won't throw an exception if I misspelled an option while using
UnlabeledMultiArg. This misspelled option is then handled as an
argument for UnlabeledMultiArg. 

Is there a way to have UnlabeledMultiArg and still get an error if 
I use "--resourcepath" instead of "--resourcePath"?

best,
Max


On Sat, 19 May 2012 10:23:32 -0400
thomas vincent <[email protected]> wrote:

> I personnaly recommend Tclap, a hearder only solution that do not
> bring any other dependency, is available through MIT license.
> What I like is the required/optional arguments, and the fact that it
> creates usage/help from your definition ... handy.
> What I don't like is that your need to use exception during parsing,
> but it's not so bad.
> Take a look here : http://tclap.sourceforge.net/
> My 2 cents,
> Tom
> 
> 2012/5/19 Daniel Schürmann <[email protected]>:
> > Hi Max,
> >
> > will this drew boost dependency to Mixxx?
> >
> > Googling a little bit I have just found
> > http://code.google.com/p/qgetopts/
> > and
> > http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKCmdLineArgs.html
> >
> > Any experience?
> >
> > Kind regards,
> >
> > Daniel
> >
> >
> >
> >
> > 2012/5/19 Max Linke <[email protected]>
> >>
> >> Hi
> >>
> >> So far we don't really parse any options during start and also get
> >> no warning if mixxx doesn't know an option. This can be unnerving
> >> if you forget that mixxx uses CamelCase and wonder what's
> >> happening.
> >>
> >> To get option parsing cross-platform we could use
> >> boost/program_options
> >>
> >> http://www.boost.org/doc/libs/1_44_0/doc/html/program_options.html
> >>
> >> Any comments why this shouldn't be used or our current system is
> >> enough?
> >>
> >> best,
> >> Max
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> Live Security Virtual Conference
> >> Exclusive live event will cover all the ways today's security and
> >> threat landscape has changed and how IT managers can respond.
> >> Discussions will include endpoint security, mobile security and
> >> the latest in malware threats.
> >> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> >> _______________________________________________ Get Mixxx, the #1
> >> Free MP3 DJ Mixing software Today http://mixxx.org
> >>
> >>
> >> Mixxx-devel mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/mixxx-devel
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond.
> > Discussions will include endpoint security, mobile security and the
> > latest in malware threats.
> > http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________ Get Mixxx, the #1
> > Free MP3 DJ Mixing software Today http://mixxx.org
> >
> >
> > Mixxx-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/mixxx-devel

// This illustrates how to change the flag and name start strings for 
// Windows, otherwise the defaults are used.
//
// Note that these defines need to happen *before* tclap is included!
//
#ifdef WINDOWS
#define TCLAP_NAMESTARTSTRING "~~"
#define TCLAP_FLAGSTARTSTRING "/"
#endif

#include <iostream>
#include <tclap/CmdLine.h>
#include <string>
#include <vector>

using namespace std;

void loadSong(string filepath){
    cout << "\t"<< filepath << endl;
}

int main(int argc,char** argv){
    try {
        TCLAP::CmdLine cmd("For more information, see http://mixxx.org/wiki/doku.php/command_line_options";, ' ', "1.11.0-alpha");

        //("shortname","longname","description",bool required,"default","expected filetype")
        //shortname="" == no shortname
        TCLAP::ValueArg<string> resourcePath("","resourcePath","Top-level directory where Mixxx should look for its resource files such as MIDI mappings, overriding the default installation location. ",false,"default","file path");
        cmd.add( resourcePath );


        TCLAP::ValueArg<string> pluginPath("","pluginPath","Top-level directory where Mixxx shoud look for sound source plugins in addition to default locations.",false,"default","file path");
        cmd.add( pluginPath );

        TCLAP::ValueArg<string> locale("","locale","Use a custom locale for loading translations",false,"default","LOCALE");
        cmd.add( locale );

        TCLAP::SwitchArg fullScreenSwitch("f","fullScreen","Starts Mixxx in full-screen mode", cmd, false);
        TCLAP::SwitchArg midiDebugSwitch("","midiDebug","Starts Mixxx in full-screen mode", cmd, false);

        // UnlabeledMultiArg must be the LAST argument added!
        TCLAP::UnlabeledMultiArg<string> songsArg("fileName","Load the specified music file(s) at start-up. Each must be one of the following file types: *.mp3 *.ogg *.aiff *.aif *.wav *.flac", false, "FILE", cmd);

        // Parse the argv array.
        cmd.parse( argc, argv );

        // Get the value parsed by each arg. 
        string resPath = resourcePath.getValue();
        string plugPath = pluginPath.getValue();
        string loc = locale.getValue(); 
        bool fullScreen = fullScreenSwitch.getValue();
        bool midiDebug = midiDebugSwitch.getValue();
        vector<string> songs = songsArg.getValue();

        //output all set information
        cout << "resourcePath="<<resPath<<endl;
        cout << "pluginPath="<<plugPath<<endl;
        cout << "locale="<<loc<<endl;
        cout << "fullscreen mode ? "<<fullScreen<<endl;
        cout << "midiDebug ? "<<midiDebug<<endl;
        cout << "songs to be loaded in a deck:"<<endl;
        for_each (songs.begin(),songs.end(),loadSong);

    } catch (TCLAP::ArgException &e) { // catch any exceptions 
        std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; 
    }
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Get Mixxx, the #1 Free MP3 DJ Mixing software Today
http://mixxx.org


Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to