humbletech99
Programmer
I have written some VBScript in wsf and am looking for a good way to handling the arguments. I know that the XML named arguments can be a little helpful, really just for free help usage, but I don't want the program to just be able to handle /h and /help but also unix style arguments like -h and --help.
I figure I will have to write this myself in VBS, but I was wondering if anyone had a good way of doing this, short of having to have 2 separate sections, one for /help style processing and one for --help or -h style processing.
What I have thought of so far is doing the named arguments first as usual, and then doing a separate loop though all WScript.Arguments for the -h and --help style arguments, but considering that I want each /option to have a corresponding -option and --option style as well, this means that there will be a lot of duplicate lines which strikes me as not the best way of attacking the problem or maintaining the code if I changes things.
Q1. Does anyone have a better way of handling all these arguments together to avoid duplication?
There are 2 other bugs I have found in the default way of handling arguments with VBS/Wsf:
Q2. When I type
I notice that it doesn't catch the /randominvalidoption and just silently ignores it. I would like an unrecognized option to trip the help usage. So far all I can think of is again cycling through all arg in a case select or something.
Q3. I have changed the default action for the WSF file type to be the Console Based Windows Script Host, but when running
it does not pass the options and arguments to the script. This is odd really, since even if I were to run
it actually does pass the arguments. What's even more strange is that if I put WSF back to the Windows Based Script Host by default, and run it again, it passes all the arguments.
I can't quite figure out this "feature" since running either cscript scriptname.wsf.... or wscript scriptname.wsf .... does pass arguments to the script...
So,to summarize my questions:
Q1. What's the best way of handling /help or /server:NAME as well as --help or --server NAME style arguments?
Q2. How to catch unrecognized switches to print usage and exit?
Q3. Why do args not get passed when called scriptname.wsf without a preceding scripthost program, but only when cscript is the default?
I figure I will have to write this myself in VBS, but I was wondering if anyone had a good way of doing this, short of having to have 2 separate sections, one for /help style processing and one for --help or -h style processing.
What I have thought of so far is doing the named arguments first as usual, and then doing a separate loop though all WScript.Arguments for the -h and --help style arguments, but considering that I want each /option to have a corresponding -option and --option style as well, this means that there will be a lot of duplicate lines which strikes me as not the best way of attacking the problem or maintaining the code if I changes things.
Q1. Does anyone have a better way of handling all these arguments together to avoid duplication?
There are 2 other bugs I have found in the default way of handling arguments with VBS/Wsf:
Q2. When I type
Code:
cscript scriptname.wsf /option1:something /randominvalidoption
Q3. I have changed the default action for the WSF file type to be the Console Based Windows Script Host, but when running
Code:
scriptname.wsf /arg1 /option1:something
Code:
wscript scriptname.wsf /arg1 /option1:something
I can't quite figure out this "feature" since running either cscript scriptname.wsf.... or wscript scriptname.wsf .... does pass arguments to the script...
So,to summarize my questions:
Q1. What's the best way of handling /help or /server:NAME as well as --help or --server NAME style arguments?
Q2. How to catch unrecognized switches to print usage and exit?
Q3. Why do args not get passed when called scriptname.wsf without a preceding scripthost program, but only when cscript is the default?