![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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) |
| | 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) |
| | 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) |
| | Re: supplying help option and throwing on empty option Thank you, Kiron and Jacques :-) Both excellent options. n |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| CD Drive "Eject" menu option ... but no "Close" option ... | Vista General | |||
How do I create a right-click option for Empty Recycle Bin? | General Discussion | |||
| The DPI option | Vista performance & maintenance | |||
| No option for mail notification in sounds option | Vista mail | |||
| run option | Vista General | |||