Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associated application passes filename only #89

Open
genfail opened this issue Oct 25, 2017 · 3 comments
Open

Associated application passes filename only #89

genfail opened this issue Oct 25, 2017 · 3 comments
Labels

Comments

@genfail
Copy link

genfail commented Oct 25, 2017

when i create an app.exe that can handle data files, i ca nassociate the extension to my app. When doubleclicking in the explorer on a data file, windows starts my associated application by:
c":\prog files\app.exe" "c:\my folder\datafile.dat"
So the commandline will have an argument without any -f or other character. How can I handle that?

@siywilliams
Copy link
Member

In 1.5.0.7-commands there is a new option called UseForOrphanArguments, you use it like this:

var fclp = new FluentCommandLineParser<Args>();

fclp.Setup(arg => arg.File)
     .As('f', "file")
     .UseForOrphanArguments(); // if no option specified then values are bound to this option

which means your use case will now be much friendlier to handle:

app.exe "c:\my folder\datafile.dat" will result in fclp.Object.File == "c:\\my folder\datafile.dat"

super!

@genfail
Copy link
Author

genfail commented Nov 26, 2017 via email

@siywilliams
Copy link
Member

I've had a good think about this, my initial thought was that I don't want to bend FCLP to fit the nuances of the different ways .NET serves up the command line args, or how windows serves them into the app itself.

However its a small mod and not the first time someone has raised it so I think adding a SkipFirstArg() option that can be used in the following would work nicely:

var fclp = new FluentCommandLineParser();
var result = fclp
        .SkipFirstArg()
        .Parse(args);

Also with SkipFirstArg() being right next to the Parse(string[]) method it is really explicit.

siywilliams added a commit that referenced this issue Nov 26, 2017
…st argument.

Sometimes this is required when Windows as part of args passed into an application includes the executable name in the first element.
This executable name is in most circumstances not required and consumers of FCLP must skip it manually before passing the arguments into the parser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants