![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | supplying help option and throwing on empty option Just wanted to poll the collective brain on the best way to go about this . . . I have a script which takes a number of options at run-time (of which defaults are stored in 'param'). One of the options is -help which gives the user a nice help description. However, one of the options should throw an error if left blank. But if the user issues -help and the required option is blank then, of course, an exception is thrown. Is there anything funky I can do within the param collection to get the desired functionality? Cheers, n |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: supplying help option and throwing on empty option You could make -help a [switch] parameter and check its state to determine whether or not to throw the exception if -xOption is $null: param ([switch]$help, $xOption, ...) if ($xOption -eq $null) { if ($help) { # change $help's state to avoid showing it twice $help = (!$help) "show help" } else {"throw exception"} } # show help if its state is $true and $xOption is not $null if ($help) {"show help"} -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: supplying help option and throwing on empty option "Neil Chambers" <n3llyb0y@aol.com> wrote in message news:2007060815331116807-n3llyb0y@aolcom... > Just wanted to poll the collective brain on the best way to go about this > . . . > > I have a script which takes a number of options at run-time (of which > defaults are stored in 'param'). One of the options is -help which gives > the user a nice help description. However, one of the options should throw > an error if left blank. But if the user issues -help and the required > option is blank then, of course, an exception is thrown. > > Is there anything funky I can do within the param collection to get the > desired functionality? You should test the content of your option outside of the param statement. To avoid running the test before showing the help when -help is specified, you can write the help section first and finish it with an exit statement so any further code is skipped. That would look like this: param ($option1, [switch]$help) if ($help) {"Help!";exit} if (! $option1) {throw "Option1 cannot be blank!"} .... Hope that helps, Jaqcues |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: supplying help option and throwing on empty option Thank you, Kiron and Jacques :-) Both excellent options. n |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The DPI option | Catmandu | Vista performance & maintenance | 9 | 08-14-2008 01:45 PM |
| Option not available... | AzTeacher | Vista mail | 3 | 05-12-2008 04:59 PM |
| No option for mail notification in sounds option | BR | Vista mail | 4 | 08-01-2007 04:31 PM |
| RUN option | Jack | Vista General | 4 | 07-25-2007 05:30 PM |
| run option | Daniel | Vista General | 7 | 07-14-2007 07:48 AM |