Windows Vista Forums

Gnu argp or getopt like arguments processor for Powershell?

  1. #1


    Duncan Smith Guest

    Gnu argp or getopt like arguments processor for Powershell?

    Is there anything like the Gnu 'argp' or 'getopt' parsers from glibc
    for processing command line arguments to a PS function? In particular
    the self documenting --usage and --help screens would be a real help
    and I just wanted to check that there wasn't already something out
    there before looking into it.

    Many thanks,

    Duncan

      My System SpecsSystem Spec

  2. #2


    RickB Guest

    Re: Gnu argp or getopt like arguments processor for Powershell?

    How do you use a parser on a directory object?
    Arguments are not necessarily text and in fact typically are not text.
    To be of any use you would also need what would be analogous to being
    able to see the names of the variables used by a caller when calling
    your routine.

    The command parser is available if you have text that needs parsing.

    [Management.Automation.PSParser]::tokenize

    static System.Collections.ObjectModel.Collection Tokenize(String
    script, Collection`1& errors)
    static System.Collections.ObjectModel.Collection Tokenize(Object[]
    script, Collection`1& errors)

    Duncan Smith wrote:

    > Is there anything like the Gnu 'argp' or 'getopt' parsers from glibc
    > for processing command line arguments to a PS function? In particular
    > the self documenting --usage and --help screens would be a real help
    > and I just wanted to check that there wasn't already something out
    > there before looking into it.
    >
    > Many thanks,
    >
    > Duncan

      My System SpecsSystem Spec

  3. #3


    Jason Archer Guest

    RE: Gnu argp or getopt like arguments processor for Powershell?

    I Duncan. Are you aware that PowerShell can already do this for you?

    Check this out:

    function test ($three) {
    write-host "The argument named 'three' was set to '$three'"
    write-host "The arguments that did not match my pre-specified list are:
    $args"
    }

    test -one "1" -two "2" -three "3" -four "four"



    Arguments can be positional, or named. If you type the argument, then you
    will be assured that you will get the write type of object (if a conversion
    is not possible, the user will get an error).

    In PowerShell v2, even more options will be available to scripts. Like
    required arguments, or allowed values.


    "Duncan Smith" wrote:

    > Is there anything like the Gnu 'argp' or 'getopt' parsers from glibc
    > for processing command line arguments to a PS function? In particular
    > the self documenting --usage and --help screens would be a real help
    > and I just wanted to check that there wasn't already something out
    > there before looking into it.
    >
    > Many thanks,
    >
    > Duncan
    >

      My System SpecsSystem Spec


Gnu argp or getopt like arguments processor for Powershell?
Similar Threads
Thread Forum
how to execute a batch file with arguments from powershell PowerShell
Passing arguments from .BAT to PowerShell script PowerShell
Re: how to see arguments with powershell when running winrs PowerShell
powershell arguments : PARAM vs ARGS ? PowerShell
Difference in how PowerShell treats arguments vs CMD PowerShell